Skip to content

Commit

Permalink
Fixed issue that caused a setup error when there was an empty wishlist.
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed May 1, 2020
1 parent fc0e13e commit 21202c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
7 changes: 7 additions & 0 deletions custom_components/steam_wishlist/entities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import List

from homeassistant.components.binary_sensor import BinarySensorDevice
Expand All @@ -8,6 +9,9 @@
from .types import SteamGame


_LOGGER = logging.getLogger(__name__)


class SteamWishlistEntity(Entity):
"""Representation of a Steam wishlist."""

Expand All @@ -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

Expand Down
20 changes: 11 additions & 9 deletions custom_components/steam_wishlist/sensor_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 21202c2

Please sign in to comment.