Skip to content

[Refactor] Migrate to DataUpdateCoordinator for centralized polling #763

@SecKatie

Description

@SecKatie

Summary

Migrate the integration from individual entity polling (SCAN_INTERVAL + async_update) to Home Assistant's recommended DataUpdateCoordinator pattern for centralized, efficient data fetching.

Current Implementation

The integration currently uses the legacy polling pattern with:

  • SCAN_INTERVAL defined per platform (e.g., 30s for lights/switches, 10s for locks)
  • Individual async_update() methods on each entity
  • Callback functions for push updates (async_update_callback)

This results in:

  • Multiple API calls when many entities of the same type exist
  • No automatic deduplication of requests
  • Manual error handling per entity

Proposed Changes

Adopt the DataUpdateCoordinator pattern as documented in Home Assistant Developer Docs.

Benefits

  • Single API call fetches data for all entities of a type
  • Automatic optimization - only polls when entities are listening
  • Built-in error handling with retry logic and rate-limit backoff
  • Reduced state writes when data hasn't changed (always_update=False)
  • Cleaner code - entities extend CoordinatorEntity for automatic updates

Implementation Steps

  1. Create coordinator classes (e.g., WyzeLightCoordinator, WyzeSwitchCoordinator)
  2. Override _async_update_data() to fetch device data from wyzeapy
  3. Use async_config_entry_first_refresh() during setup
  4. Migrate entity classes to extend CoordinatorEntity
  5. Remove SCAN_INTERVAL and individual async_update() methods
  6. Keep existing callback mechanism for push-based updates where applicable

Platforms to Migrate

  • light.py
  • switch.py
  • lock.py
  • sensor.py
  • climate.py
  • camera.py
  • binary_sensor.py
  • alarm_control_panel.py

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions