Adjust callback registration in harmony (#77533)

pull/77551/head
epenet 2022-08-30 15:54:32 +02:00 committed by GitHub
parent 5f31bdf2d7
commit b47de426d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 21 deletions

View File

@ -105,16 +105,18 @@ class HarmonyRemote(HarmonyEntity, RemoteEntity, RestoreEntity):
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:

View File

@ -58,18 +58,19 @@ class HarmonyActivitySwitch(HarmonyEntity, SwitchEntity):
"""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):