Centralize update loop
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user