Skip to content

Commit

Permalink
Code refactoring for #27
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed May 23, 2024
1 parent 445e5c9 commit 0232b70
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions custom_components/stream_assist/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers import template

from .core import run_forever, init_entity, EVENTS

Expand Down Expand Up @@ -45,6 +44,9 @@ def event_callback(self, event: PipelineEvent):

async_dispatcher_send(self.hass, f"{self.uid}-{name}", state, event.data)

async def async_added_to_hass(self) -> None:
self.options["assist"] = {"device_id": self.device_entry.id}

async def async_turn_on(self) -> None:
if self._attr_is_on:
return
Expand All @@ -55,12 +57,6 @@ async def async_turn_on(self) -> None:
for event in EVENTS:
async_dispatcher_send(self.hass, f"{self.uid}-{event}", None)

assist = self.options.get("assist", {})
if assist.get("device_id") is None:
dev_name = self.device_info.get("name")
assist["device_id"] = template.device_id(self.hass, dev_name)
self.options["assist"] = assist

self.on_close = run_forever(
self.hass,
self.options,
Expand Down

0 comments on commit 0232b70

Please sign in to comment.