Centralize update loop

This commit is contained in:
2021-04-10 23:48:29 +02:00
parent 093bebc391
commit 0113102a7f
5 changed files with 106 additions and 93 deletions

View File

@@ -26,21 +26,14 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: disable=W0613
"""Set up GeoRide tracker based off an entry."""
georide_context = hass.data[GEORIDE_DOMAIN]["context"]
trackers = georide_context.get_trackers()
update_interval = timedelta(seconds=1)
coordoned_trackers = georide_context.get_coordoned_trackers()
lock_switch_entities = []
for tracker in trackers:
coordinator = DataUpdateCoordinator[Mapping[str, Any]](
hass,
_LOGGER,
name=tracker.tracker_name,
update_method=georide_context.refresh_trackers,
update_interval=update_interval
)
for coordoned_tracker in coordoned_trackers:
tracker = coordoned_tracker['tracker']
coordinator = coordoned_tracker['coordinator']
entity = GeoRideLockSwitchEntity(coordinator, tracker, hass)
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = coordinator
lock_switch_entities.append(entity)
async_add_entities(lock_switch_entities)