Migrate Harmony to has entity name (#104737)

* Migrate Harmony to has entity name

* Fix tests

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Joost Lekkerkerker 2024-03-19 14:02:50 +01:00 committed by GitHub
parent 6106a66ed8
commit 44211dc761
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 120 additions and 114 deletions

View file

@ -19,11 +19,12 @@ TIME_MARK_DISCONNECTED = 10
class HarmonyEntity(Entity):
"""Base entity for Harmony with connection state handling."""
_attr_has_entity_name = True
def __init__(self, data: HarmonyData) -> None:
"""Initialize the Harmony base entity."""
super().__init__()
self._unsub_mark_disconnected: Callable[[], None] | None = None
self._name = data.name
self._data = data
self._attr_should_poll = False
@ -34,14 +35,14 @@ class HarmonyEntity(Entity):
async def async_got_connected(self, _: str | None = None) -> None:
"""Notification that we're connected to the HUB."""
_LOGGER.debug("%s: connected to the HUB", self._name)
_LOGGER.debug("%s: connected to the HUB", self._data.name)
self.async_write_ha_state()
self._clear_disconnection_delay()
async def async_got_disconnected(self, _: str | None = None) -> None:
"""Notification that we're disconnected from the HUB."""
_LOGGER.debug("%s: disconnected from the HUB", self._name)
_LOGGER.debug("%s: disconnected from the HUB", self._data.name)
# We're going to wait for 10 seconds before announcing we're
# unavailable, this to allow a reconnection to happen.
self._unsub_mark_disconnected = async_call_later(