1 """Platform for sensor integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from technove
import Station
as TechnoVEStation, Status
13 SensorEntityDescription,
17 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
19 UnitOfElectricCurrent,
20 UnitOfElectricPotential,
27 from .
import TechnoVEConfigEntry
28 from .coordinator
import TechnoVEDataUpdateCoordinator
29 from .entity
import TechnoVEEntity
31 STATUS_TYPE = [s.value
for s
in Status
if s != Status.UNKNOWN]
34 @dataclass(frozen=True, kw_only=True)
36 """Describes TechnoVE sensor entity."""
38 value_fn: Callable[[TechnoVEStation], StateType]
41 SENSORS: tuple[TechnoVESensorEntityDescription, ...] = (
44 translation_key=
"voltage_in",
45 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
46 device_class=SensorDeviceClass.VOLTAGE,
47 state_class=SensorStateClass.MEASUREMENT,
48 entity_category=EntityCategory.DIAGNOSTIC,
49 value_fn=
lambda station: station.info.voltage_in,
53 translation_key=
"voltage_out",
54 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
55 device_class=SensorDeviceClass.VOLTAGE,
56 state_class=SensorStateClass.MEASUREMENT,
57 entity_category=EntityCategory.DIAGNOSTIC,
58 value_fn=
lambda station: station.info.voltage_out,
61 key=
"max_station_current",
62 translation_key=
"max_station_current",
63 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
64 device_class=SensorDeviceClass.CURRENT,
65 state_class=SensorStateClass.MEASUREMENT,
66 entity_category=EntityCategory.DIAGNOSTIC,
67 value_fn=
lambda station: station.info.max_station_current,
71 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
72 device_class=SensorDeviceClass.CURRENT,
73 state_class=SensorStateClass.MEASUREMENT,
74 entity_category=EntityCategory.DIAGNOSTIC,
75 value_fn=
lambda station: station.info.current,
79 translation_key=
"energy_total",
80 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
81 device_class=SensorDeviceClass.ENERGY,
82 state_class=SensorStateClass.TOTAL,
83 entity_category=EntityCategory.DIAGNOSTIC,
84 value_fn=
lambda station: station.info.energy_total,
88 translation_key=
"energy_session",
89 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
90 device_class=SensorDeviceClass.ENERGY,
91 state_class=SensorStateClass.TOTAL_INCREASING,
92 entity_category=EntityCategory.DIAGNOSTIC,
93 value_fn=
lambda station: station.info.energy_session,
97 native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
98 device_class=SensorDeviceClass.SIGNAL_STRENGTH,
99 state_class=SensorStateClass.MEASUREMENT,
100 entity_category=EntityCategory.DIAGNOSTIC,
101 entity_registry_enabled_default=
False,
102 value_fn=
lambda station: station.info.rssi,
106 translation_key=
"ssid",
107 entity_category=EntityCategory.DIAGNOSTIC,
108 entity_registry_enabled_default=
False,
109 value_fn=
lambda station: station.info.network_ssid,
113 translation_key=
"status",
114 device_class=SensorDeviceClass.ENUM,
116 entity_category=EntityCategory.DIAGNOSTIC,
117 value_fn=
lambda station: station.info.status.value,
124 entry: TechnoVEConfigEntry,
125 async_add_entities: AddEntitiesCallback,
127 """Set up the sensor platform."""
134 """Defines a TechnoVE sensor entity."""
136 entity_description: TechnoVESensorEntityDescription
140 coordinator: TechnoVEDataUpdateCoordinator,
141 description: TechnoVESensorEntityDescription,
143 """Initialize a TechnoVE sensor entity."""
144 super().
__init__(coordinator, description.key)
149 """Return the state of the sensor."""
None __init__(self, TechnoVEDataUpdateCoordinator coordinator, TechnoVESensorEntityDescription description)
StateType native_value(self)
None async_setup_entry(HomeAssistant hass, TechnoVEConfigEntry entry, AddEntitiesCallback async_add_entities)