From 21202c291a7c68abb498e2bf66235474acbf016f Mon Sep 17 00:00:00 2001 From: Aaron Godfrey Date: Thu, 30 Apr 2020 19:32:38 -0700 Subject: [PATCH] Fixed issue that caused a setup error when there was an empty wishlist. --- custom_components/steam_wishlist/entities.py | 7 +++++++ .../steam_wishlist/sensor_manager.py | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/custom_components/steam_wishlist/entities.py b/custom_components/steam_wishlist/entities.py index 41328df..b255768 100644 --- a/custom_components/steam_wishlist/entities.py +++ b/custom_components/steam_wishlist/entities.py @@ -1,3 +1,4 @@ +import logging from typing import List from homeassistant.components.binary_sensor import BinarySensorDevice @@ -8,6 +9,9 @@ from .types import SteamGame +_LOGGER = logging.getLogger(__name__) + + class SteamWishlistEntity(Entity): """Representation of a Steam wishlist.""" @@ -30,6 +34,9 @@ def games(self) -> List[SteamGame]: """Return all games on the Steam wishlist.""" games: List[SteamGame] = [] for game_id, game in self.coordinator.data.items(): + # This indicates an empty wishlist, just return an empty list. + if game_id == "success": + break games.append(get_steam_game(game_id, game)) return games diff --git a/custom_components/steam_wishlist/sensor_manager.py b/custom_components/steam_wishlist/sensor_manager.py index 4388cdd..3be78ae 100644 --- a/custom_components/steam_wishlist/sensor_manager.py +++ b/custom_components/steam_wishlist/sensor_manager.py @@ -138,15 +138,17 @@ def async_update_items(self): new_sensors.append(self.current_wishlist[WISHLIST_ID]) new_binary_sensors: List[SteamGameEntity] = [] - for game_id, game in self.coordinator.data.items(): - existing = self.current_wishlist.get(game_id) - if existing is not None: - continue - - # Found a new game that we will need to create a new binary_sensor for. - steam_game = get_steam_game(game_id, game) - self.current_wishlist[game_id] = SteamGameEntity(self, steam_game) - new_binary_sensors.append(self.current_wishlist[game_id]) + # {"success": 2} This indicates an empty wishlist. + if "success" not in self.coordinator.data: + for game_id, game in self.coordinator.data.items(): + existing = self.current_wishlist.get(game_id) + if existing is not None: + continue + + # Found a new game that we will need to create a new binary_sensor for. + steam_game = get_steam_game(game_id, game) + self.current_wishlist[game_id] = SteamGameEntity(self, steam_game) + new_binary_sensors.append(self.current_wishlist[game_id]) if new_sensors: self._component_add_entities["sensor"](new_sensors)