diff --git a/homeassistant/components/binary_sensor/__init__.py b/homeassistant/components/binary_sensor/__init__.py index dc2d302012f..82e903ce877 100644 --- a/homeassistant/components/binary_sensor/__init__.py +++ b/homeassistant/components/binary_sensor/__init__.py @@ -37,6 +37,9 @@ class BinarySensorDeviceClass(StrEnum): # On means charging, Off means not charging BATTERY_CHARGING = "battery_charging" + # On means carbon monoxide detected, Off means no carbon monoxide (clear) + CO = "carbon_monoxide" + # On means cold, Off means normal COLD = "cold" @@ -120,6 +123,7 @@ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.Coerce(BinarySensorDeviceClass)) DEVICE_CLASSES = [cls.value for cls in BinarySensorDeviceClass] DEVICE_CLASS_BATTERY = BinarySensorDeviceClass.BATTERY.value DEVICE_CLASS_BATTERY_CHARGING = BinarySensorDeviceClass.BATTERY_CHARGING.value +DEVICE_CLASS_CO = BinarySensorDeviceClass.CO.value DEVICE_CLASS_COLD = BinarySensorDeviceClass.COLD.value DEVICE_CLASS_CONNECTIVITY = BinarySensorDeviceClass.CONNECTIVITY.value DEVICE_CLASS_DOOR = BinarySensorDeviceClass.DOOR.value diff --git a/homeassistant/components/binary_sensor/device_condition.py b/homeassistant/components/binary_sensor/device_condition.py index 6f1a0ba4f5f..31dde6fdfff 100644 --- a/homeassistant/components/binary_sensor/device_condition.py +++ b/homeassistant/components/binary_sensor/device_condition.py @@ -17,6 +17,7 @@ from homeassistant.helpers.typing import ConfigType from . import ( DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY_CHARGING, + DEVICE_CLASS_CO, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, @@ -53,6 +54,8 @@ CONF_IS_BAT_LOW = "is_bat_low" CONF_IS_NOT_BAT_LOW = "is_not_bat_low" CONF_IS_CHARGING = "is_charging" CONF_IS_NOT_CHARGING = "is_not_charging" +CONF_IS_CO = "is_co" +CONF_IS_NO_CO = "is_no_co" CONF_IS_COLD = "is_cold" CONF_IS_NOT_COLD = "is_not_cold" CONF_IS_CONNECTED = "is_connected" @@ -101,6 +104,7 @@ CONF_IS_NOT_OPEN = "is_not_open" IS_ON = [ CONF_IS_BAT_LOW, CONF_IS_CHARGING, + CONF_IS_CO, CONF_IS_COLD, CONF_IS_CONNECTED, CONF_IS_GAS, @@ -142,6 +146,7 @@ IS_OFF = [ CONF_IS_NOT_PRESENT, CONF_IS_NOT_TAMPERED, CONF_IS_NOT_UNSAFE, + CONF_IS_NO_CO, CONF_IS_NO_GAS, CONF_IS_NO_LIGHT, CONF_IS_NO_MOTION, @@ -163,6 +168,7 @@ ENTITY_CONDITIONS = { {CONF_TYPE: CONF_IS_CHARGING}, {CONF_TYPE: CONF_IS_NOT_CHARGING}, ], + DEVICE_CLASS_CO: [{CONF_TYPE: CONF_IS_CO}, {CONF_TYPE: CONF_IS_NO_CO}], DEVICE_CLASS_COLD: [{CONF_TYPE: CONF_IS_COLD}, {CONF_TYPE: CONF_IS_NOT_COLD}], DEVICE_CLASS_CONNECTIVITY: [ {CONF_TYPE: CONF_IS_CONNECTED}, diff --git a/homeassistant/components/binary_sensor/device_trigger.py b/homeassistant/components/binary_sensor/device_trigger.py index 0f2c7a836a2..aeb14efe092 100644 --- a/homeassistant/components/binary_sensor/device_trigger.py +++ b/homeassistant/components/binary_sensor/device_trigger.py @@ -15,6 +15,7 @@ from homeassistant.helpers.entity_registry import async_entries_for_device from . import ( DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY_CHARGING, + DEVICE_CLASS_CO, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, @@ -51,6 +52,8 @@ CONF_BAT_LOW = "bat_low" CONF_NOT_BAT_LOW = "not_bat_low" CONF_CHARGING = "charging" CONF_NOT_CHARGING = "not_charging" +CONF_CO = "co" +CONF_NO_CO = "no_co" CONF_COLD = "cold" CONF_NOT_COLD = "not_cold" CONF_CONNECTED = "connected" @@ -99,6 +102,7 @@ CONF_NOT_OPENED = "not_opened" TURNED_ON = [ CONF_BAT_LOW, + CONF_CO, CONF_COLD, CONF_CONNECTED, CONF_GAS, @@ -139,6 +143,7 @@ TURNED_OFF = [ CONF_NOT_PRESENT, CONF_NOT_TAMPERED, CONF_NOT_UNSAFE, + CONF_NO_CO, CONF_NO_GAS, CONF_NO_LIGHT, CONF_NO_MOTION, @@ -157,6 +162,7 @@ ENTITY_TRIGGERS = { {CONF_TYPE: CONF_CHARGING}, {CONF_TYPE: CONF_NOT_CHARGING}, ], + DEVICE_CLASS_CO: [{CONF_TYPE: CONF_CO}, {CONF_TYPE: CONF_NO_CO}], DEVICE_CLASS_COLD: [{CONF_TYPE: CONF_COLD}, {CONF_TYPE: CONF_NOT_COLD}], DEVICE_CLASS_CONNECTIVITY: [ {CONF_TYPE: CONF_CONNECTED}, diff --git a/homeassistant/components/binary_sensor/strings.json b/homeassistant/components/binary_sensor/strings.json index e2167c24f8a..62a73036238 100644 --- a/homeassistant/components/binary_sensor/strings.json +++ b/homeassistant/components/binary_sensor/strings.json @@ -4,6 +4,8 @@ "condition_type": { "is_bat_low": "{entity_name} battery is low", "is_not_bat_low": "{entity_name} battery is normal", + "is_co": "{entity_name} is detecting carbon monoxide", + "is_no_co": "{entity_name} is not detecting carbon monoxide", "is_cold": "{entity_name} is cold", "is_not_cold": "{entity_name} is not cold", "is_connected": "{entity_name} is connected", @@ -54,6 +56,8 @@ "trigger_type": { "bat_low": "{entity_name} battery low", "not_bat_low": "{entity_name} battery normal", + "co": "{entity_name} started detecting carbon monoxide", + "no_co": "{entity_name} stopped detecting carbon monoxide", "cold": "{entity_name} became cold", "not_cold": "{entity_name} became not cold", "connected": "{entity_name} connected", @@ -111,6 +115,10 @@ "off": "Not charging", "on": "Charging" }, + "co": { + "off": "Clear", + "on": "Detected" + }, "cold": { "off": "[%key:component::binary_sensor::state::battery::off%]", "on": "Cold" @@ -209,6 +217,7 @@ } }, "device_class": { + "co": "carbon_monoxide", "cold": "cold", "gas": "gas", "heat": "heat", diff --git a/homeassistant/components/homekit/type_sensors.py b/homeassistant/components/homekit/type_sensors.py index 881d91044ee..46e241efab0 100644 --- a/homeassistant/components/homekit/type_sensors.py +++ b/homeassistant/components/homekit/type_sensors.py @@ -11,7 +11,6 @@ from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.const import ( ATTR_DEVICE_CLASS, ATTR_UNIT_OF_MEASUREMENT, - DEVICE_CLASS_CO, DEVICE_CLASS_CO2, STATE_HOME, STATE_ON, @@ -66,7 +65,7 @@ class SI(NamedTuple): BINARY_SENSOR_SERVICE_MAP: dict[str, SI] = { - DEVICE_CLASS_CO: SI( + BinarySensorDeviceClass.CO: SI( SERV_CARBON_MONOXIDE_SENSOR, CHAR_CARBON_MONOXIDE_DETECTED, int ), DEVICE_CLASS_CO2: SI(SERV_CARBON_DIOXIDE_SENSOR, CHAR_CARBON_DIOXIDE_DETECTED, int),