Skip to content

Commit

Permalink
Handle empty restore state
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
jjlawren committed Feb 21, 2022
1 parent 5eecdb8 commit db6e2b1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion custom_components/sonos_cloud/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ def __init__(self, player: dict[str, Any]):
async def async_added_to_hass(self):
"""Complete entity setup."""
await super().async_added_to_hass()
await self.async_restore_states()

async def async_restore_states(self) -> None:
"""Restore last entity state."""
if (last_state := await self.async_get_last_state()) is None:
return

last_state = await self.async_get_last_state()
if volume := last_state.attributes.get("volume_level"):
self._attr_volume_level = volume

Expand Down

0 comments on commit db6e2b1

Please sign in to comment.