mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-30 13:23:41 +00:00
Renamed 25 public classes + 1 Enum to include TibberPrices prefix
following Home Assistant integration naming standards.
All classes now follow pattern: TibberPrices{SemanticPurpose}
No package hierarchy in names (import path is namespace).
Key changes:
- Coordinator module: DataFetcher, DataTransformer, ListenerManager,
PeriodCalculator, TimeService (203 usages), CacheData
- Config flow: CannotConnectError, InvalidAuthError
- Entity utils: IconContext
- Sensor calculators: BaseCalculator + 8 subclasses
- Period handlers: 5 NamedTuples (PeriodConfig, PeriodData,
PeriodStatistics, ThresholdConfig, IntervalCriteria)
- Period handlers: SpikeCandidateContext (dataclass → NamedTuple)
- API: QueryType Enum
Documentation updates:
- AGENTS.md: Added Pyright code generation guidelines
- planning/class-naming-refactoring-plan.md: Complete execution log
Quality metrics:
- 0 Pyright errors (strict type checking)
- 0 Ruff errors (linting + formatting)
- All hassfest checks passed
- 79 files validated
Impact: Aligns with HA Core standards (TibberDataCoordinator pattern).
No user-facing changes - internal refactor only.
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
"""Trend attribute builders for Tibber Prices sensors."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from custom_components.tibber_prices.coordinator.time_service import TibberPricesTimeService
|
|
|
|
from .timing import add_period_timing_attributes
|
|
from .volatility import add_volatility_attributes
|
|
|
|
|
|
def _add_timing_or_volatility_attributes(
|
|
attributes: dict,
|
|
key: str,
|
|
cached_data: dict,
|
|
native_value: Any = None,
|
|
*,
|
|
time: TibberPricesTimeService,
|
|
) -> None:
|
|
"""Add attributes for timing or volatility sensors."""
|
|
if key.endswith("_volatility"):
|
|
add_volatility_attributes(attributes=attributes, cached_data=cached_data, time=time)
|
|
else:
|
|
add_period_timing_attributes(attributes=attributes, key=key, state_value=native_value, time=time)
|
|
|
|
|
|
def _add_cached_trend_attributes(attributes: dict, key: str, cached_data: dict) -> None:
|
|
"""Add cached trend attributes if available."""
|
|
if key.startswith("price_trend_") and cached_data.get("trend_attributes"):
|
|
attributes.update(cached_data["trend_attributes"])
|
|
elif key == "current_price_trend" and cached_data.get("current_trend_attributes"):
|
|
# Add cached attributes (timestamp already set by platform)
|
|
attributes.update(cached_data["current_trend_attributes"])
|
|
elif key == "next_price_trend_change" and cached_data.get("trend_change_attributes"):
|
|
# Add cached attributes (timestamp already set by platform)
|
|
# State contains the timestamp of the trend change itself
|
|
attributes.update(cached_data["trend_change_attributes"])
|