mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-30 13:23:41 +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. |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| base.py | ||
| daily_stat.py | ||
| interval.py | ||
| lifecycle.py | ||
| metadata.py | ||
| rolling_hour.py | ||
| timing.py | ||
| trend.py | ||
| volatility.py | ||
| window_24h.py | ||