hass.tibber_prices/custom_components/tibber_prices
Julian Pawlowski 3b11c6721e feat(types): add TypedDict documentation and BaseCalculator helpers
Phase 1.1 - TypedDict Documentation System:
- Created sensor/types.py with 14 TypedDict classes documenting sensor attributes
- Created binary_sensor/types.py with 3 TypedDict classes for binary sensors
- Added Literal types (PriceLevel, PriceRating, VolatilityLevel, DataCompleteness)
- Updated imports in sensor/attributes/__init__.py and binary_sensor/attributes.py
- Changed function signatures to use dict[str, Any] for runtime flexibility
- TypedDicts serve as IDE documentation, not runtime validation

Phase 1.2 - BaseCalculator Improvements:
- Added 8 smart data access methods to BaseCalculator:
  * get_intervals(day) - day-specific intervals with None-safety
  * intervals_today/tomorrow/yesterday - convenience properties
  * get_all_intervals() - combined yesterday+today+tomorrow
  * find_interval_at_offset(offset) - interval lookup with bounds checking
  * safe_get_from_interval(interval, key, default) - safe dict access
  * has_data() / has_price_info() - existence checks
  * get_day_intervals(day) - alias for consistency
- Refactored 5 calculator files to use new helper methods:
  * daily_stat.py: -11 lines (coordinator_data checks, get_intervals usage)
  * interval.py: -18 lines (eliminated find_price_data_for_interval duplication)
  * rolling_hour.py: -3 lines (simplified interval collection)
  * volatility.py: -4 lines (eliminated price_info local variable)
  * window_24h.py: -2 lines (replaced coordinator_data check)
  * Total: -38 lines of duplicate code eliminated
- Added noqa comment for lazy import (circular import avoidance)

Type Duplication Resolution:
- Identified duplication: Literal types in types.py vs string constants in const.py
- Attempted solution: Derive constants from Literal types using typing.get_args()
- Result: Circular import failure (const.py → sensor/types.py → sensor/__init__.py → const.py)
- Final solution: Keep string constants as single source of truth
- Added SYNC comments in all 3 files (const.py, sensor/types.py, binary_sensor/types.py)
- Accept manual synchronization to avoid circular dependencies
- Platform separation maintained (no cross-imports between sensor/ and binary_sensor/)

Impact: Developers get IDE autocomplete and type hints for attribute dictionaries.
Calculator code is more readable with fewer None-checks and clearer data access patterns.
Type/constant duplication documented with sync requirements.
2025-11-22 14:32:24 +00:00
..
api fix(api): initialize time attribute to prevent AttributeError 2025-11-21 17:29:04 +00:00
binary_sensor feat(types): add TypedDict documentation and BaseCalculator helpers 2025-11-22 14:32:24 +00:00
config_flow_handlers refactor(config): use negative values for Best Price min_distance 2025-11-22 04:44:57 +00:00
coordinator refactor(coordinator): remove redundant lifecycle callback system 2025-11-22 13:01:17 +00:00
custom_translations feat(sensor): add data lifecycle diagnostic sensor with push updates 2025-11-20 15:12:41 +00:00
entity_utils refactor(entity): switch description content based on extended_descriptions 2025-11-21 17:30:29 +00:00
sensor feat(types): add TypedDict documentation and BaseCalculator helpers 2025-11-22 14:32:24 +00:00
services refactor(coordinator): centralize time operations through TimeService 2025-11-19 18:36:12 +00:00
translations refactor(config): use negative values for Best Price min_distance 2025-11-22 04:44:57 +00:00
utils fix(calculations): handle negative electricity prices correctly 2025-11-22 04:45:23 +00:00
__init__.py feat(chart_export): migrate sensor config from UI to configuration.yaml 2025-11-20 13:41:26 +00:00
config_flow.py refactor(naming): complete class naming convention alignment 2025-11-20 11:22:53 +00:00
const.py feat(types): add TypedDict documentation and BaseCalculator helpers 2025-11-22 14:32:24 +00:00
data.py refactoring 2025-04-23 16:42:31 +00:00
diagnostics.py update dev environment 2025-11-03 15:54:01 +00:00
entity.py feat(api): add multi-home support and diagnostic sensors 2025-11-16 00:11:56 +00:00
manifest.json chore(release): bump version to 0.13.0 2025-11-22 04:47:44 +00:00
services.yaml feat(chart_export): add Chart Data Export diagnostic sensor 2025-11-17 03:14:02 +00:00