From ee2658f9e6b6bd3333eabfaf2d8294c0facffb18 Mon Sep 17 00:00:00 2001 From: B-Hartley Date: Mon, 8 Mar 2021 16:22:13 +0000 Subject: [PATCH] Add (some) of ZCL concentration clusters to ZHA component (#47590) * Update registries.py Add concentration clusters recently added to zigpy * Update measurement.py Add concentration clusters recently added to ZigPy * Update sensor.py Add concentration clusters recently added to ZigPy * Update sensor.py remove unnecessary tabs * Update measurement.py remove unnecessary tabs * Update sensor.py Just adding CO and CO2 for now. * Update registries.py Just adding CO2 and CO for now. * Update measurement.py Just adding CO2 and CO for now * Update sensor.py import const CONCENTRATION_PARTS_PER_MILLION * Update registries.py removed trailing whitespace * Update sensor.py added extra blank lines and removed trailing whitespace * Update measurement.py added extra blank lines and removed trailing whitespace * Update sensor.py add device classes for CO and CO2 --- .../zha/core/channels/measurement.py | 28 +++++++++++++++++++ .../components/zha/core/registries.py | 2 ++ homeassistant/components/zha/sensor.py | 25 +++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/homeassistant/components/zha/core/channels/measurement.py b/homeassistant/components/zha/core/channels/measurement.py index 64db1aa82ac..78ff12a9bf3 100644 --- a/homeassistant/components/zha/core/channels/measurement.py +++ b/homeassistant/components/zha/core/channels/measurement.py @@ -74,3 +74,31 @@ class TemperatureMeasurement(ZigbeeChannel): "config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 50), } ] + + +@registries.ZIGBEE_CHANNEL_REGISTRY.register( + measurement.CarbonMonoxideConcentration.cluster_id +) +class CarbonMonoxideConcentration(ZigbeeChannel): + """Carbon Monoxide measurement channel.""" + + REPORT_CONFIG = [ + { + "attr": "measured_value", + "config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001), + } + ] + + +@registries.ZIGBEE_CHANNEL_REGISTRY.register( + measurement.CarbonDioxideConcentration.cluster_id +) +class CarbonDioxideConcentration(ZigbeeChannel): + """Carbon Dioxide measurement channel.""" + + REPORT_CONFIG = [ + { + "attr": "measured_value", + "config": (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, 0.000001), + } + ] diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index 4dcccc98c05..66a9a70e752 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -68,6 +68,8 @@ SINGLE_INPUT_CLUSTER_DEVICE_CLASS = { zcl.clusters.general.PowerConfiguration.cluster_id: SENSOR, zcl.clusters.homeautomation.ElectricalMeasurement.cluster_id: SENSOR, zcl.clusters.hvac.Fan.cluster_id: FAN, + zcl.clusters.measurement.CarbonDioxideConcentration.cluster_id: SENSOR, + zcl.clusters.measurement.CarbonMonoxideConcentration.cluster_id: SENSOR, zcl.clusters.measurement.IlluminanceMeasurement.cluster_id: SENSOR, zcl.clusters.measurement.OccupancySensing.cluster_id: BINARY_SENSOR, zcl.clusters.measurement.PressureMeasurement.cluster_id: SENSOR, diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 78bc8fcbe4e..84d2dfb06bb 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -5,6 +5,8 @@ from typing import Any, Callable, Dict, List, Optional, Union from homeassistant.components.sensor import ( DEVICE_CLASS_BATTERY, + DEVICE_CLASS_CO, + DEVICE_CLASS_CO2, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_POWER, @@ -14,6 +16,7 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( + CONCENTRATION_PARTS_PER_MILLION, LIGHT_LUX, PERCENTAGE, POWER_WATT, @@ -279,3 +282,25 @@ class Temperature(Sensor): _device_class = DEVICE_CLASS_TEMPERATURE _divisor = 100 _unit = TEMP_CELSIUS + + +@STRICT_MATCH(channel_names="carbon_dioxide_concentration") +class CarbonDioxideConcentration(Sensor): + """Carbon Dioxide Concentration sensor.""" + + SENSOR_ATTR = "measured_value" + _device_class = DEVICE_CLASS_CO2 + _decimals = 0 + _multiplier = 1e6 + _unit = CONCENTRATION_PARTS_PER_MILLION + + +@STRICT_MATCH(channel_names="carbon_monoxide_concentration") +class CarbonMonoxideConcentration(Sensor): + """Carbon Monoxide Concentration sensor.""" + + SENSOR_ATTR = "measured_value" + _device_class = DEVICE_CLASS_CO + _decimals = 0 + _multiplier = 1e6 + _unit = CONCENTRATION_PARTS_PER_MILLION