diff --git a/homeassistant/components/motionmount/entity.py b/homeassistant/components/motionmount/entity.py index c3f7c9c9358..8403af05491 100644 --- a/homeassistant/components/motionmount/entity.py +++ b/homeassistant/components/motionmount/entity.py @@ -1,5 +1,7 @@ """Support for MotionMount sensors.""" +from typing import TYPE_CHECKING + import motionmount from homeassistant.config_entries import ConfigEntry @@ -42,12 +44,28 @@ class MotionMountEntity(Entity): (dr.CONNECTION_NETWORK_MAC, mac) } + @property + def available(self) -> bool: + """Return True if the MotionMount is available (we're connected).""" + return self.mm.is_connected + + def update_name(self) -> None: + """Update the name of the associated device.""" + if TYPE_CHECKING: + assert self.device_entry + # Update the name in the device registry if needed + if self.device_entry.name != self.mm.name: + device_registry = dr.async_get(self.hass) + device_registry.async_update_device(self.device_entry.id, name=self.mm.name) + async def async_added_to_hass(self) -> None: """Store register state change callback.""" self.mm.add_listener(self.async_write_ha_state) + self.mm.add_listener(self.update_name) await super().async_added_to_hass() async def async_will_remove_from_hass(self) -> None: """Remove register state change callback.""" self.mm.remove_listener(self.async_write_ha_state) + self.mm.remove_listener(self.update_name) await super().async_will_remove_from_hass()