mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-30 05:13:40 +00:00
Implemented comprehensive entity lifecycle patterns following Home Assistant best practices for proper state management and history tracking. Changes: - entity.py: Added available property to base class - Returns False when coordinator has no data or last_update_success=False - Prevents entities from showing stale data during errors - Auth failures trigger reauth flow via ConfigEntryAuthFailed - sensor/core.py: Added state restore and background task handling - Changed inheritance: SensorEntity → RestoreSensor - Restore native_value from SensorExtraStoredData in async_added_to_hass() - Chart sensors restore response data from attributes - Converted blocking service calls to background tasks using hass.async_create_task() - Eliminates 194ms setup warning by making async_added_to_hass non-blocking - binary_sensor/core.py: Added state restore and force_update - Changed inheritance: BinarySensorEntity → RestoreEntity + BinarySensorEntity - Restore is_on state in async_added_to_hass() - Added available property override for connection sensor (always True) - Added force_update property for connection sensor to track all state changes - Other binary sensors use base available logic - AGENTS.md: Documented entity lifecycle patterns in Common Pitfalls - Added "Entity Lifecycle & State Management" section - Documents available, state restore, and force_update patterns - Explains why each pattern matters for proper HA integration Impact: Entities no longer show stale data during errors, history has no gaps after HA restart, connection state changes are properly tracked, and config entry setup completes in <200ms (under HA threshold). All patterns verified against HA developer documentation: https://developers.home-assistant.io/docs/core/entity/ |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| attributes.py | ||
| core.py | ||
| definitions.py | ||
| types.py | ||