hass.tibber_prices/custom_components/tibber_prices/switch/definitions.py
Julian Pawlowski 2f704a35a3 refactor: remove dead code across integration
Remove unused functions, constants, and entity definitions that were
left over from previous refactorings. All removed code was either
superseded by better implementations or never actually called.

Removed functions:
- entity_utils/helpers.py: translate_level(), translate_rating_level()
  (HA handles ENUM translation automatically via translations/*.json)
- entity_utils/attributes.py: build_timestamp_attribute(),
  build_period_attributes() (superseded by inline implementations)
- sensor/helpers.py: get_hourly_price_value(), aggregate_window_data()
  (replaced by Calculator Pattern in sensor/calculators/)

Removed constants and definitions:
- const.py: CONF_CHART_DATA_CONFIG (DATA_CHART_CONFIG is the active one),
  PRICE_LEVEL_OPTIONS, PRICE_RATING_OPTIONS, VOLATILITY_OPTIONS,
  PRICE_TREND_OPTIONS (never imported; options defined inline in
  definitions.py due to HA import timing constraints),
  async_get_home_type_translation() (sync version used instead)
- coordinator/core.py: FRESH_TO_CACHED_SECONDS (leftover from old
  caching strategy, never referenced)
- switch/definitions.py: BEST_PRICE_SWITCH_ENTITIES (duplicate of
  BEST_PRICE_SWITCH_ENTITY_DESCRIPTIONS using base class instead of
  custom TibberPricesSwitchEntityDescription subclass)

Cleanup:
- entity_utils/__init__.py: Remove exports for deleted functions
- sensor/helpers.py: Remove now-unused imports (timedelta,
  get_intervals_for_day_offsets, get_price_value, Callable)
- entity_utils/helpers.py: Remove unused get_price_level_translation
  import after translate_level() removal
- sensor/definitions.py: Update 7x "Keep in sync with *_OPTIONS"
  comments to reference individual PRICE_LEVEL_*/PRICE_RATING_*/
  VOLATILITY_* constants instead

Impact: No user-visible changes. Reduces codebase by ~130 lines.
Improves maintainability by eliminating misleading dead code.
2026-04-11 12:13:26 +00:00

71 lines
2.7 KiB
Python

"""
Switch entity definitions for Tibber Prices configuration overrides.
These switch entities allow runtime configuration of boolean settings
for Best Price and Peak Price period calculations.
When enabled, the entity value takes precedence over the options flow setting.
When disabled (default), the options flow setting is used.
"""
from __future__ import annotations
from dataclasses import dataclass
from homeassistant.components.switch import SwitchEntityDescription
from homeassistant.const import EntityCategory
@dataclass(frozen=True, kw_only=True)
class TibberPricesSwitchEntityDescription(SwitchEntityDescription):
"""Describes a Tibber Prices switch entity for config overrides."""
# The config key this entity overrides (matches CONF_* constants)
config_key: str
# The section in options where this setting is stored
config_section: str
# Whether this is for best_price (False) or peak_price (True)
is_peak_price: bool = False
# Default value from const.py
default_value: bool = True
# ============================================================================
# BEST PRICE PERIOD CONFIGURATION OVERRIDES (Boolean)
# ============================================================================
# Custom descriptions with extra fields
BEST_PRICE_SWITCH_ENTITY_DESCRIPTIONS = (
TibberPricesSwitchEntityDescription(
key="best_price_enable_relaxation_override",
translation_key="best_price_enable_relaxation_override",
icon="mdi:arrow-down-bold-circle",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
config_key="enable_min_periods_best",
config_section="relaxation_and_target_periods",
is_peak_price=False,
default_value=True, # DEFAULT_ENABLE_MIN_PERIODS_BEST
),
)
# ============================================================================
# PEAK PRICE PERIOD CONFIGURATION OVERRIDES (Boolean)
# ============================================================================
PEAK_PRICE_SWITCH_ENTITY_DESCRIPTIONS = (
TibberPricesSwitchEntityDescription(
key="peak_price_enable_relaxation_override",
translation_key="peak_price_enable_relaxation_override",
icon="mdi:arrow-up-bold-circle",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
config_key="enable_min_periods_peak",
config_section="relaxation_and_target_periods",
is_peak_price=True,
default_value=True, # DEFAULT_ENABLE_MIN_PERIODS_PEAK
),
)
# All switch entity descriptions combined
SWITCH_ENTITY_DESCRIPTIONS = BEST_PRICE_SWITCH_ENTITY_DESCRIPTIONS + PEAK_PRICE_SWITCH_ENTITY_DESCRIPTIONS