mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Cleanup tedee callbacks (#135577)
This commit is contained in:
parent
096c6b8575
commit
6359a75977
@ -69,20 +69,15 @@ async def async_setup_entry(
|
||||
"""Set up the Tedee sensor entity."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
TedeeBinarySensorEntity(lock, coordinator, entity_description)
|
||||
for lock in coordinator.data.values()
|
||||
for entity_description in ENTITIES
|
||||
)
|
||||
|
||||
def _async_add_new_lock(lock_id: int) -> None:
|
||||
lock = coordinator.data[lock_id]
|
||||
def _async_add_new_lock(locks: list[TedeeLock]) -> None:
|
||||
async_add_entities(
|
||||
TedeeBinarySensorEntity(lock, coordinator, entity_description)
|
||||
for entity_description in ENTITIES
|
||||
for lock in locks
|
||||
)
|
||||
|
||||
coordinator.new_lock_callbacks.append(_async_add_new_lock)
|
||||
_async_add_new_lock(list(coordinator.data.values()))
|
||||
|
||||
|
||||
class TedeeBinarySensorEntity(TedeeDescriptionEntity, BinarySensorEntity):
|
||||
|
@ -60,7 +60,7 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
|
||||
|
||||
self._next_get_locks = time.time()
|
||||
self._locks_last_update: set[int] = set()
|
||||
self.new_lock_callbacks: list[Callable[[int], None]] = []
|
||||
self.new_lock_callbacks: list[Callable[[list[TedeeLock]], None]] = []
|
||||
self.tedee_webhook_id: int | None = None
|
||||
|
||||
async def _async_setup(self) -> None:
|
||||
@ -158,8 +158,7 @@ class TedeeApiCoordinator(DataUpdateCoordinator[dict[int, TedeeLock]]):
|
||||
# add new locks
|
||||
if new_locks := current_locks - self._locks_last_update:
|
||||
_LOGGER.debug("New locks found: %s", ", ".join(map(str, new_locks)))
|
||||
for lock_id in new_locks:
|
||||
for callback in self.new_lock_callbacks:
|
||||
callback(lock_id)
|
||||
for callback in self.new_lock_callbacks:
|
||||
callback([self.data[lock_id] for lock_id in new_locks])
|
||||
|
||||
self._locks_last_update = current_locks
|
||||
|
@ -24,23 +24,18 @@ async def async_setup_entry(
|
||||
"""Set up the Tedee lock entity."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
entities: list[TedeeLockEntity] = []
|
||||
for lock in coordinator.data.values():
|
||||
if lock.is_enabled_pullspring:
|
||||
entities.append(TedeeLockWithLatchEntity(lock, coordinator))
|
||||
else:
|
||||
entities.append(TedeeLockEntity(lock, coordinator))
|
||||
|
||||
def _async_add_new_lock(lock_id: int) -> None:
|
||||
lock = coordinator.data[lock_id]
|
||||
if lock.is_enabled_pullspring:
|
||||
async_add_entities([TedeeLockWithLatchEntity(lock, coordinator)])
|
||||
else:
|
||||
async_add_entities([TedeeLockEntity(lock, coordinator)])
|
||||
def _async_add_new_lock(locks: list[TedeeLock]) -> None:
|
||||
entities: list[TedeeLockEntity] = []
|
||||
for lock in locks:
|
||||
if lock.is_enabled_pullspring:
|
||||
entities.append(TedeeLockWithLatchEntity(lock, coordinator))
|
||||
else:
|
||||
entities.append(TedeeLockEntity(lock, coordinator))
|
||||
async_add_entities(entities)
|
||||
|
||||
coordinator.new_lock_callbacks.append(_async_add_new_lock)
|
||||
|
||||
async_add_entities(entities)
|
||||
_async_add_new_lock(list(coordinator.data.values()))
|
||||
|
||||
|
||||
class TedeeLockEntity(TedeeEntity, LockEntity):
|
||||
|
@ -58,20 +58,15 @@ async def async_setup_entry(
|
||||
"""Set up the Tedee sensor entity."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
TedeeSensorEntity(lock, coordinator, entity_description)
|
||||
for lock in coordinator.data.values()
|
||||
for entity_description in ENTITIES
|
||||
)
|
||||
|
||||
def _async_add_new_lock(lock_id: int) -> None:
|
||||
lock = coordinator.data[lock_id]
|
||||
def _async_add_new_lock(locks: list[TedeeLock]) -> None:
|
||||
async_add_entities(
|
||||
TedeeSensorEntity(lock, coordinator, entity_description)
|
||||
for entity_description in ENTITIES
|
||||
for lock in locks
|
||||
)
|
||||
|
||||
coordinator.new_lock_callbacks.append(_async_add_new_lock)
|
||||
_async_add_new_lock(list(coordinator.data.values()))
|
||||
|
||||
|
||||
class TedeeSensorEntity(TedeeDescriptionEntity, SensorEntity):
|
||||
|
Loading…
x
Reference in New Issue
Block a user