Home Assistant Unofficial Reference 2024.12.1
const.py
Go to the documentation of this file.
1 """Constants for the Tuya integration."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 from dataclasses import dataclass, field
7 from enum import StrEnum
8 import logging
9 
10 from homeassistant.components.sensor import SensorDeviceClass
11 from homeassistant.const import (
12  CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
13  CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
14  CONCENTRATION_PARTS_PER_BILLION,
15  CONCENTRATION_PARTS_PER_MILLION,
16  LIGHT_LUX,
17  PERCENTAGE,
18  SIGNAL_STRENGTH_DECIBELS,
19  SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
20  Platform,
21  UnitOfElectricCurrent,
22  UnitOfElectricPotential,
23  UnitOfEnergy,
24  UnitOfPower,
25  UnitOfPressure,
26  UnitOfTemperature,
27  UnitOfVolume,
28 )
29 
30 DOMAIN = "tuya"
31 LOGGER = logging.getLogger(__package__)
32 
33 CONF_APP_TYPE = "tuya_app_type"
34 CONF_ENDPOINT = "endpoint"
35 CONF_TERMINAL_ID = "terminal_id"
36 CONF_TOKEN_INFO = "token_info"
37 CONF_USER_CODE = "user_code"
38 CONF_USERNAME = "username"
39 
40 TUYA_CLIENT_ID = "HA_3y9q4ak7g4ephrvke"
41 TUYA_SCHEMA = "haauthorize"
42 
43 TUYA_DISCOVERY_NEW = "tuya_discovery_new"
44 TUYA_HA_SIGNAL_UPDATE_ENTITY = "tuya_entry_update"
45 
46 TUYA_RESPONSE_CODE = "code"
47 TUYA_RESPONSE_MSG = "msg"
48 TUYA_RESPONSE_QR_CODE = "qrcode"
49 TUYA_RESPONSE_RESULT = "result"
50 TUYA_RESPONSE_SUCCESS = "success"
51 
52 PLATFORMS = [
53  Platform.ALARM_CONTROL_PANEL,
54  Platform.BINARY_SENSOR,
55  Platform.BUTTON,
56  Platform.CAMERA,
57  Platform.CLIMATE,
58  Platform.COVER,
59  Platform.FAN,
60  Platform.HUMIDIFIER,
61  Platform.LIGHT,
62  Platform.NUMBER,
63  Platform.SCENE,
64  Platform.SELECT,
65  Platform.SENSOR,
66  Platform.SIREN,
67  Platform.SWITCH,
68  Platform.VACUUM,
69 ]
70 
71 
72 class WorkMode(StrEnum):
73  """Work modes."""
74 
75  COLOUR = "colour"
76  MUSIC = "music"
77  SCENE = "scene"
78  WHITE = "white"
79 
80 
81 class DPType(StrEnum):
82  """Data point types."""
83 
84  BOOLEAN = "Boolean"
85  ENUM = "Enum"
86  INTEGER = "Integer"
87  JSON = "Json"
88  RAW = "Raw"
89  STRING = "String"
90 
91 
92 class DPCode(StrEnum):
93  """Data Point Codes used by Tuya.
94 
95  https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
96  """
97 
98  AIR_QUALITY = "air_quality"
99  AIR_QUALITY_INDEX = "air_quality_index"
100  ALARM_SWITCH = "alarm_switch" # Alarm switch
101  ALARM_TIME = "alarm_time" # Alarm time
102  ALARM_VOLUME = "alarm_volume" # Alarm volume
103  ALARM_MESSAGE = "alarm_message"
104  ANGLE_HORIZONTAL = "angle_horizontal"
105  ANGLE_VERTICAL = "angle_vertical"
106  ANION = "anion" # Ionizer unit
107  ARM_DOWN_PERCENT = "arm_down_percent"
108  ARM_UP_PERCENT = "arm_up_percent"
109  BASIC_ANTI_FLICKER = "basic_anti_flicker"
110  BASIC_DEVICE_VOLUME = "basic_device_volume"
111  BASIC_FLIP = "basic_flip"
112  BASIC_INDICATOR = "basic_indicator"
113  BASIC_NIGHTVISION = "basic_nightvision"
114  BASIC_OSD = "basic_osd"
115  BASIC_PRIVATE = "basic_private"
116  BASIC_WDR = "basic_wdr"
117  BATTERY = "battery" # Used by non-standard contact sensor implementations
118  BATTERY_PERCENTAGE = "battery_percentage" # Battery percentage
119  BATTERY_STATE = "battery_state" # Battery state
120  BATTERY_VALUE = "battery_value" # Battery value
121  BRIGHT_CONTROLLER = "bright_controller"
122  BRIGHT_STATE = "bright_state" # Brightness status
123  BRIGHT_VALUE = "bright_value" # Brightness
124  BRIGHT_VALUE_1 = "bright_value_1"
125  BRIGHT_VALUE_2 = "bright_value_2"
126  BRIGHT_VALUE_3 = "bright_value_3"
127  BRIGHT_VALUE_V2 = "bright_value_v2"
128  BRIGHTNESS_MAX_1 = "brightness_max_1"
129  BRIGHTNESS_MAX_2 = "brightness_max_2"
130  BRIGHTNESS_MAX_3 = "brightness_max_3"
131  BRIGHTNESS_MIN_1 = "brightness_min_1"
132  BRIGHTNESS_MIN_2 = "brightness_min_2"
133  BRIGHTNESS_MIN_3 = "brightness_min_3"
134  C_F = "c_f" # Temperature unit switching
135  CH2O_STATE = "ch2o_state"
136  CH2O_VALUE = "ch2o_value"
137  CH4_SENSOR_STATE = "ch4_sensor_state"
138  CH4_SENSOR_VALUE = "ch4_sensor_value"
139  CHILD_LOCK = "child_lock" # Child lock
140  CISTERN = "cistern"
141  CLEAN_AREA = "clean_area"
142  CLEAN_TIME = "clean_time"
143  CLICK_SUSTAIN_TIME = "click_sustain_time"
144  CLOUD_RECIPE_NUMBER = "cloud_recipe_number"
145  CLOSED_OPENED_KIT = "closed_opened_kit"
146  CO_STATE = "co_state"
147  CO_STATUS = "co_status"
148  CO_VALUE = "co_value"
149  CO2_STATE = "co2_state"
150  CO2_VALUE = "co2_value" # CO2 concentration
151  COLLECTION_MODE = "collection_mode"
152  COLOR_DATA_V2 = "color_data_v2"
153  COLOUR_DATA = "colour_data" # Colored light mode
154  COLOUR_DATA_HSV = "colour_data_hsv" # Colored light mode
155  COLOUR_DATA_V2 = "colour_data_v2" # Colored light mode
156  COOK_TEMPERATURE = "cook_temperature"
157  COOK_TIME = "cook_time"
158  CONCENTRATION_SET = "concentration_set" # Concentration setting
159  CONTROL = "control"
160  CONTROL_2 = "control_2"
161  CONTROL_3 = "control_3"
162  CONTROL_BACK = "control_back"
163  CONTROL_BACK_MODE = "control_back_mode"
164  COUNTDOWN = "countdown" # Countdown
165  COUNTDOWN_LEFT = "countdown_left"
166  COUNTDOWN_SET = "countdown_set" # Countdown setting
167  CRY_DETECTION_SWITCH = "cry_detection_switch"
168  CUP_NUMBER = "cup_number" # NUmber of cups
169  CUR_CURRENT = "cur_current" # Actual current
170  CUR_NEUTRAL = "cur_neutral" # Total reverse energy
171  CUR_POWER = "cur_power" # Actual power
172  CUR_VOLTAGE = "cur_voltage" # Actual voltage
173  DECIBEL_SENSITIVITY = "decibel_sensitivity"
174  DECIBEL_SWITCH = "decibel_switch"
175  DEHUMIDITY_SET_ENUM = "dehumidify_set_enum"
176  DEHUMIDITY_SET_VALUE = "dehumidify_set_value"
177  DISINFECTION = "disinfection"
178  DO_NOT_DISTURB = "do_not_disturb"
179  DOORCONTACT_STATE = "doorcontact_state" # Status of door window sensor
180  DOORCONTACT_STATE_2 = "doorcontact_state_2"
181  DOORCONTACT_STATE_3 = "doorcontact_state_3"
182  DUSTER_CLOTH = "duster_cloth"
183  ECO2 = "eco2"
184  EDGE_BRUSH = "edge_brush"
185  ELECTRICITY_LEFT = "electricity_left"
186  FAN_BEEP = "fan_beep" # Sound
187  FAN_COOL = "fan_cool" # Cool wind
188  FAN_DIRECTION = "fan_direction" # Fan direction
189  FAN_HORIZONTAL = "fan_horizontal" # Horizontal swing flap angle
190  FAN_SPEED = "fan_speed"
191  FAN_SPEED_ENUM = "fan_speed_enum" # Speed mode
192  FAN_SPEED_PERCENT = "fan_speed_percent" # Stepless speed
193  FAN_SWITCH = "fan_switch"
194  FAN_MODE = "fan_mode"
195  FAN_VERTICAL = "fan_vertical" # Vertical swing flap angle
196  FAR_DETECTION = "far_detection"
197  FAULT = "fault"
198  FEED_REPORT = "feed_report"
199  FEED_STATE = "feed_state"
200  FILTER = "filter"
201  FILTER_LIFE = "filter"
202  FILTER_RESET = "filter_reset" # Filter (cartridge) reset
203  FLOODLIGHT_LIGHTNESS = "floodlight_lightness"
204  FLOODLIGHT_SWITCH = "floodlight_switch"
205  FORWARD_ENERGY_TOTAL = "forward_energy_total"
206  GAS_SENSOR_STATE = "gas_sensor_state"
207  GAS_SENSOR_STATUS = "gas_sensor_status"
208  GAS_SENSOR_VALUE = "gas_sensor_value"
209  HUMIDIFIER = "humidifier" # Humidification
210  HUMIDITY = "humidity" # Humidity
211  HUMIDITY_CURRENT = "humidity_current" # Current humidity
212  HUMIDITY_INDOOR = "humidity_indoor" # Indoor humidity
213  HUMIDITY_SET = "humidity_set" # Humidity setting
214  HUMIDITY_VALUE = "humidity_value" # Humidity
215  IPC_WORK_MODE = "ipc_work_mode"
216  LED_TYPE_1 = "led_type_1"
217  LED_TYPE_2 = "led_type_2"
218  LED_TYPE_3 = "led_type_3"
219  LEVEL = "level"
220  LEVEL_CURRENT = "level_current"
221  LIGHT = "light" # Light
222  LIGHT_MODE = "light_mode"
223  LOCK = "lock" # Lock / Child lock
224  MASTER_MODE = "master_mode" # alarm mode
225  MACH_OPERATE = "mach_operate"
226  MANUAL_FEED = "manual_feed"
227  MATERIAL = "material" # Material
228  MODE = "mode" # Working mode / Mode
229  MOODLIGHTING = "moodlighting" # Mood light
230  MOTION_RECORD = "motion_record"
231  MOTION_SENSITIVITY = "motion_sensitivity"
232  MOTION_SWITCH = "motion_switch" # Motion switch
233  MOTION_TRACKING = "motion_tracking"
234  MOVEMENT_DETECT_PIC = "movement_detect_pic"
235  MUFFLING = "muffling" # Muffling
236  NEAR_DETECTION = "near_detection"
237  OPPOSITE = "opposite"
238  PAUSE = "pause"
239  PERCENT_CONTROL = "percent_control"
240  PERCENT_CONTROL_2 = "percent_control_2"
241  PERCENT_CONTROL_3 = "percent_control_3"
242  PERCENT_STATE = "percent_state"
243  PERCENT_STATE_2 = "percent_state_2"
244  PERCENT_STATE_3 = "percent_state_3"
245  POSITION = "position"
246  PHASE_A = "phase_a"
247  PHASE_B = "phase_b"
248  PHASE_C = "phase_c"
249  PIR = "pir" # Motion sensor
250  PM1 = "pm1"
251  PM10 = "pm10"
252  PM25 = "pm25"
253  PM25_STATE = "pm25_state"
254  PM25_VALUE = "pm25_value"
255  POWDER_SET = "powder_set" # Powder
256  POWER = "power"
257  POWER_GO = "power_go"
258  POWER_TOTAL = "power_total"
259  PRESENCE_STATE = "presence_state"
260  PRESSURE_STATE = "pressure_state"
261  PRESSURE_VALUE = "pressure_value"
262  PUMP = "pump"
263  PUMP_RESET = "pump_reset" # Water pump reset
264  OXYGEN = "oxygen" # Oxygen bar
265  RECORD_MODE = "record_mode"
266  RECORD_SWITCH = "record_switch" # Recording switch
267  RELAY_STATUS = "relay_status"
268  REMAIN_TIME = "remain_time"
269  RESET_DUSTER_CLOTH = "reset_duster_cloth"
270  RESET_EDGE_BRUSH = "reset_edge_brush"
271  RESET_FILTER = "reset_filter"
272  RESET_MAP = "reset_map"
273  RESET_ROLL_BRUSH = "reset_roll_brush"
274  REVERSE_ENERGY_TOTAL = "reverse_energy_total"
275  ROLL_BRUSH = "roll_brush"
276  SEEK = "seek"
277  SENSITIVITY = "sensitivity" # Sensitivity
278  SENSOR_HUMIDITY = "sensor_humidity"
279  SENSOR_TEMPERATURE = "sensor_temperature"
280  SHAKE = "shake" # Oscillating
281  SHOCK_STATE = "shock_state" # Vibration status
282  SIREN_SWITCH = "siren_switch"
283  SITUATION_SET = "situation_set"
284  SLEEP = "sleep" # Sleep function
285  SLOW_FEED = "slow_feed"
286  SMOKE_SENSOR_STATE = "smoke_sensor_state"
287  SMOKE_SENSOR_STATUS = "smoke_sensor_status"
288  SMOKE_SENSOR_VALUE = "smoke_sensor_value"
289  SOS = "sos" # Emergency State
290  SOS_STATE = "sos_state" # Emergency mode
291  SPEED = "speed" # Speed level
292  SPRAY_MODE = "spray_mode" # Spraying mode
293  START = "start" # Start
294  STATUS = "status"
295  STERILIZATION = "sterilization" # Sterilization
296  SUCTION = "suction"
297  SWING = "swing" # Swing mode
298  SWITCH = "switch" # Switch
299  SWITCH_1 = "switch_1" # Switch 1
300  SWITCH_2 = "switch_2" # Switch 2
301  SWITCH_3 = "switch_3" # Switch 3
302  SWITCH_4 = "switch_4" # Switch 4
303  SWITCH_5 = "switch_5" # Switch 5
304  SWITCH_6 = "switch_6" # Switch 6
305  SWITCH_7 = "switch_7" # Switch 7
306  SWITCH_8 = "switch_8" # Switch 8
307  SWITCH_BACKLIGHT = "switch_backlight" # Backlight switch
308  SWITCH_CHARGE = "switch_charge"
309  SWITCH_CONTROLLER = "switch_controller"
310  SWITCH_DISTURB = "switch_disturb"
311  SWITCH_FAN = "switch_fan"
312  SWITCH_HORIZONTAL = "switch_horizontal" # Horizontal swing flap switch
313  SWITCH_LED = "switch_led" # Switch
314  SWITCH_LED_1 = "switch_led_1"
315  SWITCH_LED_2 = "switch_led_2"
316  SWITCH_LED_3 = "switch_led_3"
317  SWITCH_NIGHT_LIGHT = "switch_night_light"
318  SWITCH_SAVE_ENERGY = "switch_save_energy"
319  SWITCH_SOUND = "switch_sound" # Voice switch
320  SWITCH_SPRAY = "switch_spray" # Spraying switch
321  SWITCH_USB1 = "switch_usb1" # USB 1
322  SWITCH_USB2 = "switch_usb2" # USB 2
323  SWITCH_USB3 = "switch_usb3" # USB 3
324  SWITCH_USB4 = "switch_usb4" # USB 4
325  SWITCH_USB5 = "switch_usb5" # USB 5
326  SWITCH_USB6 = "switch_usb6" # USB 6
327  SWITCH_VERTICAL = "switch_vertical" # Vertical swing flap switch
328  SWITCH_VOICE = "switch_voice" # Voice switch
329  TARGET_DIS_CLOSEST = "target_dis_closest" # Closest target distance
330  TEMP = "temp" # Temperature setting
331  TEMP_BOILING_C = "temp_boiling_c"
332  TEMP_BOILING_F = "temp_boiling_f"
333  TEMP_CONTROLLER = "temp_controller"
334  TEMP_CURRENT = "temp_current" # Current temperature in °C
335  TEMP_CURRENT_F = "temp_current_f" # Current temperature in °F
336  TEMP_INDOOR = "temp_indoor" # Indoor temperature in °C
337  TEMP_SET = "temp_set" # Set the temperature in °C
338  TEMP_SET_F = "temp_set_f" # Set the temperature in °F
339  TEMP_UNIT_CONVERT = "temp_unit_convert" # Temperature unit switching
340  TEMP_VALUE = "temp_value" # Color temperature
341  TEMP_VALUE_V2 = "temp_value_v2"
342  TEMPER_ALARM = "temper_alarm" # Tamper alarm
343  TIME_TOTAL = "time_total"
344  TIME_USE = "time_use" # Total seconds of irrigation
345  TOTAL_CLEAN_AREA = "total_clean_area"
346  TOTAL_CLEAN_COUNT = "total_clean_count"
347  TOTAL_CLEAN_TIME = "total_clean_time"
348  TOTAL_FORWARD_ENERGY = "total_forward_energy"
349  TOTAL_TIME = "total_time"
350  TOTAL_PM = "total_pm"
351  TOTAL_POWER = "total_power"
352  TVOC = "tvoc"
353  UPPER_TEMP = "upper_temp"
354  UPPER_TEMP_F = "upper_temp_f"
355  UV = "uv" # UV sterilization
356  VA_BATTERY = "va_battery"
357  VA_HUMIDITY = "va_humidity"
358  VA_TEMPERATURE = "va_temperature"
359  VOC_STATE = "voc_state"
360  VOC_VALUE = "voc_value"
361  VOICE_SWITCH = "voice_switch"
362  VOICE_TIMES = "voice_times"
363  VOLUME_SET = "volume_set"
364  WARM = "warm" # Heat preservation
365  WARM_TIME = "warm_time" # Heat preservation time
366  WATER = "water"
367  WATER_RESET = "water_reset" # Resetting of water usage days
368  WATER_SET = "water_set" # Water level
369  WATERSENSOR_STATE = "watersensor_state"
370  WEATHER_DELAY = "weather_delay"
371  WET = "wet" # Humidification
372  WINDOW_CHECK = "window_check"
373  WINDOW_STATE = "window_state"
374  WINDSPEED = "windspeed"
375  WIRELESS_BATTERYLOCK = "wireless_batterylock"
376  WIRELESS_ELECTRICITY = "wireless_electricity"
377  WORK_MODE = "work_mode" # Working mode
378  WORK_POWER = "work_power"
379 
380 
381 @dataclass
383  """Describes a unit of measurement."""
384 
385  unit: str
386  device_classes: set[str]
387 
388  aliases: set[str] = field(default_factory=set)
389  conversion_unit: str | None = None
390  conversion_fn: Callable[[float], float] | None = None
391 
392 
393 # A tuple of available units of measurements we can work with.
394 # Tuya's devices aren't consistent in UOM use, thus this provides
395 # a list of aliases for units and possible conversions we can do
396 # to make them compatible with our model.
397 UNITS = (
398  UnitOfMeasurement(
399  unit="",
400  aliases={" "},
401  device_classes={
402  SensorDeviceClass.AQI,
403  SensorDeviceClass.DATE,
404  SensorDeviceClass.MONETARY,
405  SensorDeviceClass.TIMESTAMP,
406  },
407  ),
408  UnitOfMeasurement(
409  unit=PERCENTAGE,
410  aliases={"pct", "percent", "% RH"},
411  device_classes={
412  SensorDeviceClass.BATTERY,
413  SensorDeviceClass.HUMIDITY,
414  SensorDeviceClass.POWER_FACTOR,
415  },
416  ),
417  UnitOfMeasurement(
418  unit=CONCENTRATION_PARTS_PER_MILLION,
419  device_classes={
420  SensorDeviceClass.CO,
421  SensorDeviceClass.CO2,
422  },
423  ),
424  UnitOfMeasurement(
425  unit=CONCENTRATION_PARTS_PER_BILLION,
426  device_classes={
427  SensorDeviceClass.CO,
428  SensorDeviceClass.CO2,
429  },
430  conversion_unit=CONCENTRATION_PARTS_PER_MILLION,
431  conversion_fn=lambda x: x / 1000,
432  ),
433  UnitOfMeasurement(
434  unit=UnitOfElectricCurrent.AMPERE,
435  aliases={"a", "ampere"},
436  device_classes={SensorDeviceClass.CURRENT},
437  ),
438  UnitOfMeasurement(
439  unit=UnitOfElectricCurrent.MILLIAMPERE,
440  aliases={"ma", "milliampere"},
441  device_classes={SensorDeviceClass.CURRENT},
442  conversion_unit=UnitOfElectricCurrent.AMPERE,
443  conversion_fn=lambda x: x / 1000,
444  ),
445  UnitOfMeasurement(
446  unit=UnitOfEnergy.WATT_HOUR,
447  aliases={"wh", "watthour"},
448  device_classes={SensorDeviceClass.ENERGY},
449  ),
450  UnitOfMeasurement(
451  unit=UnitOfEnergy.KILO_WATT_HOUR,
452  aliases={"kwh", "kilowatt-hour", "kW·h", "kW.h"},
453  device_classes={SensorDeviceClass.ENERGY},
454  ),
455  UnitOfMeasurement(
456  unit=UnitOfVolume.CUBIC_FEET,
457  aliases={"ft3"},
458  device_classes={SensorDeviceClass.GAS},
459  ),
460  UnitOfMeasurement(
461  unit=UnitOfVolume.CUBIC_METERS,
462  aliases={"m3"},
463  device_classes={SensorDeviceClass.GAS},
464  ),
465  UnitOfMeasurement(
466  unit=LIGHT_LUX,
467  aliases={"lux"},
468  device_classes={SensorDeviceClass.ILLUMINANCE},
469  ),
470  UnitOfMeasurement(
471  unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
472  aliases={"ug/m3", "µg/m3", "ug/m³"},
473  device_classes={
474  SensorDeviceClass.NITROGEN_DIOXIDE,
475  SensorDeviceClass.NITROGEN_MONOXIDE,
476  SensorDeviceClass.NITROUS_OXIDE,
477  SensorDeviceClass.OZONE,
478  SensorDeviceClass.PM1,
479  SensorDeviceClass.PM25,
480  SensorDeviceClass.PM10,
481  SensorDeviceClass.SULPHUR_DIOXIDE,
482  SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
483  },
484  ),
485  UnitOfMeasurement(
486  unit=CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER,
487  aliases={"mg/m3"},
488  device_classes={
489  SensorDeviceClass.NITROGEN_DIOXIDE,
490  SensorDeviceClass.NITROGEN_MONOXIDE,
491  SensorDeviceClass.NITROUS_OXIDE,
492  SensorDeviceClass.OZONE,
493  SensorDeviceClass.PM1,
494  SensorDeviceClass.PM25,
495  SensorDeviceClass.PM10,
496  SensorDeviceClass.SULPHUR_DIOXIDE,
497  SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS,
498  },
499  conversion_unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
500  conversion_fn=lambda x: x * 1000,
501  ),
502  UnitOfMeasurement(
503  unit=UnitOfPower.WATT,
504  aliases={"watt"},
505  device_classes={SensorDeviceClass.POWER},
506  ),
507  UnitOfMeasurement(
508  unit=UnitOfPower.KILO_WATT,
509  aliases={"kilowatt"},
510  device_classes={SensorDeviceClass.POWER},
511  ),
512  UnitOfMeasurement(
513  unit=UnitOfPressure.BAR,
514  device_classes={SensorDeviceClass.PRESSURE},
515  ),
516  UnitOfMeasurement(
517  unit=UnitOfPressure.MBAR,
518  aliases={"millibar"},
519  device_classes={SensorDeviceClass.PRESSURE},
520  ),
521  UnitOfMeasurement(
522  unit=UnitOfPressure.HPA,
523  aliases={"hpa", "hectopascal"},
524  device_classes={SensorDeviceClass.PRESSURE},
525  ),
526  UnitOfMeasurement(
527  unit=UnitOfPressure.INHG,
528  aliases={"inhg"},
529  device_classes={SensorDeviceClass.PRESSURE},
530  ),
531  UnitOfMeasurement(
532  unit=UnitOfPressure.PSI,
533  device_classes={SensorDeviceClass.PRESSURE},
534  ),
535  UnitOfMeasurement(
536  unit=UnitOfPressure.PA,
537  device_classes={SensorDeviceClass.PRESSURE},
538  ),
539  UnitOfMeasurement(
540  unit=SIGNAL_STRENGTH_DECIBELS,
541  aliases={"db"},
542  device_classes={SensorDeviceClass.SIGNAL_STRENGTH},
543  ),
544  UnitOfMeasurement(
545  unit=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
546  aliases={"dbm"},
547  device_classes={SensorDeviceClass.SIGNAL_STRENGTH},
548  ),
549  UnitOfMeasurement(
550  unit=UnitOfTemperature.CELSIUS,
551  aliases={"°c", "c", "celsius", "℃"},
552  device_classes={SensorDeviceClass.TEMPERATURE},
553  ),
554  UnitOfMeasurement(
555  unit=UnitOfTemperature.FAHRENHEIT,
556  aliases={"°f", "f", "fahrenheit"},
557  device_classes={SensorDeviceClass.TEMPERATURE},
558  ),
559  UnitOfMeasurement(
560  unit=UnitOfElectricPotential.VOLT,
561  aliases={"volt"},
562  device_classes={SensorDeviceClass.VOLTAGE},
563  ),
564  UnitOfMeasurement(
565  unit=UnitOfElectricPotential.MILLIVOLT,
566  aliases={"mv", "millivolt"},
567  device_classes={SensorDeviceClass.VOLTAGE},
568  conversion_unit=UnitOfElectricPotential.VOLT,
569  conversion_fn=lambda x: x / 1000,
570  ),
571 )
572 
573 
574 DEVICE_CLASS_UNITS: dict[str, dict[str, UnitOfMeasurement]] = {}
575 for uom in UNITS:
576  for device_class in uom.device_classes:
577  DEVICE_CLASS_UNITS.setdefault(device_class, {})[uom.unit] = uom
578  for unit_alias in uom.aliases:
579  DEVICE_CLASS_UNITS[device_class][unit_alias] = uom