Skip to content

Commit

Permalink
Adjust callback registration in harmony (#77533)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 30, 2022
1 parent 5f31bdf commit b47de42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
22 changes: 12 additions & 10 deletions homeassistant/components/harmony/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,18 @@ async def _async_update_options(self, data):
if ATTR_ACTIVITY in data:
self.default_activity = data[ATTR_ACTIVITY]

def _setup_callbacks(self):
callbacks = {
"connected": self.async_got_connected,
"disconnected": self.async_got_disconnected,
"config_updated": self.async_new_config,
"activity_starting": self.async_new_activity,
"activity_started": self.async_new_activity_finished,
}

self.async_on_remove(self._data.async_subscribe(HarmonyCallback(**callbacks)))
def _setup_callbacks(self) -> None:
self.async_on_remove(
self._data.async_subscribe(
HarmonyCallback(
connected=self.async_got_connected,
disconnected=self.async_got_disconnected,
config_updated=self.async_new_config,
activity_starting=self.async_new_activity,
activity_started=self.async_new_activity_finished,
)
)
)

@callback
def async_new_activity_finished(self, activity_info: tuple) -> None:
Expand Down
23 changes: 12 additions & 11 deletions homeassistant/components/harmony/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ async def async_turn_off(self, **kwargs):
"""Stop this activity."""
await self._data.async_power_off()

async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass."""

callbacks = {
"connected": self.async_got_connected,
"disconnected": self.async_got_disconnected,
"activity_starting": self._async_activity_update,
"activity_started": self._async_activity_update,
"config_updated": None,
}

self.async_on_remove(self._data.async_subscribe(HarmonyCallback(**callbacks)))
self.async_on_remove(
self._data.async_subscribe(
HarmonyCallback(
connected=self.async_got_connected,
disconnected=self.async_got_disconnected,
activity_starting=self._async_activity_update,
activity_started=self._async_activity_update,
config_updated=None,
)
)
)

@callback
def _async_activity_update(self, activity_info: tuple):
Expand Down

0 comments on commit b47de42

Please sign in to comment.