1 """Provides the constants needed for the component."""
3 from __future__
import annotations
5 from enum
import StrEnum
6 from functools
import partial
7 from typing
import Final
9 import voluptuous
as vol
12 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
13 CONCENTRATION_PARTS_PER_BILLION,
14 CONCENTRATION_PARTS_PER_MILLION,
17 SIGNAL_STRENGTH_DECIBELS,
18 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
21 UnitOfBloodGlucoseConcentration,
24 UnitOfElectricCurrent,
25 UnitOfElectricPotential,
33 UnitOfPrecipitationDepth,
45 DeprecatedConstantEnum,
46 all_with_deprecated_constants,
47 check_if_deprecated_constant,
48 dir_with_deprecated_constants,
53 VolumeFlowRateConverter,
60 ATTR_STEP_VALIDATION =
"step_validation"
62 DEFAULT_MIN_VALUE = 0.0
63 DEFAULT_MAX_VALUE = 100.0
68 SERVICE_SET_VALUE =
"set_value"
72 """Modes for number entities."""
80 _DEPRECATED_MODE_AUTO: Final = DeprecatedConstantEnum(NumberMode.AUTO,
"2025.1")
81 _DEPRECATED_MODE_BOX: Final = DeprecatedConstantEnum(NumberMode.BOX,
"2025.1")
82 _DEPRECATED_MODE_SLIDER: Final = DeprecatedConstantEnum(NumberMode.SLIDER,
"2025.1")
86 """Device class for numbers."""
90 APPARENT_POWER =
"apparent_power"
93 Unit of measurement: `VA`
99 Unit of measurement: `None`
105 Unit of measurement: `UnitOfArea` units
108 ATMOSPHERIC_PRESSURE =
"atmospheric_pressure"
109 """Atmospheric pressure.
111 Unit of measurement: `UnitOfPressure` units
115 """Percentage of battery that is left.
117 Unit of measurement: `%`
120 BLOOD_GLUCOSE_CONCENTRATION =
"blood_glucose_concentration"
121 """Blood glucose concentration.
123 Unit of measurement: `mg/dL`, `mmol/L`
126 CO =
"carbon_monoxide"
127 """Carbon Monoxide gas concentration.
129 Unit of measurement: `ppm` (parts per million)
132 CO2 =
"carbon_dioxide"
133 """Carbon Dioxide gas concentration.
135 Unit of measurement: `ppm` (parts per million)
138 CONDUCTIVITY =
"conductivity"
141 Unit of measurement: `S/cm`, `mS/cm`, `µS/cm`
147 Unit of measurement: `A`, `mA`
150 DATA_RATE =
"data_rate"
153 Unit of measurement: UnitOfDataRate
156 DATA_SIZE =
"data_size"
159 Unit of measurement: UnitOfInformation
162 DISTANCE =
"distance"
165 Unit of measurement: `LENGTH_*` units
166 - SI /metric: `mm`, `cm`, `m`, `km`
167 - USCS / imperial: `in`, `ft`, `yd`, `mi`
170 DURATION =
"duration"
173 Unit of measurement: `d`, `h`, `min`, `s`, `ms`
179 Unit of measurement: `Wh`, `kWh`, `MWh`, `GWh`, `TWh`, `MJ`, `GJ`
182 ENERGY_STORAGE =
"energy_storage"
185 Use this device class for sensors measuring stored energy, for example the amount
186 of electric energy currently stored in a battery or the capacity of a battery.
188 Unit of measurement: `Wh`, `kWh`, `MWh`, `GWh`, `TWh`, `MJ`, `GJ`
191 FREQUENCY =
"frequency"
194 Unit of measurement: `Hz`, `kHz`, `MHz`, `GHz`
202 - USCS / imperial: `ft³`, `CCF`
205 HUMIDITY =
"humidity"
206 """Relative humidity.
208 Unit of measurement: `%`
211 ILLUMINANCE =
"illuminance"
214 Unit of measurement: `lx`
217 IRRADIANCE =
"irradiance"
221 - SI / metric: `W/m²`
222 - USCS / imperial: `BTU/(h⋅ft²)`
225 MOISTURE =
"moisture"
228 Unit of measurement: `%`
231 MONETARY =
"monetary"
234 Unit of measurement: ISO4217 currency code
236 See https://en.wikipedia.org/wiki/ISO_4217#Active_codes for active codes
239 NITROGEN_DIOXIDE =
"nitrogen_dioxide"
242 Unit of measurement: `µg/m³`
245 NITROGEN_MONOXIDE =
"nitrogen_monoxide"
248 Unit of measurement: `µg/m³`
251 NITROUS_OXIDE =
"nitrous_oxide"
254 Unit of measurement: `µg/m³`
260 Unit of measurement: `µg/m³`
264 """Potential hydrogen (acidity/alkalinity).
266 Unit of measurement: Unitless
270 """Particulate matter <= 1 μm.
272 Unit of measurement: `µg/m³`
276 """Particulate matter <= 10 μm.
278 Unit of measurement: `µg/m³`
282 """Particulate matter <= 2.5 μm.
284 Unit of measurement: `µg/m³`
287 POWER_FACTOR =
"power_factor"
290 Unit of measurement: `%`, `None`
296 Unit of measurement: `W`, `kW`, `MW`, `GW`, `TW`
299 PRECIPITATION =
"precipitation"
300 """Accumulated precipitation.
302 Unit of measurement: UnitOfPrecipitationDepth
303 - SI / metric: `cm`, `mm`
304 - USCS / imperial: `in`
307 PRECIPITATION_INTENSITY =
"precipitation_intensity"
308 """Precipitation intensity.
310 Unit of measurement: UnitOfVolumetricFlux
311 - SI /metric: `mm/d`, `mm/h`
312 - USCS / imperial: `in/d`, `in/h`
315 PRESSURE =
"pressure"
319 - `mbar`, `cbar`, `bar`
325 REACTIVE_POWER =
"reactive_power"
328 Unit of measurement: `var`
331 SIGNAL_STRENGTH =
"signal_strength"
334 Unit of measurement: `dB`, `dBm`
337 SOUND_PRESSURE =
"sound_pressure"
340 Unit of measurement: `dB`, `dBA`
346 Unit of measurement: `SPEED_*` units or `UnitOfVolumetricFlux`
347 - SI /metric: `mm/d`, `mm/h`, `m/s`, `km/h`
348 - USCS / imperial: `in/d`, `in/h`, `ft/s`, `mph`
352 SULPHUR_DIOXIDE =
"sulphur_dioxide"
355 Unit of measurement: `µg/m³`
358 TEMPERATURE =
"temperature"
361 Unit of measurement: `°C`, `°F`, `K`
364 VOLATILE_ORGANIC_COMPOUNDS =
"volatile_organic_compounds"
367 Unit of measurement: `µg/m³`
370 VOLATILE_ORGANIC_COMPOUNDS_PARTS =
"volatile_organic_compounds_parts"
373 Unit of measurement: `ppm`, `ppb`
379 Unit of measurement: `V`, `mV`, `µV`
385 Unit of measurement: `VOLUME_*` units
386 - SI / metric: `mL`, `L`, `m³`
387 - USCS / imperial: `ft³`, `CCF`, `fl. oz.`, `gal` (warning: volumes expressed in
388 USCS/imperial units are currently assumed to be US volumes)
391 VOLUME_STORAGE =
"volume_storage"
392 """Generic stored volume.
394 Use this device class for sensors measuring stored volume, for example the amount
395 of fuel in a fuel tank.
397 Unit of measurement: `VOLUME_*` units
398 - SI / metric: `mL`, `L`, `m³`
399 - USCS / imperial: `ft³`, `CCF`, `fl. oz.`, `gal` (warning: volumes expressed in
400 USCS/imperial units are currently assumed to be US volumes)
403 VOLUME_FLOW_RATE =
"volume_flow_rate"
406 Unit of measurement: UnitOfVolumeFlowRate
407 - SI / metric: `m³/h`, `L/min`, `mL/s`
408 - USCS / imperial: `ft³/min`, `gal/min`
415 - SI / metric: `m³`, `L`
416 - USCS / imperial: `ft³`, `CCF`, `gal` (warning: volumes expressed in
417 USCS/imperial units are currently assumed to be US volumes)
421 """Generic weight, represents a measurement of an object's mass.
423 Weight is used instead of mass to fit with every day language.
425 Unit of measurement: `MASS_*` units
426 - SI / metric: `µg`, `mg`, `g`, `kg`
427 - USCS / imperial: `oz`, `lb`
430 WIND_SPEED =
"wind_speed"
433 Unit of measurement: `SPEED_*` units
434 - SI /metric: `m/s`, `km/h`
435 - USCS / imperial: `ft/s`, `mph`
440 DEVICE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(NumberDeviceClass))
441 DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str |
None]] = {
442 NumberDeviceClass.APPARENT_POWER: set(UnitOfApparentPower),
443 NumberDeviceClass.AQI: {
None},
444 NumberDeviceClass.AREA: set(UnitOfArea),
445 NumberDeviceClass.ATMOSPHERIC_PRESSURE: set(UnitOfPressure),
446 NumberDeviceClass.BATTERY: {PERCENTAGE},
447 NumberDeviceClass.BLOOD_GLUCOSE_CONCENTRATION: set(UnitOfBloodGlucoseConcentration),
448 NumberDeviceClass.CO: {CONCENTRATION_PARTS_PER_MILLION},
449 NumberDeviceClass.CO2: {CONCENTRATION_PARTS_PER_MILLION},
450 NumberDeviceClass.CONDUCTIVITY: set(UnitOfConductivity),
451 NumberDeviceClass.CURRENT: set(UnitOfElectricCurrent),
452 NumberDeviceClass.DATA_RATE: set(UnitOfDataRate),
453 NumberDeviceClass.DATA_SIZE: set(UnitOfInformation),
454 NumberDeviceClass.DISTANCE: set(UnitOfLength),
455 NumberDeviceClass.DURATION: {
460 UnitOfTime.MILLISECONDS,
462 NumberDeviceClass.ENERGY: set(UnitOfEnergy),
463 NumberDeviceClass.ENERGY_STORAGE: set(UnitOfEnergy),
464 NumberDeviceClass.FREQUENCY: set(UnitOfFrequency),
465 NumberDeviceClass.GAS: {
466 UnitOfVolume.CENTUM_CUBIC_FEET,
467 UnitOfVolume.CUBIC_FEET,
468 UnitOfVolume.CUBIC_METERS,
470 NumberDeviceClass.HUMIDITY: {PERCENTAGE},
471 NumberDeviceClass.ILLUMINANCE: {LIGHT_LUX},
472 NumberDeviceClass.IRRADIANCE: set(UnitOfIrradiance),
473 NumberDeviceClass.MOISTURE: {PERCENTAGE},
474 NumberDeviceClass.NITROGEN_DIOXIDE: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
475 NumberDeviceClass.NITROGEN_MONOXIDE: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
476 NumberDeviceClass.NITROUS_OXIDE: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
477 NumberDeviceClass.OZONE: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
478 NumberDeviceClass.PH: {
None},
479 NumberDeviceClass.PM1: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
480 NumberDeviceClass.PM10: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
481 NumberDeviceClass.PM25: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
482 NumberDeviceClass.POWER_FACTOR: {PERCENTAGE,
None},
483 NumberDeviceClass.POWER: {
485 UnitOfPower.KILO_WATT,
486 UnitOfPower.MEGA_WATT,
487 UnitOfPower.GIGA_WATT,
488 UnitOfPower.TERA_WATT,
490 NumberDeviceClass.PRECIPITATION: set(UnitOfPrecipitationDepth),
491 NumberDeviceClass.PRECIPITATION_INTENSITY: set(UnitOfVolumetricFlux),
492 NumberDeviceClass.PRESSURE: set(UnitOfPressure),
493 NumberDeviceClass.REACTIVE_POWER: {UnitOfReactivePower.VOLT_AMPERE_REACTIVE},
494 NumberDeviceClass.SIGNAL_STRENGTH: {
495 SIGNAL_STRENGTH_DECIBELS,
496 SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
498 NumberDeviceClass.SOUND_PRESSURE: set(UnitOfSoundPressure),
499 NumberDeviceClass.SPEED: set(UnitOfSpeed).union(set(UnitOfVolumetricFlux)),
500 NumberDeviceClass.SULPHUR_DIOXIDE: {CONCENTRATION_MICROGRAMS_PER_CUBIC_METER},
501 NumberDeviceClass.TEMPERATURE: set(UnitOfTemperature),
502 NumberDeviceClass.VOLATILE_ORGANIC_COMPOUNDS: {
503 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
505 NumberDeviceClass.VOLATILE_ORGANIC_COMPOUNDS_PARTS: {
506 CONCENTRATION_PARTS_PER_BILLION,
507 CONCENTRATION_PARTS_PER_MILLION,
509 NumberDeviceClass.VOLTAGE: set(UnitOfElectricPotential),
510 NumberDeviceClass.VOLUME: set(UnitOfVolume),
511 NumberDeviceClass.VOLUME_STORAGE: set(UnitOfVolume),
512 NumberDeviceClass.VOLUME_FLOW_RATE: set(UnitOfVolumeFlowRate),
513 NumberDeviceClass.WATER: {
514 UnitOfVolume.CENTUM_CUBIC_FEET,
515 UnitOfVolume.CUBIC_FEET,
516 UnitOfVolume.CUBIC_METERS,
517 UnitOfVolume.GALLONS,
520 NumberDeviceClass.WEIGHT: set(UnitOfMass),
521 NumberDeviceClass.WIND_SPEED: set(UnitOfSpeed),
524 UNIT_CONVERTERS: dict[NumberDeviceClass, type[BaseUnitConverter]] = {
525 NumberDeviceClass.TEMPERATURE: TemperatureConverter,
526 NumberDeviceClass.VOLUME_FLOW_RATE: VolumeFlowRateConverter,
530 __getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
532 dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
list[str] all_with_deprecated_constants(dict[str, Any] module_globals)