Add new atmospheric pressure device class (#83455)
* Add new atmospheric pressure device class * Translations * Automatic conversion * Convert all pressure units
This commit is contained in:
parent
061cef1a5e
commit
b172abaeeb
8 changed files with 70 additions and 0 deletions
|
@ -69,6 +69,12 @@ class NumberDeviceClass(StrEnum):
|
|||
Unit of measurement: `None`
|
||||
"""
|
||||
|
||||
ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||
"""Atmospheric pressure.
|
||||
|
||||
Unit of measurement: `UnitOfPressure` units
|
||||
"""
|
||||
|
||||
BATTERY = "battery"
|
||||
"""Percentage of battery that is left.
|
||||
|
||||
|
|
|
@ -133,6 +133,12 @@ class SensorDeviceClass(StrEnum):
|
|||
Unit of measurement: `None`
|
||||
"""
|
||||
|
||||
ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||
"""Atmospheric pressure.
|
||||
|
||||
Unit of measurement: `UnitOfPressure` units
|
||||
"""
|
||||
|
||||
BATTERY = "battery"
|
||||
"""Percentage of battery that is left.
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
|||
DEVICE_CLASS_NONE = "none"
|
||||
|
||||
CONF_IS_APPARENT_POWER = "is_apparent_power"
|
||||
CONF_IS_ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||
CONF_IS_BATTERY_LEVEL = "is_battery_level"
|
||||
CONF_IS_CO = "is_carbon_monoxide"
|
||||
CONF_IS_CO2 = "is_carbon_dioxide"
|
||||
|
@ -74,6 +75,7 @@ CONF_IS_WIND_SPEED = "is_wind_speed"
|
|||
|
||||
ENTITY_CONDITIONS = {
|
||||
SensorDeviceClass.APPARENT_POWER: [{CONF_TYPE: CONF_IS_APPARENT_POWER}],
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE: [{CONF_TYPE: CONF_IS_ATMOSPHERIC_PRESSURE}],
|
||||
SensorDeviceClass.BATTERY: [{CONF_TYPE: CONF_IS_BATTERY_LEVEL}],
|
||||
SensorDeviceClass.CO: [{CONF_TYPE: CONF_IS_CO}],
|
||||
SensorDeviceClass.CO2: [{CONF_TYPE: CONF_IS_CO2}],
|
||||
|
@ -126,6 +128,7 @@ CONDITION_SCHEMA = vol.All(
|
|||
vol.Required(CONF_TYPE): vol.In(
|
||||
[
|
||||
CONF_IS_APPARENT_POWER,
|
||||
CONF_IS_ATMOSPHERIC_PRESSURE,
|
||||
CONF_IS_BATTERY_LEVEL,
|
||||
CONF_IS_CO,
|
||||
CONF_IS_CO2,
|
||||
|
|
|
@ -31,6 +31,7 @@ from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
|||
DEVICE_CLASS_NONE = "none"
|
||||
|
||||
CONF_APPARENT_POWER = "apparent_power"
|
||||
CONF_ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||
CONF_BATTERY_LEVEL = "battery_level"
|
||||
CONF_CO = "carbon_monoxide"
|
||||
CONF_CO2 = "carbon_dioxide"
|
||||
|
@ -73,6 +74,7 @@ CONF_WIND_SPEED = "wind_speed"
|
|||
|
||||
ENTITY_TRIGGERS = {
|
||||
SensorDeviceClass.APPARENT_POWER: [{CONF_TYPE: CONF_APPARENT_POWER}],
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE: [{CONF_TYPE: CONF_ATMOSPHERIC_PRESSURE}],
|
||||
SensorDeviceClass.BATTERY: [{CONF_TYPE: CONF_BATTERY_LEVEL}],
|
||||
SensorDeviceClass.CO: [{CONF_TYPE: CONF_CO}],
|
||||
SensorDeviceClass.CO2: [{CONF_TYPE: CONF_CO2}],
|
||||
|
@ -126,6 +128,7 @@ TRIGGER_SCHEMA = vol.All(
|
|||
vol.Required(CONF_TYPE): vol.In(
|
||||
[
|
||||
CONF_APPARENT_POWER,
|
||||
CONF_ATMOSPHERIC_PRESSURE,
|
||||
CONF_BATTERY_LEVEL,
|
||||
CONF_CO,
|
||||
CONF_CO2,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"device_automation": {
|
||||
"condition_type": {
|
||||
"is_apparent_power": "Current {entity_name} apparent power",
|
||||
"is_atmospheric_pressure": "Current {entity_name} atmospheric pressure",
|
||||
"is_battery_level": "Current {entity_name} battery level",
|
||||
"is_carbon_monoxide": "Current {entity_name} carbon monoxide concentration level",
|
||||
"is_carbon_dioxide": "Current {entity_name} carbon dioxide concentration level",
|
||||
|
@ -42,6 +43,7 @@
|
|||
},
|
||||
"trigger_type": {
|
||||
"apparent_power": "{entity_name} apparent power changes",
|
||||
"atmospheric_pressure": "{entity_name} atmospheric pressure changes",
|
||||
"battery_level": "{entity_name} battery level changes",
|
||||
"carbon_monoxide": "{entity_name} carbon monoxide concentration changes",
|
||||
"carbon_dioxide": "{entity_name} carbon dioxide concentration changes",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"device_automation": {
|
||||
"condition_type": {
|
||||
"is_apparent_power": "Current {entity_name} apparent power",
|
||||
"is_atmospheric_pressure": "Current {entity_name} atmospheric pressure",
|
||||
"is_battery_level": "Current {entity_name} battery level",
|
||||
"is_carbon_dioxide": "Current {entity_name} carbon dioxide concentration level",
|
||||
"is_carbon_monoxide": "Current {entity_name} carbon monoxide concentration level",
|
||||
|
@ -41,6 +42,7 @@
|
|||
},
|
||||
"trigger_type": {
|
||||
"apparent_power": "{entity_name} apparent power changes",
|
||||
"atmospheric_pressure": "{entity_name} atmospheric pressure changes",
|
||||
"battery_level": "{entity_name} battery level changes",
|
||||
"carbon_dioxide": "{entity_name} carbon dioxide concentration changes",
|
||||
"carbon_monoxide": "{entity_name} carbon monoxide concentration changes",
|
||||
|
|
|
@ -250,6 +250,12 @@ METRIC_SYSTEM = UnitSystem(
|
|||
_CONF_UNIT_SYSTEM_METRIC,
|
||||
accumulated_precipitation=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||
conversions={
|
||||
# Force atmospheric pressures to hPa
|
||||
**{
|
||||
("atmospheric_pressure", unit): UnitOfPressure.HPA
|
||||
for unit in UnitOfPressure
|
||||
if unit != UnitOfPressure.HPA
|
||||
},
|
||||
# Convert non-metric distances
|
||||
("distance", UnitOfLength.FEET): UnitOfLength.METERS,
|
||||
("distance", UnitOfLength.INCHES): UnitOfLength.MILLIMETERS,
|
||||
|
@ -282,6 +288,12 @@ US_CUSTOMARY_SYSTEM = UnitSystem(
|
|||
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
||||
accumulated_precipitation=UnitOfPrecipitationDepth.INCHES,
|
||||
conversions={
|
||||
# Force atmospheric pressures to inHg
|
||||
**{
|
||||
("atmospheric_pressure", unit): UnitOfPressure.INHG
|
||||
for unit in UnitOfPressure
|
||||
if unit != UnitOfPressure.INHG
|
||||
},
|
||||
# Convert non-USCS distances
|
||||
("distance", UnitOfLength.CENTIMETERS): UnitOfLength.INCHES,
|
||||
("distance", UnitOfLength.KILOMETERS): UnitOfLength.MILES,
|
||||
|
|
|
@ -380,6 +380,24 @@ def test_get_unit_system_invalid(key: str) -> None:
|
|||
@pytest.mark.parametrize(
|
||||
"device_class, original_unit, state_unit",
|
||||
(
|
||||
# Test atmospheric pressure
|
||||
(
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
UnitOfPressure.PSI,
|
||||
UnitOfPressure.HPA,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
UnitOfPressure.BAR,
|
||||
UnitOfPressure.HPA,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
UnitOfPressure.INHG,
|
||||
UnitOfPressure.HPA,
|
||||
),
|
||||
(SensorDeviceClass.ATMOSPHERIC_PRESSURE, UnitOfPressure.HPA, None),
|
||||
(SensorDeviceClass.ATMOSPHERIC_PRESSURE, "very_much", None),
|
||||
# Test distance conversion
|
||||
(SensorDeviceClass.DISTANCE, UnitOfLength.FEET, UnitOfLength.METERS),
|
||||
(SensorDeviceClass.DISTANCE, UnitOfLength.INCHES, UnitOfLength.MILLIMETERS),
|
||||
|
@ -435,6 +453,24 @@ def test_get_metric_converted_unit_(
|
|||
@pytest.mark.parametrize(
|
||||
"device_class, original_unit, state_unit",
|
||||
(
|
||||
# Test atmospheric pressure
|
||||
(
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
UnitOfPressure.PSI,
|
||||
UnitOfPressure.INHG,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
UnitOfPressure.BAR,
|
||||
UnitOfPressure.INHG,
|
||||
),
|
||||
(
|
||||
SensorDeviceClass.ATMOSPHERIC_PRESSURE,
|
||||
UnitOfPressure.HPA,
|
||||
UnitOfPressure.INHG,
|
||||
),
|
||||
(SensorDeviceClass.ATMOSPHERIC_PRESSURE, UnitOfPressure.INHG, None),
|
||||
(SensorDeviceClass.ATMOSPHERIC_PRESSURE, "very_much", None),
|
||||
# Test distance conversion
|
||||
(SensorDeviceClass.DISTANCE, UnitOfLength.CENTIMETERS, UnitOfLength.INCHES),
|
||||
(SensorDeviceClass.DISTANCE, UnitOfLength.KILOMETERS, UnitOfLength.MILES),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue