1 """Support for the Zeversolar platform."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
13 SensorEntityDescription,
21 from .const
import DOMAIN
22 from .coordinator
import ZeversolarCoordinator
23 from .entity
import ZeversolarEntity
26 @dataclass(frozen=True, kw_only=True)
28 """Describes Zeversolar sensor entity."""
30 value_fn: Callable[[zeversolar.ZeverSolarData], zeversolar.kWh | zeversolar.Watt]
36 translation_key=
"pac",
37 native_unit_of_measurement=UnitOfPower.WATT,
38 state_class=SensorStateClass.MEASUREMENT,
39 entity_category=EntityCategory.DIAGNOSTIC,
40 device_class=SensorDeviceClass.POWER,
41 value_fn=
lambda data: data.pac,
45 translation_key=
"energy_today",
46 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
47 state_class=SensorStateClass.TOTAL_INCREASING,
48 device_class=SensorDeviceClass.ENERGY,
49 value_fn=
lambda data: data.energy_today,
55 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
57 """Set up the Zeversolar sensor."""
58 coordinator: ZeversolarCoordinator = hass.data[DOMAIN][entry.entry_id]
61 description=description,
62 coordinator=coordinator,
64 for description
in SENSOR_TYPES
69 """Implementation of the Zeversolar sensor."""
71 entity_description: ZeversolarEntityDescription
76 description: ZeversolarEntityDescription,
77 coordinator: ZeversolarCoordinator,
79 """Initialize the sensor."""
81 super().
__init__(coordinator=coordinator)
82 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.data.serial_number}_{description.key}"
86 """Return sensor state."""
None __init__(self, *ZeversolarEntityDescription description, ZeversolarCoordinator coordinator)
int|float native_value(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)