diff --git a/homeassistant/components/fritz/binary_sensor.py b/homeassistant/components/fritz/binary_sensor.py index 00e9f406ed4cb7..f703fadb4b85ce 100644 --- a/homeassistant/components/fritz/binary_sensor.py +++ b/homeassistant/components/fritz/binary_sensor.py @@ -68,7 +68,7 @@ async def async_setup_entry( if description.is_suitable(connection_info) ] - async_add_entities(entities, True) + async_add_entities(entities) class FritzBoxBinarySensor(FritzBoxBaseCoordinatorEntity, BinarySensorEntity): diff --git a/homeassistant/components/fritz/common.py b/homeassistant/components/fritz/common.py index c9acd60b23c6e8..3d287b57384f34 100644 --- a/homeassistant/components/fritz/common.py +++ b/homeassistant/components/fritz/common.py @@ -291,7 +291,7 @@ def setup(self) -> None: self.has_call_deflections = "X_AVM-DE_OnTel1" in self.connection.services - def register_entity_updates( + async def async_register_entity_updates( self, key: str, update_fn: Callable[[FritzStatus, StateType], Any] ) -> Callable[[], None]: """Register an entity to be updated by coordinator.""" @@ -305,6 +305,12 @@ def unregister_entity_updates() -> None: if key not in self._entity_update_functions: _LOGGER.debug("register entity %s for updates", key) self._entity_update_functions[key] = update_fn + if self.fritz_status: + self.data["entity_states"][ + key + ] = await self.hass.async_add_executor_job( + update_fn, self.fritz_status, self.data["entity_states"].get(key) + ) return unregister_entity_updates async def _async_update_data(self) -> UpdateCoordinatorDataType: @@ -1121,16 +1127,20 @@ def __init__( ) -> None: """Init device info class.""" super().__init__(avm_wrapper) - if description.value_fn is not None: - self.async_on_remove( - avm_wrapper.register_entity_updates( - description.key, description.value_fn - ) - ) self.entity_description = description self._device_name = device_name self._attr_unique_id = f"{avm_wrapper.unique_id}-{description.key}" + async def async_added_to_hass(self) -> None: + """When entity is added to hass.""" + await super().async_added_to_hass() + if self.entity_description.value_fn is not None: + self.async_on_remove( + await self.coordinator.async_register_entity_updates( + self.entity_description.key, self.entity_description.value_fn + ) + ) + @property def device_info(self) -> DeviceInfo: """Return the device information.""" diff --git a/homeassistant/components/fritz/sensor.py b/homeassistant/components/fritz/sensor.py index 53a299cd576745..980d86e2455ca0 100644 --- a/homeassistant/components/fritz/sensor.py +++ b/homeassistant/components/fritz/sensor.py @@ -298,7 +298,7 @@ async def async_setup_entry( if description.is_suitable(connection_info) ] - async_add_entities(entities, True) + async_add_entities(entities) class FritzBoxSensor(FritzBoxBaseCoordinatorEntity, SensorEntity):