From a81fa9b500dc1b151d08ad4398dfb620aa8e746c Mon Sep 17 00:00:00 2001 From: Alex X Date: Fri, 22 Nov 2024 21:22:42 +0300 Subject: [PATCH] Add template support to sync_volume param --- .../yandex_station/core/yandex_station.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/custom_components/yandex_station/core/yandex_station.py b/custom_components/yandex_station/core/yandex_station.py index 258d2ce..76b0edd 100644 --- a/custom_components/yandex_station/core/yandex_station.py +++ b/custom_components/yandex_station/core/yandex_station.py @@ -989,13 +989,20 @@ async def sync_play_media(self, player_state: dict): def sync_service_call(self, service: str, **kwargs): source = self.sync_sources[self._attr_source] - if source.get("sync_volume") is False and service == "volume_set": - return - - self.debug(f"Sync state: {service}") kwargs["entity_id"] = source["entity_id"] + if service == "volume_set" and "sync_volume" in source: + if source["sync_volume"] is False: + return + if isinstance(source["sync_volume"], str): + source["sync_volume"] = Template(source["sync_volume"], self.hass) + if isinstance(source["sync_volume"], Template): + v = source["sync_volume"].async_render(kwargs, False) + kwargs["volume_level"] = float(v) + + self.debug(f"Sync state: {service}") + self.hass.create_task( self.hass.services.async_call("media_player", service, kwargs) )