mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
Refactored Trend, Timing, and Lifecycle calculators to use BaseCalculator helper methods instead of duplicating data access logic. Changes: - TrendCalculator: Simplified 12 lines of repeated price_info access to 3-4 clean property calls (intervals_today/tomorrow, get_all_intervals) - TimingCalculator: Replaced direct coordinator.data checks with has_data() - LifecycleCalculator: Replaced 5 lines of nested gets with 2 helper calls Benefits: - Eliminated 10+ duplicate data access patterns - Consistent None-handling across all calculators - Single source of truth for coordinator data access - Easier to maintain (changes propagate automatically) BaseCalculator helpers used: - has_data(): Replaces 'if not self.coordinator.data:' checks - intervals_today/tomorrow: Direct property access to day intervals - get_intervals(day): Safe day-specific interval retrieval - get_all_intervals(): Combined yesterday+today+tomorrow - coordinator_data: Property for coordinator.data access Validation: - Type checker: 0 errors, 0 warnings - Tests: 347 passed, 2 skipped (no behavior change) - Net: 19 deletions, 14 insertions (5 lines removed, patterns simplified) Impact: Cleaner code, reduced duplication, consistent error handling. Future calculator additions will automatically benefit from centralized data access patterns. |
||
|---|---|---|
| .. | ||
| api | ||
| binary_sensor | ||
| config_flow_handlers | ||
| coordinator | ||
| custom_translations | ||
| entity_utils | ||
| sensor | ||
| services | ||
| translations | ||
| utils | ||
| __init__.py | ||
| config_flow.py | ||
| const.py | ||
| data.py | ||
| diagnostics.py | ||
| entity.py | ||
| manifest.json | ||
| services.yaml | ||