Skip to content

Commit

Permalink
Add template support to sync_volume param
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 22, 2024
1 parent d39e478 commit a81fa9b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/yandex_station/core/yandex_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down

0 comments on commit a81fa9b

Please sign in to comment.