hass.tibber_prices/custom_components/tibber_prices/switch/definitions.py
Julian Pawlowski f8fd0f4936 refactor(entities): remove redundant name= from all entity descriptions
All entity descriptions had hardcoded English name= strings that were
never used at runtime: HA always prefers translations via translation_key
(entity.<platform>.<key>.name in translations/en.json), making the name=
fields dead code.

Removed 106 lines across all four platforms:
- sensor/definitions.py: 85 name= lines
- number/definitions.py: 12 name= lines
- binary_sensor/definitions.py: 6 name= lines
- switch/definitions.py: 3 name= lines

No functional change. The unique_id (entry_id + key) and translation_key
remain stable, ensuring entity IDs and friendly names are unaffected.

Impact: Cleaner definitions, no drift between name= strings and
translations. Aligns with HA standard: translations are the single
source of truth for entity names.
2026-04-06 13:16:07 +00:00

81 lines
3 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)
# ============================================================================
BEST_PRICE_SWITCH_ENTITIES = (
SwitchEntityDescription(
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,
),
)
# 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