mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Don't add fritz entities with update_before_add (#110667)
Co-authored-by: mib1185 <mail@mib85.de>
This commit is contained in:
parent
ae39945a85
commit
5f00e15d35
@ -68,7 +68,7 @@ async def async_setup_entry(
|
|||||||
if description.is_suitable(connection_info)
|
if description.is_suitable(connection_info)
|
||||||
]
|
]
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class FritzBoxBinarySensor(FritzBoxBaseCoordinatorEntity, BinarySensorEntity):
|
class FritzBoxBinarySensor(FritzBoxBaseCoordinatorEntity, BinarySensorEntity):
|
||||||
|
@ -291,7 +291,7 @@ class FritzBoxTools(
|
|||||||
|
|
||||||
self.has_call_deflections = "X_AVM-DE_OnTel1" in self.connection.services
|
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]
|
self, key: str, update_fn: Callable[[FritzStatus, StateType], Any]
|
||||||
) -> Callable[[], None]:
|
) -> Callable[[], None]:
|
||||||
"""Register an entity to be updated by coordinator."""
|
"""Register an entity to be updated by coordinator."""
|
||||||
@ -305,6 +305,12 @@ class FritzBoxTools(
|
|||||||
if key not in self._entity_update_functions:
|
if key not in self._entity_update_functions:
|
||||||
_LOGGER.debug("register entity %s for updates", key)
|
_LOGGER.debug("register entity %s for updates", key)
|
||||||
self._entity_update_functions[key] = update_fn
|
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
|
return unregister_entity_updates
|
||||||
|
|
||||||
async def _async_update_data(self) -> UpdateCoordinatorDataType:
|
async def _async_update_data(self) -> UpdateCoordinatorDataType:
|
||||||
@ -1121,16 +1127,20 @@ class FritzBoxBaseCoordinatorEntity(update_coordinator.CoordinatorEntity[AvmWrap
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Init device info class."""
|
"""Init device info class."""
|
||||||
super().__init__(avm_wrapper)
|
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.entity_description = description
|
||||||
self._device_name = device_name
|
self._device_name = device_name
|
||||||
self._attr_unique_id = f"{avm_wrapper.unique_id}-{description.key}"
|
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
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device information."""
|
"""Return the device information."""
|
||||||
|
@ -298,7 +298,7 @@ async def async_setup_entry(
|
|||||||
if description.is_suitable(connection_info)
|
if description.is_suitable(connection_info)
|
||||||
]
|
]
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class FritzBoxSensor(FritzBoxBaseCoordinatorEntity, SensorEntity):
|
class FritzBoxSensor(FritzBoxBaseCoordinatorEntity, SensorEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user