Skip to content

Commit

Permalink
Restore sound mode on Hass restarts #207
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 4, 2024
1 parent 2b9417e commit 72a73c2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion custom_components/yandex_station/core/yandex_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceRegistry
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.restore_state import (
ExtraStoredData,
RestoreEntity,
RestoredExtraData,
)
from homeassistant.helpers.template import Template
from homeassistant.util import dt

Expand Down Expand Up @@ -173,7 +178,7 @@ async def async_browse_media(


# noinspection PyAbstractClass
class YandexStationBase(MediaBrowser):
class YandexStationBase(MediaBrowser, RestoreEntity):
_attr_extra_state_attributes: dict = None

local_state: Optional[dict] = None
Expand Down Expand Up @@ -604,7 +609,15 @@ def async_set_state(self, data: dict):

# BASE MEDIA PLAYER FUNCTIONS

@property
def extra_restore_state_data(self) -> ExtraStoredData | None:
return RestoredExtraData({"sound_mode": self._attr_sound_mode})

async def async_added_to_hass(self):
if extra_data := await self.async_get_last_extra_data():
data = extra_data.as_dict()
self._attr_sound_mode = data["sound_mode"]

if await utils.has_custom_icons(self.hass) and self.device_platform in CUSTOM:
self._attr_icon = CUSTOM[self.device_platform][0]
self.debug(f"Установка кастомной иконки: {self._attr_icon}")
Expand Down

0 comments on commit 72a73c2

Please sign in to comment.