Files
core/homeassistant/components/fronius/entity.py
T
2026-08-26 08:56:41 -04:00

50 lines
1.6 KiB
Python

"""Base entity for the Fronius integration."""
from collections.abc import Callable
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any
from fronius_modbus import Controls, FroniusModbusInverter, Storage
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
if TYPE_CHECKING:
from .coordinator import FroniusCoordinatorBase
# the model a writable setting lives in, picked off a discovered inverter
type ModbusComponent = Controls | Storage
type ModbusComponentFn = Callable[[FroniusModbusInverter], ModbusComponent | None]
@dataclass(frozen=True)
class FroniusEntityDescription(EntityDescription):
"""Base class for Fronius entity descriptions."""
response_key: str | None = None
class FroniusEntity(CoordinatorEntity["FroniusCoordinatorBase"]):
"""Defines a Fronius coordinator entity."""
entity_description: FroniusEntityDescription
_attr_has_entity_name = True
def __init__(
self,
coordinator: FroniusCoordinatorBase,
description: FroniusEntityDescription,
solar_net_id: str,
) -> None:
"""Set up an individual Fronius coordinator entity."""
super().__init__(coordinator)
self.entity_description = description
self.response_key = description.response_key or description.key
self.solar_net_id = solar_net_id
self._attr_translation_key = description.translation_key or description.key
def _device_data(self) -> dict[str, Any]:
"""Extract information for SolarNet device from coordinator data."""
return self.coordinator.data[self.solar_net_id]