1 """Sensor for myUplink."""
3 from myuplink
import DevicePoint
8 SensorEntityDescription,
12 REVOLUTIONS_PER_MINUTE,
14 UnitOfElectricCurrent,
27 from .
import MyUplinkConfigEntry, MyUplinkDataCoordinator
28 from .const
import F_SERIES
29 from .entity
import MyUplinkEntity
30 from .helpers
import find_matching_platform, skip_entity, transform_model_series
32 DEVICE_POINT_UNIT_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
35 device_class=SensorDeviceClass.TEMPERATURE,
36 state_class=SensorStateClass.MEASUREMENT,
37 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
41 device_class=SensorDeviceClass.TEMPERATURE,
42 state_class=SensorStateClass.MEASUREMENT,
43 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
47 device_class=SensorDeviceClass.CURRENT,
48 state_class=SensorStateClass.MEASUREMENT,
49 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
53 device_class=SensorDeviceClass.PRESSURE,
54 state_class=SensorStateClass.MEASUREMENT,
55 native_unit_of_measurement=UnitOfPressure.BAR,
59 device_class=SensorDeviceClass.DURATION,
60 state_class=SensorStateClass.MEASUREMENT,
61 native_unit_of_measurement=UnitOfTime.DAYS,
62 suggested_display_precision=0,
66 device_class=SensorDeviceClass.DURATION,
67 state_class=SensorStateClass.MEASUREMENT,
68 native_unit_of_measurement=UnitOfTime.HOURS,
69 suggested_display_precision=1,
73 device_class=SensorDeviceClass.DURATION,
74 state_class=SensorStateClass.MEASUREMENT,
75 native_unit_of_measurement=UnitOfTime.HOURS,
76 suggested_display_precision=1,
80 device_class=SensorDeviceClass.FREQUENCY,
81 state_class=SensorStateClass.MEASUREMENT,
82 native_unit_of_measurement=UnitOfFrequency.HERTZ,
86 device_class=SensorDeviceClass.POWER,
87 state_class=SensorStateClass.MEASUREMENT,
88 native_unit_of_measurement=UnitOfPower.KILO_WATT,
92 device_class=SensorDeviceClass.ENERGY,
93 state_class=SensorStateClass.TOTAL_INCREASING,
94 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
98 translation_key=
"airflow",
99 device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
100 state_class=SensorStateClass.MEASUREMENT,
101 native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
105 device_class=SensorDeviceClass.DURATION,
106 state_class=SensorStateClass.MEASUREMENT,
107 native_unit_of_measurement=UnitOfTime.MINUTES,
108 suggested_display_precision=0,
112 device_class=SensorDeviceClass.PRESSURE,
113 state_class=SensorStateClass.MEASUREMENT,
114 native_unit_of_measurement=UnitOfPressure.PA,
115 suggested_display_precision=0,
119 translation_key=
"rpm",
120 state_class=SensorStateClass.MEASUREMENT,
121 native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
122 suggested_display_precision=0,
126 device_class=SensorDeviceClass.DURATION,
127 state_class=SensorStateClass.MEASUREMENT,
128 native_unit_of_measurement=UnitOfTime.SECONDS,
129 suggested_display_precision=0,
133 device_class=SensorDeviceClass.DURATION,
134 state_class=SensorStateClass.MEASUREMENT,
135 native_unit_of_measurement=UnitOfTime.SECONDS,
136 suggested_display_precision=0,
140 MARKER_FOR_UNKNOWN_VALUE = -32768
142 CATEGORY_BASED_DESCRIPTIONS: dict[str, dict[str, SensorEntityDescription]] = {
146 translation_key=
"fan_mode",
149 key=
"status_compressor",
150 translation_key=
"status_compressor",
151 device_class=SensorDeviceClass.ENUM,
155 translation_key=
"elect_add",
156 device_class=SensorDeviceClass.ENUM,
160 translation_key=
"priority",
161 device_class=SensorDeviceClass.ENUM,
165 translation_key=
"status",
166 device_class=SensorDeviceClass.ENUM,
172 translation_key=
"fan_mode",
175 key=
"status_compressor",
176 translation_key=
"status_compressor",
177 device_class=SensorDeviceClass.ENUM,
181 translation_key=
"elect_add",
182 device_class=SensorDeviceClass.ENUM,
186 translation_key=
"priority",
187 device_class=SensorDeviceClass.ENUM,
195 """Get description for a device point.
198 1. Category specific prefix e.g "NIBEF"
199 2. Global parameter_unit e.g. "°C"
203 prefix, _, _ = device_point.category.partition(
" ")
205 description = CATEGORY_BASED_DESCRIPTIONS.get(prefix, {}).
get(
206 device_point.parameter_id
208 if description
is None:
209 description = DEVICE_POINT_UNIT_DESCRIPTIONS.get(device_point.parameter_unit)
216 config_entry: MyUplinkConfigEntry,
217 async_add_entities: AddEntitiesCallback,
219 """Set up myUplink sensor."""
221 entities: list[SensorEntity] = []
222 coordinator = config_entry.runtime_data
225 for device_id, point_data
in coordinator.data.points.items():
226 for point_id, device_point
in point_data.items():
227 if skip_entity(device_point.category, device_point):
231 entity_class = MyUplinkDevicePointSensor
233 if description
is None and not isinstance(
234 device_point.value, (int, float)
238 description
is not None
239 and description.device_class == SensorDeviceClass.ENUM
243 coordinator=coordinator,
245 device_point=device_point,
246 entity_description=description,
247 unique_id_suffix=f
"{point_id}-raw",
250 entity_class = MyUplinkEnumSensor
254 coordinator=coordinator,
256 device_point=device_point,
257 entity_description=description,
258 unique_id_suffix=point_id,
266 """Representation of a myUplink device point sensor."""
270 coordinator: MyUplinkDataCoordinator,
272 device_point: DevicePoint,
273 entity_description: SensorEntityDescription |
None,
274 unique_id_suffix: str,
276 """Initialize the sensor."""
278 coordinator=coordinator,
280 unique_id_suffix=unique_id_suffix,
286 self.
_attr_name_attr_name = device_point.parameter_name.replace(
"\u00ad",
"")
288 if entity_description
is not None:
295 """Sensor state value."""
296 device_point = self.coordinator.data.points[self.
device_iddevice_id][self.
point_idpoint_id]
297 if device_point.value == MARKER_FOR_UNKNOWN_VALUE:
299 return device_point.value
303 """Representation of a myUplink device point sensor for ENUM device_class."""
307 coordinator: MyUplinkDataCoordinator,
309 device_point: DevicePoint,
310 entity_description: SensorEntityDescription |
None,
311 unique_id_suffix: str,
313 """Initialize the sensor."""
315 coordinator=coordinator,
317 device_point=device_point,
318 entity_description=entity_description,
319 unique_id_suffix=unique_id_suffix,
322 self.
_attr_options_attr_options = [x[
"text"].capitalize()
for x
in device_point.enum_values]
324 x[
"value"]: x[
"text"].capitalize()
for x
in device_point.enum_values
329 """Sensor state value for enum sensor."""
330 device_point = self.coordinator.data.points[self.
device_iddevice_id][self.
point_idpoint_id]
335 """Representation of a myUplink device point sensor for raw value from ENUM device_class."""
337 _attr_entity_registry_enabled_default =
False
338 _attr_device_class =
None
342 coordinator: MyUplinkDataCoordinator,
344 device_point: DevicePoint,
345 entity_description: SensorEntityDescription |
None,
346 unique_id_suffix: str,
348 """Initialize the sensor."""
350 coordinator=coordinator,
352 device_point=device_point,
353 entity_description=entity_description,
354 unique_id_suffix=unique_id_suffix,
StateType native_value(self)
None __init__(self, MyUplinkDataCoordinator coordinator, str device_id, DevicePoint device_point, SensorEntityDescription|None entity_description, str unique_id_suffix)
_attr_native_unit_of_measurement
None __init__(self, MyUplinkDataCoordinator coordinator, str device_id, DevicePoint device_point, SensorEntityDescription|None entity_description, str unique_id_suffix)
None __init__(self, MyUplinkDataCoordinator coordinator, str device_id, DevicePoint device_point, SensorEntityDescription|None entity_description, str unique_id_suffix)
web.Response get(self, web.Request request, str config_key)
str transform_model_series(str prefix)
bool skip_entity(str model, DevicePoint device_point)
Platform find_matching_platform(DevicePoint device_point, SensorEntityDescription|NumberEntityDescription|None description=None)
None async_setup_entry(HomeAssistant hass, MyUplinkConfigEntry config_entry, AddEntitiesCallback async_add_entities)
SensorEntityDescription|None get_description(DevicePoint device_point)