diff --git a/homeassistant/components/harmony/const.py b/homeassistant/components/harmony/const.py index 26368810c83..f6315b57b57 100644 --- a/homeassistant/components/harmony/const.py +++ b/homeassistant/components/harmony/const.py @@ -10,4 +10,5 @@ ATTR_ACTIVITY_LIST = "activity_list" ATTR_DEVICES_LIST = "devices_list" ATTR_LAST_ACTIVITY = "last_activity" ATTR_CURRENT_ACTIVITY = "current_activity" +ATTR_ACTIVITY_STARTING = "activity_starting" PREVIOUS_ACTIVE_ACTIVITY = "Previous Active Activity" diff --git a/homeassistant/components/harmony/remote.py b/homeassistant/components/harmony/remote.py index badd1cc9508..1ebcfbaa760 100644 --- a/homeassistant/components/harmony/remote.py +++ b/homeassistant/components/harmony/remote.py @@ -30,6 +30,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from .const import ( ACTIVITY_POWER_OFF, ATTR_ACTIVITY_LIST, + ATTR_ACTIVITY_STARTING, ATTR_CURRENT_ACTIVITY, ATTR_DEVICES_LIST, ATTR_LAST_ACTIVITY, @@ -138,6 +139,8 @@ class HarmonyRemote(remote.RemoteEntity, RestoreEntity): self._state = None self._current_activity = ACTIVITY_POWER_OFF self.default_activity = activity + self._activity_starting = None + self._is_initial_update = False self._client = HarmonyClient(ip_address=host) self._config_path = out_path self.delay_secs = delay_secs @@ -172,10 +175,15 @@ class HarmonyRemote(remote.RemoteEntity, RestoreEntity): "connect": self.got_connected, "disconnect": self.got_disconnected, "new_activity_starting": self.new_activity, - "new_activity": None, + "new_activity": self._new_activity_finished, } self._client.callbacks = ClientCallbackType(**callbacks) + def _new_activity_finished(self, activity_info: tuple) -> None: + """Call for finished updated current activity.""" + self._activity_starting = None + self.async_write_ha_state() + async def async_added_to_hass(self): """Complete the initialization.""" await super().async_added_to_hass() @@ -252,6 +260,7 @@ class HarmonyRemote(remote.RemoteEntity, RestoreEntity): def device_state_attributes(self): """Add platform specific attributes.""" return { + ATTR_ACTIVITY_STARTING: self._activity_starting, ATTR_CURRENT_ACTIVITY: self._current_activity, ATTR_ACTIVITY_LIST: list_names_from_hublist( self._client.hub_config.activities @@ -288,6 +297,10 @@ class HarmonyRemote(remote.RemoteEntity, RestoreEntity): activity_id, activity_name = activity_info _LOGGER.debug("%s: activity reported as: %s", self._name, activity_name) self._current_activity = activity_name + if self._is_initial_update: + self._is_initial_update = False + else: + self._activity_starting = activity_name if activity_id != -1: # Save the activity so we can restore # to that activity if none is specified