1 """Support for Rflink sensors."""
3 from __future__
import annotations
7 from rflink.parser
import PACKET_FIELDS, UNITS
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
14 SensorEntityDescription,
18 CONCENTRATION_PARTS_PER_MILLION,
22 CONF_UNIT_OF_MEASUREMENT,
27 UnitOfElectricCurrent,
28 UnitOfElectricPotential,
31 UnitOfPrecipitationDepth,
55 from .entity
import RflinkDevice
60 key=
"average_windspeed",
61 name=
"Average windspeed",
62 device_class=SensorDeviceClass.WIND_SPEED,
63 state_class=SensorStateClass.MEASUREMENT,
64 native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
67 key=
"barometric_pressure",
68 name=
"Barometric pressure",
69 device_class=SensorDeviceClass.PRESSURE,
70 state_class=SensorStateClass.MEASUREMENT,
71 native_unit_of_measurement=UnitOfPressure.HPA,
81 key=
"co2_air_quality",
82 name=
"CO2 air quality",
83 device_class=SensorDeviceClass.CO2,
84 state_class=SensorStateClass.MEASUREMENT,
85 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
93 key=
"current_phase_1",
94 name=
"Current phase 1",
95 device_class=SensorDeviceClass.CURRENT,
96 state_class=SensorStateClass.MEASUREMENT,
97 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
100 key=
"current_phase_2",
101 name=
"Current phase 2",
102 device_class=SensorDeviceClass.CURRENT,
103 state_class=SensorStateClass.MEASUREMENT,
104 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
107 key=
"current_phase_3",
108 name=
"Current phase 3",
109 device_class=SensorDeviceClass.CURRENT,
110 state_class=SensorStateClass.MEASUREMENT,
111 native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
116 device_class=SensorDeviceClass.DISTANCE,
117 state_class=SensorStateClass.MEASUREMENT,
118 native_unit_of_measurement=UnitOfLength.MILLIMETERS,
121 key=
"doorbell_melody",
122 name=
"Doorbell melody",
128 icon=
"mdi:information-outline",
138 device_class=SensorDeviceClass.HUMIDITY,
139 state_class=SensorStateClass.MEASUREMENT,
140 native_unit_of_measurement=PERCENTAGE,
143 key=
"humidity_status",
144 name=
"Humidity status",
145 icon=
"mdi:water-percent",
150 device_class=SensorDeviceClass.POWER,
151 state_class=SensorStateClass.MEASUREMENT,
152 native_unit_of_measurement=UnitOfPower.KILO_WATT,
155 key=
"light_intensity",
156 name=
"Light intensity",
157 device_class=SensorDeviceClass.ILLUMINANCE,
158 state_class=SensorStateClass.MEASUREMENT,
159 native_unit_of_measurement=LIGHT_LUX,
169 icon=
"mdi:bell-alert",
174 device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
175 state_class=SensorStateClass.MEASUREMENT,
176 native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
181 icon=
"mdi:information",
186 device_class=SensorDeviceClass.TEMPERATURE,
187 state_class=SensorStateClass.MEASUREMENT,
188 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
193 device_class=SensorDeviceClass.PRECIPITATION,
194 state_class=SensorStateClass.TOTAL_INCREASING,
195 native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
200 icon=
"mdi:sunglasses",
201 state_class=SensorStateClass.MEASUREMENT,
202 native_unit_of_measurement=UV_INDEX,
207 icon=
"mdi:information",
212 device_class=SensorDeviceClass.VOLTAGE,
213 state_class=SensorStateClass.MEASUREMENT,
214 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
219 device_class=SensorDeviceClass.POWER,
220 state_class=SensorStateClass.MEASUREMENT,
221 native_unit_of_measurement=UnitOfPower.WATT,
224 key=
"weather_forecast",
225 name=
"Weather forecast",
226 icon=
"mdi:weather-cloudy-clock",
231 device_class=SensorDeviceClass.TEMPERATURE,
232 state_class=SensorStateClass.MEASUREMENT,
233 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
237 name=
"Wind direction",
239 state_class=SensorStateClass.MEASUREMENT,
240 native_unit_of_measurement=DEGREE,
245 device_class=SensorDeviceClass.WIND_SPEED,
246 state_class=SensorStateClass.MEASUREMENT,
247 native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
252 device_class=SensorDeviceClass.WIND_SPEED,
253 state_class=SensorStateClass.MEASUREMENT,
254 native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
258 name=
"Wind temperature",
259 device_class=SensorDeviceClass.TEMPERATURE,
260 state_class=SensorStateClass.MEASUREMENT,
261 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
265 SENSOR_TYPES_DICT = {desc.key: desc
for desc
in SENSOR_TYPES}
267 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
269 vol.Optional(CONF_AUTOMATIC_ADD, default=
True): cv.boolean,
270 vol.Optional(CONF_DEVICES, default={}): {
271 cv.string: vol.Schema(
273 vol.Optional(CONF_NAME): cv.string,
274 vol.Required(CONF_SENSOR_TYPE): cv.string,
275 vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
276 vol.Optional(CONF_ALIASES, default=[]): vol.All(
277 cv.ensure_list, [cv.string]
283 extra=vol.ALLOW_EXTRA,
288 """Get unit for sensor type.
292 field_abbrev = {v: k
for k, v
in PACKET_FIELDS.items()}
294 return UNITS.get(field_abbrev.get(sensor_type))
298 """Parse configuration and add Rflink sensor devices."""
300 for device_id, config
in domain_config[CONF_DEVICES].items():
302 devices.append(device)
310 async_add_entities: AddEntitiesCallback,
311 discovery_info: DiscoveryInfoType |
None =
None,
313 """Set up the Rflink platform."""
317 """Check if device is known, otherwise create device entity."""
318 device_id = event[EVENT_KEY_ID]
322 event[EVENT_KEY_SENSOR],
323 event[EVENT_KEY_UNIT],
329 if config[CONF_AUTOMATIC_ADD]:
330 hass.data[DATA_DEVICE_REGISTER][EVENT_KEY_SENSOR] = add_new_device
334 """Representation of a Rflink sensor."""
340 unit_of_measurement: str |
None =
None,
344 """Handle sensor specific args and super init."""
347 if sensor_type
in SENSOR_TYPES_DICT:
349 elif not unit_of_measurement:
352 super().
__init__(device_id, initial_event=initial_event, **kwargs)
355 """Domain specific event handler."""
360 """Register update callback."""
362 tmp_entity = TMP_ENTITY.format(self.
_device_id_device_id)
365 in self.
hasshass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][self.
_device_id_device_id]
367 self.
hasshass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][
372 self.
hasshass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][self.
_device_id_device_id].append(
377 self.
hasshass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][_id].append(
388 SIGNAL_HANDLE_EVENT.format(self.
entity_identity_id),
399 """Return measurement unit."""
402 if hasattr(self,
"entity_description"):
def handle_event_callback(self, event)
def _availability_callback(self, availability)
None __init__(self, str device_id, str sensor_type, str|None unit_of_measurement=None, initial_event=None, **Any kwargs)
def _handle_event(self, event)
def native_unit_of_measurement(self)
None async_added_to_hass(self)
None async_on_remove(self, CALLBACK_TYPE func)
bool remove(self, _T matcher)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
def devices_from_config(domain_config)
def lookup_unit_for_sensor_type(sensor_type)
def add_new_device(new_device)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)