Don't add fritz entities with update_before_add (#110667)

Co-authored-by: mib1185 <mail@mib85.de>
pull/110446/head
Erik Montnemery 2024-02-15 21:49:26 +01:00 committed by GitHub
parent ae39945a85
commit 5f00e15d35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View File

@ -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):

View File

@ -291,7 +291,7 @@ class FritzBoxTools(
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 @@ class FritzBoxTools(
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 @@ class FritzBoxBaseCoordinatorEntity(update_coordinator.CoordinatorEntity[AvmWrap
) -> 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."""

View File

@ -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):