Skip to content

Instantly share code, notes, and snippets.

@9zigen
Last active January 7, 2024 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9zigen/3ec959af5b83722563f09826cef0021e to your computer and use it in GitHub Desktop.
Save 9zigen/3ec959af5b83722563f09826cef0021e to your computer and use it in GitHub Desktop.
"""Module to handle quirks of the Alap CO2 Sensor.
manufacturer specific attributes to control displaying and specific configuration.
"""
import logging
import zigpy.profiles.zha as zha_p
from zigpy.quirks import CustomCluster, CustomDevice
from zigpy.zcl.clusters.homeautomation import Diagnostic
from zhaquirks import Bus, LocalDataCluster, QuickInitDevice
import zigpy.types as t
from zigpy.zcl.clusters.general import (
Basic,
Identify,
Ota,
PollControl,
PowerConfiguration,
Time, AnalogInput,
)
from zigpy.zcl.clusters.measurement import RelativeHumidity, TemperatureMeasurement, CarbonDioxideConcentration
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
_LOGGER = logging.getLogger(__name__)
class AlabCO2SensorCluster(CustomCluster, CarbonDioxideConcentration):
"""CO2 measurement cluster to receive reports from the Alab CO2 cluster."""
CO2_MEASUREMENT_CLUSTER = 0x040D
CO2_MEASURED_VALUE = 0x0000
CO2_MIN_MEASURED_VALUE = 0x0001
CO2_MAX_MEASURED_VALUE = 0x0002
CALIBRATION_NITROGEN = 0x1001
CALIBRATION_BACKGROUND = 0x1002
cluster_id = CO2_MEASUREMENT_CLUSTER
name = "Carbon Dioxide (CO₂) Concentration"
ep_attribute = "carbon_dioxide_concentration"
vendor_attributes = {
# CO2_MEASURED_VALUE: ("measured_value", t.uint16_t),
# CO2_MIN_MEASURED_VALUE: ("min_measured_value", t.uint16_t),
# CO2_MAX_MEASURED_VALUE: ("max_measured_value", t.uint16_t),
CALIBRATION_NITROGEN: ("calibration_nitrogen", t.uint16_t),
CALIBRATION_BACKGROUND: ("calibration_background", t.uint16_t)
}
server_commands = {}
client_commands = {}
def _update_attribute(self, attrid, value):
if attrid == self.CO2_MEASURED_VALUE:
value = value / 1e6
super()._update_attribute(attrid, value)
class AlabCO2SensorOne(CustomDevice):
"""Alab CO2 Sensor custom device."""
signature = {
MODELS_INFO: [("Alab", "Alab-CO2-1.0")],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=770
# device_version=0
# input_clusters=[0, 3, 1026, 1029, 1037, 1]
# output_clusters=[0]>
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
CarbonDioxideConcentration.cluster_id,
PowerConfiguration.cluster_id
],
OUTPUT_CLUSTERS: [],
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
AlabCO2SensorCluster,
PowerConfiguration.cluster_id
],
OUTPUT_CLUSTERS: [],
}
}
}
class AlabCO2SensorTwo(CustomDevice):
"""Alab CO2 Sensor custom device."""
signature = {
MODELS_INFO: [("Alab", "Alab-CO2-1.1")],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=770
# device_version=0
# input_clusters=[0, 3, 1026, 1029, 1037, 1]
# output_clusters=[0]>
1: {
PROFILE_ID: zha_p.PROFILE_ID,
DEVICE_TYPE: zha_p.DeviceType.TEMPERATURE_SENSOR,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
CarbonDioxideConcentration.cluster_id,
PowerConfiguration.cluster_id
],
OUTPUT_CLUSTERS: [],
},
242: {
PROFILE_ID: 0xa1e0,
DEVICE_TYPE: 0x0061,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: {
0x0021
}
}
},
}
replacement = {
ENDPOINTS: {
1: {
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
TemperatureMeasurement.cluster_id,
RelativeHumidity.cluster_id,
AlabCO2SensorCluster,
PowerConfiguration.cluster_id
],
OUTPUT_CLUSTERS: [],
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment