mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
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
@ -69,6 +69,12 @@ class NumberDeviceClass(StrEnum):
|
|||||||
Unit of measurement: `None`
|
Unit of measurement: `None`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||||
|
"""Atmospheric pressure.
|
||||||
|
|
||||||
|
Unit of measurement: `UnitOfPressure` units
|
||||||
|
"""
|
||||||
|
|
||||||
BATTERY = "battery"
|
BATTERY = "battery"
|
||||||
"""Percentage of battery that is left.
|
"""Percentage of battery that is left.
|
||||||
|
|
||||||
|
@ -133,6 +133,12 @@ class SensorDeviceClass(StrEnum):
|
|||||||
Unit of measurement: `None`
|
Unit of measurement: `None`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||||
|
"""Atmospheric pressure.
|
||||||
|
|
||||||
|
Unit of measurement: `UnitOfPressure` units
|
||||||
|
"""
|
||||||
|
|
||||||
BATTERY = "battery"
|
BATTERY = "battery"
|
||||||
"""Percentage of battery that is left.
|
"""Percentage of battery that is left.
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
|||||||
DEVICE_CLASS_NONE = "none"
|
DEVICE_CLASS_NONE = "none"
|
||||||
|
|
||||||
CONF_IS_APPARENT_POWER = "is_apparent_power"
|
CONF_IS_APPARENT_POWER = "is_apparent_power"
|
||||||
|
CONF_IS_ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||||
CONF_IS_BATTERY_LEVEL = "is_battery_level"
|
CONF_IS_BATTERY_LEVEL = "is_battery_level"
|
||||||
CONF_IS_CO = "is_carbon_monoxide"
|
CONF_IS_CO = "is_carbon_monoxide"
|
||||||
CONF_IS_CO2 = "is_carbon_dioxide"
|
CONF_IS_CO2 = "is_carbon_dioxide"
|
||||||
@ -74,6 +75,7 @@ CONF_IS_WIND_SPEED = "is_wind_speed"
|
|||||||
|
|
||||||
ENTITY_CONDITIONS = {
|
ENTITY_CONDITIONS = {
|
||||||
SensorDeviceClass.APPARENT_POWER: [{CONF_TYPE: CONF_IS_APPARENT_POWER}],
|
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.BATTERY: [{CONF_TYPE: CONF_IS_BATTERY_LEVEL}],
|
||||||
SensorDeviceClass.CO: [{CONF_TYPE: CONF_IS_CO}],
|
SensorDeviceClass.CO: [{CONF_TYPE: CONF_IS_CO}],
|
||||||
SensorDeviceClass.CO2: [{CONF_TYPE: CONF_IS_CO2}],
|
SensorDeviceClass.CO2: [{CONF_TYPE: CONF_IS_CO2}],
|
||||||
@ -126,6 +128,7 @@ CONDITION_SCHEMA = vol.All(
|
|||||||
vol.Required(CONF_TYPE): vol.In(
|
vol.Required(CONF_TYPE): vol.In(
|
||||||
[
|
[
|
||||||
CONF_IS_APPARENT_POWER,
|
CONF_IS_APPARENT_POWER,
|
||||||
|
CONF_IS_ATMOSPHERIC_PRESSURE,
|
||||||
CONF_IS_BATTERY_LEVEL,
|
CONF_IS_BATTERY_LEVEL,
|
||||||
CONF_IS_CO,
|
CONF_IS_CO,
|
||||||
CONF_IS_CO2,
|
CONF_IS_CO2,
|
||||||
|
@ -31,6 +31,7 @@ from . import ATTR_STATE_CLASS, DOMAIN, SensorDeviceClass
|
|||||||
DEVICE_CLASS_NONE = "none"
|
DEVICE_CLASS_NONE = "none"
|
||||||
|
|
||||||
CONF_APPARENT_POWER = "apparent_power"
|
CONF_APPARENT_POWER = "apparent_power"
|
||||||
|
CONF_ATMOSPHERIC_PRESSURE = "atmospheric_pressure"
|
||||||
CONF_BATTERY_LEVEL = "battery_level"
|
CONF_BATTERY_LEVEL = "battery_level"
|
||||||
CONF_CO = "carbon_monoxide"
|
CONF_CO = "carbon_monoxide"
|
||||||
CONF_CO2 = "carbon_dioxide"
|
CONF_CO2 = "carbon_dioxide"
|
||||||
@ -73,6 +74,7 @@ CONF_WIND_SPEED = "wind_speed"
|
|||||||
|
|
||||||
ENTITY_TRIGGERS = {
|
ENTITY_TRIGGERS = {
|
||||||
SensorDeviceClass.APPARENT_POWER: [{CONF_TYPE: CONF_APPARENT_POWER}],
|
SensorDeviceClass.APPARENT_POWER: [{CONF_TYPE: CONF_APPARENT_POWER}],
|
||||||
|
SensorDeviceClass.ATMOSPHERIC_PRESSURE: [{CONF_TYPE: CONF_ATMOSPHERIC_PRESSURE}],
|
||||||
SensorDeviceClass.BATTERY: [{CONF_TYPE: CONF_BATTERY_LEVEL}],
|
SensorDeviceClass.BATTERY: [{CONF_TYPE: CONF_BATTERY_LEVEL}],
|
||||||
SensorDeviceClass.CO: [{CONF_TYPE: CONF_CO}],
|
SensorDeviceClass.CO: [{CONF_TYPE: CONF_CO}],
|
||||||
SensorDeviceClass.CO2: [{CONF_TYPE: CONF_CO2}],
|
SensorDeviceClass.CO2: [{CONF_TYPE: CONF_CO2}],
|
||||||
@ -126,6 +128,7 @@ TRIGGER_SCHEMA = vol.All(
|
|||||||
vol.Required(CONF_TYPE): vol.In(
|
vol.Required(CONF_TYPE): vol.In(
|
||||||
[
|
[
|
||||||
CONF_APPARENT_POWER,
|
CONF_APPARENT_POWER,
|
||||||
|
CONF_ATMOSPHERIC_PRESSURE,
|
||||||
CONF_BATTERY_LEVEL,
|
CONF_BATTERY_LEVEL,
|
||||||
CONF_CO,
|
CONF_CO,
|
||||||
CONF_CO2,
|
CONF_CO2,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"device_automation": {
|
"device_automation": {
|
||||||
"condition_type": {
|
"condition_type": {
|
||||||
"is_apparent_power": "Current {entity_name} apparent power",
|
"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_battery_level": "Current {entity_name} battery level",
|
||||||
"is_carbon_monoxide": "Current {entity_name} carbon monoxide concentration level",
|
"is_carbon_monoxide": "Current {entity_name} carbon monoxide concentration level",
|
||||||
"is_carbon_dioxide": "Current {entity_name} carbon dioxide concentration level",
|
"is_carbon_dioxide": "Current {entity_name} carbon dioxide concentration level",
|
||||||
@ -42,6 +43,7 @@
|
|||||||
},
|
},
|
||||||
"trigger_type": {
|
"trigger_type": {
|
||||||
"apparent_power": "{entity_name} apparent power changes",
|
"apparent_power": "{entity_name} apparent power changes",
|
||||||
|
"atmospheric_pressure": "{entity_name} atmospheric pressure changes",
|
||||||
"battery_level": "{entity_name} battery level changes",
|
"battery_level": "{entity_name} battery level changes",
|
||||||
"carbon_monoxide": "{entity_name} carbon monoxide concentration changes",
|
"carbon_monoxide": "{entity_name} carbon monoxide concentration changes",
|
||||||
"carbon_dioxide": "{entity_name} carbon dioxide concentration changes",
|
"carbon_dioxide": "{entity_name} carbon dioxide concentration changes",
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"device_automation": {
|
"device_automation": {
|
||||||
"condition_type": {
|
"condition_type": {
|
||||||
"is_apparent_power": "Current {entity_name} apparent power",
|
"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_battery_level": "Current {entity_name} battery level",
|
||||||
"is_carbon_dioxide": "Current {entity_name} carbon dioxide concentration level",
|
"is_carbon_dioxide": "Current {entity_name} carbon dioxide concentration level",
|
||||||
"is_carbon_monoxide": "Current {entity_name} carbon monoxide concentration level",
|
"is_carbon_monoxide": "Current {entity_name} carbon monoxide concentration level",
|
||||||
@ -41,6 +42,7 @@
|
|||||||
},
|
},
|
||||||
"trigger_type": {
|
"trigger_type": {
|
||||||
"apparent_power": "{entity_name} apparent power changes",
|
"apparent_power": "{entity_name} apparent power changes",
|
||||||
|
"atmospheric_pressure": "{entity_name} atmospheric pressure changes",
|
||||||
"battery_level": "{entity_name} battery level changes",
|
"battery_level": "{entity_name} battery level changes",
|
||||||
"carbon_dioxide": "{entity_name} carbon dioxide concentration changes",
|
"carbon_dioxide": "{entity_name} carbon dioxide concentration changes",
|
||||||
"carbon_monoxide": "{entity_name} carbon monoxide concentration changes",
|
"carbon_monoxide": "{entity_name} carbon monoxide concentration changes",
|
||||||
|
@ -250,6 +250,12 @@ METRIC_SYSTEM = UnitSystem(
|
|||||||
_CONF_UNIT_SYSTEM_METRIC,
|
_CONF_UNIT_SYSTEM_METRIC,
|
||||||
accumulated_precipitation=UnitOfPrecipitationDepth.MILLIMETERS,
|
accumulated_precipitation=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||||
conversions={
|
conversions={
|
||||||
|
# Force atmospheric pressures to hPa
|
||||||
|
**{
|
||||||
|
("atmospheric_pressure", unit): UnitOfPressure.HPA
|
||||||
|
for unit in UnitOfPressure
|
||||||
|
if unit != UnitOfPressure.HPA
|
||||||
|
},
|
||||||
# Convert non-metric distances
|
# Convert non-metric distances
|
||||||
("distance", UnitOfLength.FEET): UnitOfLength.METERS,
|
("distance", UnitOfLength.FEET): UnitOfLength.METERS,
|
||||||
("distance", UnitOfLength.INCHES): UnitOfLength.MILLIMETERS,
|
("distance", UnitOfLength.INCHES): UnitOfLength.MILLIMETERS,
|
||||||
@ -282,6 +288,12 @@ US_CUSTOMARY_SYSTEM = UnitSystem(
|
|||||||
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
|
||||||
accumulated_precipitation=UnitOfPrecipitationDepth.INCHES,
|
accumulated_precipitation=UnitOfPrecipitationDepth.INCHES,
|
||||||
conversions={
|
conversions={
|
||||||
|
# Force atmospheric pressures to inHg
|
||||||
|
**{
|
||||||
|
("atmospheric_pressure", unit): UnitOfPressure.INHG
|
||||||
|
for unit in UnitOfPressure
|
||||||
|
if unit != UnitOfPressure.INHG
|
||||||
|
},
|
||||||
# Convert non-USCS distances
|
# Convert non-USCS distances
|
||||||
("distance", UnitOfLength.CENTIMETERS): UnitOfLength.INCHES,
|
("distance", UnitOfLength.CENTIMETERS): UnitOfLength.INCHES,
|
||||||
("distance", UnitOfLength.KILOMETERS): UnitOfLength.MILES,
|
("distance", UnitOfLength.KILOMETERS): UnitOfLength.MILES,
|
||||||
|
@ -380,6 +380,24 @@ def test_get_unit_system_invalid(key: str) -> None:
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"device_class, original_unit, state_unit",
|
"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
|
# Test distance conversion
|
||||||
(SensorDeviceClass.DISTANCE, UnitOfLength.FEET, UnitOfLength.METERS),
|
(SensorDeviceClass.DISTANCE, UnitOfLength.FEET, UnitOfLength.METERS),
|
||||||
(SensorDeviceClass.DISTANCE, UnitOfLength.INCHES, UnitOfLength.MILLIMETERS),
|
(SensorDeviceClass.DISTANCE, UnitOfLength.INCHES, UnitOfLength.MILLIMETERS),
|
||||||
@ -435,6 +453,24 @@ def test_get_metric_converted_unit_(
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"device_class, original_unit, state_unit",
|
"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
|
# Test distance conversion
|
||||||
(SensorDeviceClass.DISTANCE, UnitOfLength.CENTIMETERS, UnitOfLength.INCHES),
|
(SensorDeviceClass.DISTANCE, UnitOfLength.CENTIMETERS, UnitOfLength.INCHES),
|
||||||
(SensorDeviceClass.DISTANCE, UnitOfLength.KILOMETERS, UnitOfLength.MILES),
|
(SensorDeviceClass.DISTANCE, UnitOfLength.KILOMETERS, UnitOfLength.MILES),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user