mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add air_quality radon triggers (#184935)
This commit is contained in:
@@ -139,6 +139,12 @@
|
||||
"pm4_crossed_threshold": {
|
||||
"trigger": "mdi:blur"
|
||||
},
|
||||
"radon_changed": {
|
||||
"trigger": "mdi:radioactive"
|
||||
},
|
||||
"radon_crossed_threshold": {
|
||||
"trigger": "mdi:radioactive"
|
||||
},
|
||||
"smoke_cleared": {
|
||||
"trigger": "mdi:check-circle"
|
||||
},
|
||||
|
||||
@@ -581,6 +581,30 @@
|
||||
},
|
||||
"name": "PM4 level crossed threshold"
|
||||
},
|
||||
"radon_changed": {
|
||||
"description": "Triggers when one or more radon levels change.",
|
||||
"fields": {
|
||||
"threshold": {
|
||||
"name": "[%key:component::air_quality::common::trigger_threshold_name%]"
|
||||
}
|
||||
},
|
||||
"name": "Radon level changed"
|
||||
},
|
||||
"radon_crossed_threshold": {
|
||||
"description": "Triggers when one or more radon levels cross a threshold.",
|
||||
"fields": {
|
||||
"behavior": {
|
||||
"name": "[%key:component::air_quality::common::trigger_behavior_name%]"
|
||||
},
|
||||
"for": {
|
||||
"name": "[%key:component::air_quality::common::trigger_for_name%]"
|
||||
},
|
||||
"threshold": {
|
||||
"name": "[%key:component::air_quality::common::trigger_threshold_name%]"
|
||||
}
|
||||
},
|
||||
"name": "Radon level crossed threshold"
|
||||
},
|
||||
"smoke_cleared": {
|
||||
"description": "Triggers when one or more smoke sensors stop detecting smoke.",
|
||||
"fields": {
|
||||
|
||||
@@ -5,7 +5,13 @@ from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, UnitOfDensity, UnitOfRatio
|
||||
from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
UnitOfDensity,
|
||||
UnitOfRadiationConcentration,
|
||||
UnitOfRatio,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.automation import DomainSpec
|
||||
from homeassistant.helpers.trigger import (
|
||||
@@ -23,6 +29,7 @@ from homeassistant.util.unit_conversion import (
|
||||
NitrogenDioxideConcentrationConverter,
|
||||
NitrogenMonoxideConcentrationConverter,
|
||||
OzoneConcentrationConverter,
|
||||
RadiationConcentrationConverter,
|
||||
SulphurDioxideConcentrationConverter,
|
||||
UnitlessRatioConverter,
|
||||
)
|
||||
@@ -165,6 +172,18 @@ TRIGGERS: dict[str, type[Trigger]] = {
|
||||
SulphurDioxideConcentrationConverter,
|
||||
)
|
||||
),
|
||||
"radon_changed": make_entity_numerical_state_changed_with_unit_trigger(
|
||||
{SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.RADON)},
|
||||
UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER,
|
||||
RadiationConcentrationConverter,
|
||||
),
|
||||
"radon_crossed_threshold": (
|
||||
make_entity_numerical_state_crossed_threshold_with_unit_trigger(
|
||||
{SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.RADON)},
|
||||
UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER,
|
||||
RadiationConcentrationConverter,
|
||||
)
|
||||
),
|
||||
# Numerical sensor triggers without unit conversion (single-unit device classes)
|
||||
"co2_changed": make_entity_numerical_state_changed_trigger(
|
||||
{SENSOR_DOMAIN: DomainSpec(device_class=SensorDeviceClass.CO2)},
|
||||
|
||||
@@ -45,6 +45,10 @@
|
||||
- "ppb"
|
||||
- "μg/m³"
|
||||
|
||||
.radon_units: &radon_units
|
||||
- "Bq/m³"
|
||||
- "pCi/L"
|
||||
|
||||
# --- Entity filter anchors ---
|
||||
|
||||
.co_threshold_entity: &co_threshold_entity
|
||||
@@ -151,6 +155,14 @@
|
||||
- domain: number
|
||||
device_class: sulphur_dioxide
|
||||
|
||||
.radon_threshold_entity: &radon_threshold_entity
|
||||
- domain: input_number
|
||||
unit_of_measurement: *radon_units
|
||||
- domain: sensor
|
||||
device_class: radon
|
||||
- domain: number
|
||||
device_class: radon
|
||||
|
||||
# --- Number anchors for single-unit pollutants ---
|
||||
|
||||
.co2_threshold_number: &co2_threshold_number
|
||||
@@ -250,6 +262,11 @@
|
||||
- domain: sensor
|
||||
device_class: sulphur_dioxide
|
||||
|
||||
.target_radon: &target_radon
|
||||
entity:
|
||||
- domain: sensor
|
||||
device_class: radon
|
||||
|
||||
# --- Binary sensor triggers ---
|
||||
|
||||
gas_detected:
|
||||
@@ -630,3 +647,32 @@ so2_crossed_threshold:
|
||||
number:
|
||||
mode: box
|
||||
unit_of_measurement: *so2_units
|
||||
|
||||
# Radon (multi-unit)
|
||||
radon_changed:
|
||||
target: *target_radon
|
||||
fields:
|
||||
threshold:
|
||||
required: true
|
||||
selector:
|
||||
numeric_threshold:
|
||||
entity: *radon_threshold_entity
|
||||
mode: changed
|
||||
number:
|
||||
mode: box
|
||||
unit_of_measurement: *radon_units
|
||||
|
||||
radon_crossed_threshold:
|
||||
target: *target_radon
|
||||
fields:
|
||||
behavior: *trigger_behavior
|
||||
for: *trigger_for
|
||||
threshold:
|
||||
required: true
|
||||
selector:
|
||||
numeric_threshold:
|
||||
entity: *radon_threshold_entity
|
||||
mode: crossed
|
||||
number:
|
||||
mode: box
|
||||
unit_of_measurement: *radon_units
|
||||
|
||||
@@ -14,6 +14,7 @@ from homeassistant.const import (
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
UnitOfDensity,
|
||||
UnitOfRadiationConcentration,
|
||||
UnitOfRatio,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -39,6 +40,9 @@ _UGM3_UNIT_ATTRIBUTES = {
|
||||
}
|
||||
_PPB_UNIT_ATTRIBUTES = {ATTR_UNIT_OF_MEASUREMENT: UnitOfRatio.PARTS_PER_BILLION}
|
||||
_PPM_UNIT_ATTRIBUTES = {ATTR_UNIT_OF_MEASUREMENT: UnitOfRatio.PARTS_PER_MILLION}
|
||||
_BQM3_UNIT_ATTRIBUTES = {
|
||||
ATTR_UNIT_OF_MEASUREMENT: UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -73,6 +77,17 @@ _UGM3_CROSSED_THRESHOLD = {
|
||||
},
|
||||
}
|
||||
}
|
||||
_BQM3_CROSSED_THRESHOLD = {
|
||||
"threshold": {
|
||||
"type": "above",
|
||||
"value": {
|
||||
"number": 50,
|
||||
"unit_of_measurement": (
|
||||
UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER
|
||||
),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_TRIGGER_TARGET_SUPPORT: dict[str, TargetSupport] = {
|
||||
@@ -96,6 +111,8 @@ _TRIGGER_TARGET_SUPPORT: dict[str, TargetSupport] = {
|
||||
"no2_crossed_threshold": TargetSupport.STANDARD,
|
||||
"so2_changed": TargetSupport.STANDARD,
|
||||
"so2_crossed_threshold": TargetSupport.STANDARD,
|
||||
"radon_changed": TargetSupport.STANDARD,
|
||||
"radon_crossed_threshold": TargetSupport.STANDARD,
|
||||
"co2_changed": TargetSupport.STANDARD,
|
||||
"co2_crossed_threshold": TargetSupport.STANDARD,
|
||||
"pm1_changed": TargetSupport.STANDARD,
|
||||
@@ -146,6 +163,8 @@ _TRIGGER_TARGET_SUPPORT: dict[str, TargetSupport] = {
|
||||
("air_quality.n2o_crossed_threshold", _PLAIN_CROSSED_THRESHOLD, True, True),
|
||||
("air_quality.so2_changed", _CHANGED_THRESHOLD, False, False),
|
||||
("air_quality.so2_crossed_threshold", _UGM3_CROSSED_THRESHOLD, True, True),
|
||||
("air_quality.radon_changed", _CHANGED_THRESHOLD, False, False),
|
||||
("air_quality.radon_crossed_threshold", _BQM3_CROSSED_THRESHOLD, True, True),
|
||||
],
|
||||
)
|
||||
async def test_air_quality_trigger_options_validation(
|
||||
@@ -500,6 +519,19 @@ async def test_air_quality_trigger_binary_sensor_behavior_all(
|
||||
threshold_unit=UnitOfRatio.PARTS_PER_BILLION,
|
||||
unit_attributes=_PPB_UNIT_ATTRIBUTES,
|
||||
),
|
||||
# With unit conversion (Bq/m³ base unit)
|
||||
*parametrize_numerical_state_value_changed_trigger_states(
|
||||
"air_quality.radon_changed",
|
||||
device_class=SensorDeviceClass.RADON,
|
||||
threshold_unit=UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER,
|
||||
unit_attributes=_BQM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"air_quality.radon_crossed_threshold",
|
||||
device_class=SensorDeviceClass.RADON,
|
||||
threshold_unit=UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER,
|
||||
unit_attributes=_BQM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
# Without unit conversion (single-unit device classes)
|
||||
*parametrize_numerical_state_value_changed_trigger_states(
|
||||
"air_quality.co2_changed",
|
||||
@@ -637,6 +669,13 @@ async def test_air_quality_trigger_sensor_behavior_each(
|
||||
threshold_unit=UnitOfRatio.PARTS_PER_BILLION,
|
||||
unit_attributes=_PPB_UNIT_ATTRIBUTES,
|
||||
),
|
||||
# With unit conversion (Bq/m³ base unit)
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"air_quality.radon_crossed_threshold",
|
||||
device_class=SensorDeviceClass.RADON,
|
||||
threshold_unit=UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER,
|
||||
unit_attributes=_BQM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
# Without unit conversion (single-unit device classes)
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"air_quality.co2_crossed_threshold",
|
||||
@@ -747,6 +786,13 @@ async def test_air_quality_trigger_sensor_crossed_threshold_behavior_first(
|
||||
threshold_unit=UnitOfRatio.PARTS_PER_BILLION,
|
||||
unit_attributes=_PPB_UNIT_ATTRIBUTES,
|
||||
),
|
||||
# With unit conversion (Bq/m³ base unit)
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"air_quality.radon_crossed_threshold",
|
||||
device_class=SensorDeviceClass.RADON,
|
||||
threshold_unit=UnitOfRadiationConcentration.BECQUEREL_PER_CUBIC_METER,
|
||||
unit_attributes=_BQM3_UNIT_ATTRIBUTES,
|
||||
),
|
||||
# Without unit conversion (single-unit device classes)
|
||||
*parametrize_numerical_state_value_crossed_threshold_trigger_states(
|
||||
"air_quality.co2_crossed_threshold",
|
||||
|
||||
Reference in New Issue
Block a user