1 """The read-only sensors for APsystems local API integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from APsystemsEZ1
import ReturnOutputData
13 SensorEntityDescription,
22 from .
import ApSystemsConfigEntry, ApSystemsData
23 from .coordinator
import ApSystemsDataCoordinator
24 from .entity
import ApSystemsEntity
27 @dataclass(frozen=True, kw_only=True)
29 """Describes Apsystens Inverter sensor entity."""
31 value_fn: Callable[[ReturnOutputData], float |
None]
34 SENSORS: tuple[ApsystemsLocalApiSensorDescription, ...] = (
37 translation_key=
"total_power",
38 native_unit_of_measurement=UnitOfPower.WATT,
39 device_class=SensorDeviceClass.POWER,
40 state_class=SensorStateClass.MEASUREMENT,
41 value_fn=
lambda c: c.p1 + c.p2,
45 translation_key=
"total_power_p1",
46 native_unit_of_measurement=UnitOfPower.WATT,
47 device_class=SensorDeviceClass.POWER,
48 state_class=SensorStateClass.MEASUREMENT,
49 value_fn=
lambda c: c.p1,
53 translation_key=
"total_power_p2",
54 native_unit_of_measurement=UnitOfPower.WATT,
55 device_class=SensorDeviceClass.POWER,
56 state_class=SensorStateClass.MEASUREMENT,
57 value_fn=
lambda c: c.p2,
60 key=
"lifetime_production",
61 translation_key=
"lifetime_production",
62 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
63 device_class=SensorDeviceClass.ENERGY,
64 state_class=SensorStateClass.TOTAL_INCREASING,
65 value_fn=
lambda c: c.te1 + c.te2,
68 key=
"lifetime_production_p1",
69 translation_key=
"lifetime_production_p1",
70 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
71 device_class=SensorDeviceClass.ENERGY,
72 state_class=SensorStateClass.TOTAL_INCREASING,
73 value_fn=
lambda c: c.te1,
76 key=
"lifetime_production_p2",
77 translation_key=
"lifetime_production_p2",
78 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
79 device_class=SensorDeviceClass.ENERGY,
80 state_class=SensorStateClass.TOTAL_INCREASING,
81 value_fn=
lambda c: c.te2,
84 key=
"today_production",
85 translation_key=
"today_production",
86 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
87 device_class=SensorDeviceClass.ENERGY,
88 state_class=SensorStateClass.TOTAL_INCREASING,
89 value_fn=
lambda c: c.e1 + c.e2,
92 key=
"today_production_p1",
93 translation_key=
"today_production_p1",
94 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
95 device_class=SensorDeviceClass.ENERGY,
96 state_class=SensorStateClass.TOTAL_INCREASING,
97 value_fn=
lambda c: c.e1,
100 key=
"today_production_p2",
101 translation_key=
"today_production_p2",
102 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
103 device_class=SensorDeviceClass.ENERGY,
104 state_class=SensorStateClass.TOTAL_INCREASING,
105 value_fn=
lambda c: c.e2,
112 config_entry: ApSystemsConfigEntry,
113 add_entities: AddEntitiesCallback,
114 discovery_info: DiscoveryInfoType |
None =
None,
116 """Set up the sensor platform."""
117 config = config_entry.runtime_data
122 entity_description=desc,
129 CoordinatorEntity[ApSystemsDataCoordinator], ApSystemsEntity, SensorEntity
131 """Base sensor to be used with description."""
133 entity_description: ApsystemsLocalApiSensorDescription
134 _attr_has_entity_name =
True
139 entity_description: ApsystemsLocalApiSensorDescription,
141 """Initialize the sensor."""
143 ApSystemsEntity.__init__(self, data)
149 """Return value of sensor."""
StateType native_value(self)
None __init__(self, ApSystemsData data, ApsystemsLocalApiSensorDescription entity_description)
None async_setup_entry(HomeAssistant hass, ApSystemsConfigEntry config_entry, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
def add_entities(account, async_add_entities, tracked)