hass.tibber_prices/custom_components/tibber_prices
Julian Pawlowski 98512672ae feat(lifecycle): implement HA entity best practices for state management
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/
2025-12-07 17:24:41 +00:00
..
api feat(interval-pool): add intelligent interval caching and memory optimization 2025-11-25 20:44:39 +00:00
binary_sensor feat(lifecycle): implement HA entity best practices for state management 2025-12-07 17:24:41 +00:00
config_flow_handlers refactor(config_flow): reorganize options flow steps with section structure 2025-12-02 20:23:31 +00:00
coordinator fix(coordinator): add _is_fetching flag and fix tomorrow data detection 2025-12-02 19:00:20 +00:00
custom_translations fix(translations): ensure newline at end of translation files for consistency 2025-12-07 15:17:21 +00:00
entity_utils refactor(price_info): price data handling to use unified interval retrieval 2025-11-24 10:49:34 +00:00
interval_pool feat(interval-pool): add intelligent interval caching and memory optimization 2025-11-25 20:44:39 +00:00
sensor feat(lifecycle): implement HA entity best practices for state management 2025-12-07 17:24:41 +00:00
services refactor(services): remove gradient_stop, use fixed 50% gradient 2025-12-05 20:51:30 +00:00
translations refactor(i18n): normalize enum values and improve translation consistency 2025-12-07 14:21:53 +00:00
utils refactor(logging): remove verbose debug logging from price enrichment 2025-11-25 20:44:39 +00:00
__init__.py feat(sensors): add chart_metadata sensor for lightweight chart configuration 2025-12-05 20:30:54 +00:00
config_flow.py refactor(config_flow): rename TibberPricesFlowHandler to TibberPricesConfigFlowHandler 2025-11-25 20:44:39 +00:00
const.py feat(sensors): add chart_metadata sensor for lightweight chart configuration 2025-12-05 20:30:54 +00:00
data.py feat(interval-pool): add intelligent interval caching and memory optimization 2025-11-25 20:44:39 +00:00
diagnostics.py refactor: migrate from multi-home to single-home-per-coordinator architecture 2025-11-24 16:24:37 +00:00
entity.py feat(lifecycle): implement HA entity best practices for state management 2025-12-07 17:24:41 +00:00
icons.json feat(services): add new services and icons for enhanced functionality and user experience 2025-12-02 18:46:15 +00:00
manifest.json chore(release): bump version to 0.20.0 2025-12-05 18:14:32 +00:00
services.yaml feat(apexcharts): add server-side metadata with dynamic yaxis and gradient 2025-12-05 18:14:18 +00:00