diff --git a/.homeycompose/flow/actions/alarm_switch_off.json b/.homeycompose/flow/actions/alarm_switch_off.json index d61e8dd1..6d830064 100644 --- a/.homeycompose/flow/actions/alarm_switch_off.json +++ b/.homeycompose/flow/actions/alarm_switch_off.json @@ -7,7 +7,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "onoff.alarm_switch" }, "title": { diff --git a/.homeycompose/flow/actions/alarm_switch_on.json b/.homeycompose/flow/actions/alarm_switch_on.json index 8eed821d..35261020 100644 --- a/.homeycompose/flow/actions/alarm_switch_on.json +++ b/.homeycompose/flow/actions/alarm_switch_on.json @@ -7,7 +7,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "onoff.alarm_switch" }, "title": { diff --git a/.homeycompose/flow/actions/send_command_boolean.json b/.homeycompose/flow/actions/send_command_boolean.json index f3175dfd..2f17f9f6 100644 --- a/.homeycompose/flow/actions/send_command_boolean.json +++ b/.homeycompose/flow/actions/send_command_boolean.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/actions/send_command_json.json b/.homeycompose/flow/actions/send_command_json.json index 22c1bd5f..02788c80 100644 --- a/.homeycompose/flow/actions/send_command_json.json +++ b/.homeycompose/flow/actions/send_command_json.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/actions/send_command_number.json b/.homeycompose/flow/actions/send_command_number.json index 57b3c985..1384993d 100644 --- a/.homeycompose/flow/actions/send_command_number.json +++ b/.homeycompose/flow/actions/send_command_number.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/actions/send_command_string.json b/.homeycompose/flow/actions/send_command_string.json index 2951d510..67d35084 100644 --- a/.homeycompose/flow/actions/send_command_string.json +++ b/.homeycompose/flow/actions/send_command_string.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/actions/set_sensor_alarm_bright.json b/.homeycompose/flow/actions/set_sensor_alarm_bright.json index 7ff3ddb2..061d40b5 100644 --- a/.homeycompose/flow/actions/set_sensor_alarm_bright.json +++ b/.homeycompose/flow/actions/set_sensor_alarm_bright.json @@ -10,7 +10,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_bright" }, "title": { diff --git a/.homeycompose/flow/actions/set_sensor_alarm_ringtone.json b/.homeycompose/flow/actions/set_sensor_alarm_ringtone.json index c0da2d44..7f1fb096 100644 --- a/.homeycompose/flow/actions/set_sensor_alarm_ringtone.json +++ b/.homeycompose/flow/actions/set_sensor_alarm_ringtone.json @@ -10,7 +10,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_ringtone" }, "title": { diff --git a/.homeycompose/flow/actions/set_sensor_alarm_time.json b/.homeycompose/flow/actions/set_sensor_alarm_time.json index 5decea4b..e80b5b49 100644 --- a/.homeycompose/flow/actions/set_sensor_alarm_time.json +++ b/.homeycompose/flow/actions/set_sensor_alarm_time.json @@ -10,7 +10,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_time" }, "title": { diff --git a/.homeycompose/flow/actions/set_sensor_alarm_volume.json b/.homeycompose/flow/actions/set_sensor_alarm_volume.json index db1f8b8d..c9bd1338 100644 --- a/.homeycompose/flow/actions/set_sensor_alarm_volume.json +++ b/.homeycompose/flow/actions/set_sensor_alarm_volume.json @@ -10,7 +10,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_volume" }, "title": { diff --git a/.homeycompose/flow/actions/set_sensor_muffling.json b/.homeycompose/flow/actions/set_sensor_muffling.json index 6f1c121e..2f9d6efb 100644 --- a/.homeycompose/flow/actions/set_sensor_muffling.json +++ b/.homeycompose/flow/actions/set_sensor_muffling.json @@ -10,7 +10,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.muffling" }, "title": { diff --git a/.homeycompose/flow/triggers/receive_status_boolean.json b/.homeycompose/flow/triggers/receive_status_boolean.json index a5bc18f6..330accc9 100644 --- a/.homeycompose/flow/triggers/receive_status_boolean.json +++ b/.homeycompose/flow/triggers/receive_status_boolean.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/triggers/receive_status_json.json b/.homeycompose/flow/triggers/receive_status_json.json index b3f7f06c..5336552c 100644 --- a/.homeycompose/flow/triggers/receive_status_json.json +++ b/.homeycompose/flow/triggers/receive_status_json.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/triggers/receive_status_number.json b/.homeycompose/flow/triggers/receive_status_number.json index 590d18b1..95bd861b 100644 --- a/.homeycompose/flow/triggers/receive_status_number.json +++ b/.homeycompose/flow/triggers/receive_status_number.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/.homeycompose/flow/triggers/receive_status_string.json b/.homeycompose/flow/triggers/receive_status_string.json index 60e8dcf1..9b035bcc 100644 --- a/.homeycompose/flow/triggers/receive_status_string.json +++ b/.homeycompose/flow/triggers/receive_status_string.json @@ -13,7 +13,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" diff --git a/app.json b/app.json index 66d96ed6..1be691b8 100644 --- a/app.json +++ b/app.json @@ -438,7 +438,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -479,7 +479,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -520,7 +520,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -561,7 +561,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -1305,7 +1305,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "onoff.alarm_switch" }, "title": { @@ -1324,7 +1324,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "onoff.alarm_switch" }, "title": { @@ -1349,7 +1349,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -1387,7 +1387,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -1425,7 +1425,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -1463,7 +1463,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" + "driver_id": "button|camera|circuit_breaker|dimmer|doorbell|fan|garage_door|heater|irrigator|light|other|sensor_climate|sensor_co2|sensor_contact|sensor_human|sensor_motion|sensor_smoke|siren|socket|thermostat|window_coverings" }, "title": { "en": "Device" @@ -1498,7 +1498,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_bright" }, "title": { @@ -1533,7 +1533,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_ringtone" }, "title": { @@ -1584,7 +1584,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_time" }, "title": { @@ -1618,7 +1618,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.alarm_volume" }, "title": { @@ -1673,7 +1673,7 @@ "name": "device", "type": "device", "filter": { - "driver_id": "sensor_smoke", + "driver_id": "sensor_smoke|sensor_co2", "capabilities": "hidden.muffling" }, "title": { @@ -5265,6 +5265,198 @@ } ] }, + { + "capabilities": [ + "alarm_co2", + "measure_co2" + ], + "connectivity": [ + "cloud" + ], + "platforms": [ + "local", + "cloud" + ], + "images": { + "small": "/drivers/sensor_co2/assets/images/small.png", + "large": "/drivers/sensor_co2/assets/images/large.png", + "xlarge": "/drivers/sensor_co2/assets/images/xlarge.png" + }, + "pair": [ + { + "id": "welcome", + "navigation": { + "next": "login_oauth2" + } + }, + { + "id": "login_oauth2", + "template": "login_oauth2" + }, + { + "id": "list_devices", + "template": "list_devices", + "navigation": { + "next": "add_devices" + } + }, + { + "id": "add_devices", + "template": "add_devices" + } + ], + "repair": [ + { + "id": "login_oauth2", + "template": "login_oauth2" + } + ], + "class": "sensor", + "name": { + "en": "CO2 Detector", + "nl": "CO2 Melder" + }, + "id": "sensor_co2", + "settings": [ + { + "id": "use_alarm_timeout", + "type": "checkbox", + "hint": { + "en": "Turn the alarm off a set time after the start signal, even if no end signal is received." + }, + "label": { + "en": "Use Alarm Timeout" + }, + "value": false + }, + { + "id": "alarm_timeout", + "type": "number", + "label": { + "en": "Alarm Timeout" + }, + "value": 10, + "min": 1, + "units": { + "en": "seconds" + } + }, + { + "id": "sensor_alarm_group", + "type": "group", + "label": { + "en": "NOTE: Some settings are not supported by every device." + }, + "children": [ + { + "id": "muffling", + "type": "checkbox", + "label": { + "en": "Mute Alarm" + } + }, + { + "id": "alarm_volume", + "type": "dropdown", + "label": { + "en": "Alarm Volume" + }, + "values": [ + { + "id": "low", + "label": { + "en": "Low" + } + }, + { + "id": "middle", + "label": { + "en": "Middle" + } + }, + { + "id": "high", + "label": { + "en": "High" + } + }, + { + "id": "mute", + "label": { + "en": "Mute" + } + } + ] + }, + { + "id": "alarm_time", + "type": "number", + "label": { + "en": "Alarm Duration" + }, + "min": 1, + "step": 1, + "value": 1, + "units": { + "en": "seconds" + } + }, + { + "id": "alarm_ringtone", + "type": "dropdown", + "label": { + "en": "Alarm Tone" + }, + "values": [ + { + "id": "1", + "label": "1" + }, + { + "id": "2", + "label": "2" + }, + { + "id": "3", + "label": "3" + }, + { + "id": "4", + "label": "4" + }, + { + "id": "5", + "label": "5" + } + ] + }, + { + "id": "alarm_bright", + "type": "number", + "label": { + "en": "Alarm Brightness" + }, + "min": 0, + "step": 1, + "max": 100, + "value": 100, + "units": "%" + } + ] + }, + { + "id": "deviceSpecification", + "type": "label", + "label": { + "en": "Device Specification" + }, + "hint": { + "en": "The Tuya specification of this device" + }, + "value": "" + } + ] + }, { "capabilities": [ "alarm_contact" diff --git a/drivers/sensor_co2/SensorCo2Constants.ts b/drivers/sensor_co2/SensorCo2Constants.ts new file mode 100644 index 00000000..294415d3 --- /dev/null +++ b/drivers/sensor_co2/SensorCo2Constants.ts @@ -0,0 +1,4 @@ +export const SENSOR_CO2_CAPABILITY_MAPPING = { + co2_state: 'alarm_co2', + co2_value: 'measure_co2', +} as const; diff --git a/drivers/sensor_co2/assets/icon.svg b/drivers/sensor_co2/assets/icon.svg new file mode 100644 index 00000000..9248b977 --- /dev/null +++ b/drivers/sensor_co2/assets/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/drivers/sensor_co2/assets/images/large.png b/drivers/sensor_co2/assets/images/large.png new file mode 100644 index 00000000..f096827a Binary files /dev/null and b/drivers/sensor_co2/assets/images/large.png differ diff --git a/drivers/sensor_co2/assets/images/small.png b/drivers/sensor_co2/assets/images/small.png new file mode 100644 index 00000000..992d1a3e Binary files /dev/null and b/drivers/sensor_co2/assets/images/small.png differ diff --git a/drivers/sensor_co2/assets/images/xlarge.png b/drivers/sensor_co2/assets/images/xlarge.png new file mode 100644 index 00000000..5440ec2a Binary files /dev/null and b/drivers/sensor_co2/assets/images/xlarge.png differ diff --git a/drivers/sensor_co2/device.ts b/drivers/sensor_co2/device.ts new file mode 100644 index 00000000..bcb1595d --- /dev/null +++ b/drivers/sensor_co2/device.ts @@ -0,0 +1,39 @@ +import TuyaOAuth2DeviceSensor from '../../lib/sensor/TuyaOAuth2DeviceSensor'; +import { SettingsEvent, TuyaStatus } from '../../types/TuyaTypes'; +import { HomeySensorSettings, SENSOR_SETTING_LABELS } from '../../lib/sensor/TuyaSensorConstants'; +import * as Util from '../../lib/TuyaOAuth2Util'; +import { SENSOR_CO2_CAPABILITY_MAPPING } from './SensorCo2Constants'; + +module.exports = class TuyaOAuth2DeviceSensorCO2 extends TuyaOAuth2DeviceSensor { + async onOAuth2Init(): Promise { + await this.initAlarm('alarm_smoke').catch(this.error); + + return super.onOAuth2Init(); + } + + async onTuyaStatus(status: TuyaStatus, changedStatusCodes: string[]): Promise { + await super.onTuyaStatus(status, changedStatusCodes); + + for (const tuyaCapability in status) { + const value = status[tuyaCapability]; + + if ( + tuyaCapability === 'co2_state' && + (!this.getSetting('use_alarm_timeout') || changedStatusCodes.includes(tuyaCapability)) + ) { + await this.setAlarmCapabilityValue(SENSOR_CO2_CAPABILITY_MAPPING[tuyaCapability], value === 'alarm').catch( + this.error, + ); + } + + if (tuyaCapability === 'co2_value') { + await this.safeSetCapabilityValue(SENSOR_CO2_CAPABILITY_MAPPING[tuyaCapability], value); + } + } + } + + async onSettings(event: SettingsEvent): Promise { + const [unsupportedSettings, unsupportedValues] = await super.onAlarmSettings(event); + return Util.reportUnsupportedSettings(this, unsupportedSettings, unsupportedValues, SENSOR_SETTING_LABELS); + } +}; diff --git a/drivers/sensor_co2/driver.compose.json b/drivers/sensor_co2/driver.compose.json new file mode 100644 index 00000000..94386937 --- /dev/null +++ b/drivers/sensor_co2/driver.compose.json @@ -0,0 +1,9 @@ +{ + "$extends": "tuya", + "class": "sensor", + "name": { + "en": "CO2 Detector", + "nl": "CO2 Melder" + }, + "capabilities": ["alarm_co2", "measure_co2"] +} diff --git a/drivers/sensor_co2/driver.settings.compose.json b/drivers/sensor_co2/driver.settings.compose.json new file mode 100644 index 00000000..001bf15d --- /dev/null +++ b/drivers/sensor_co2/driver.settings.compose.json @@ -0,0 +1,14 @@ +[ + { + "$extends": "useAlarmTimeout" + }, + { + "$extends": "alarmTimeout" + }, + { + "$extends": "sensor_alarm_group" + }, + { + "$extends": "deviceSpecification" + } +] diff --git a/drivers/sensor_co2/driver.ts b/drivers/sensor_co2/driver.ts new file mode 100644 index 00000000..92cd74b5 --- /dev/null +++ b/drivers/sensor_co2/driver.ts @@ -0,0 +1,48 @@ +import { DEVICE_CATEGORIES } from '../../lib/TuyaOAuth2Constants'; +import { ListDeviceProperties } from '../../lib/TuyaOAuth2Driver'; +import TuyaOAuth2DriverSensor from '../../lib/sensor/TuyaOAuth2DriverSensor'; +import { + type TuyaDeviceDataPointResponse, + TuyaDeviceResponse, + TuyaDeviceSpecificationResponse, +} from '../../types/TuyaApiTypes'; +import { getFromMap } from '../../lib/TuyaOAuth2Util'; +import { SENSOR_CO2_CAPABILITY_MAPPING } from './SensorCo2Constants'; + +module.exports = class TuyaOAuth2DriverSensorCO2 extends TuyaOAuth2DriverSensor { + TUYA_DEVICE_CATEGORIES = [DEVICE_CATEGORIES.SECURITY_VIDEO_SURV.CO2_DETECTOR] as const; + + onTuyaPairListDeviceProperties( + device: TuyaDeviceResponse, + specifications?: TuyaDeviceSpecificationResponse, + dataPoints?: TuyaDeviceDataPointResponse, + ): ListDeviceProperties { + const props = super.onTuyaPairListDeviceProperties(device, specifications, dataPoints); + + for (const status of device.status) { + const tuyaCapability = status.code; + const homeyCapability = getFromMap(SENSOR_CO2_CAPABILITY_MAPPING, tuyaCapability); + + if (homeyCapability) { + props.store.tuya_capabilities.push(tuyaCapability); + props.capabilities.push(homeyCapability); + } + } + + if (!specifications || !specifications.status) { + return props; + } + + for (const specification of specifications.status) { + const tuyaCapability = specification.code; + const values = JSON.parse(specification.values); + if (tuyaCapability === 'co2_state') { + if (!values.range.includes('normal')) { + props.settings['use_alarm_timeout'] = true; + } + } + } + + return props; + } +}; diff --git a/drivers/sensor_co2/pair/welcome.assets/chevron-right.png b/drivers/sensor_co2/pair/welcome.assets/chevron-right.png new file mode 100644 index 00000000..d7331b23 Binary files /dev/null and b/drivers/sensor_co2/pair/welcome.assets/chevron-right.png differ diff --git a/drivers/sensor_co2/pair/welcome.assets/logos.png b/drivers/sensor_co2/pair/welcome.assets/logos.png new file mode 100644 index 00000000..faefa496 Binary files /dev/null and b/drivers/sensor_co2/pair/welcome.assets/logos.png differ diff --git a/drivers/sensor_co2/pair/welcome.html b/drivers/sensor_co2/pair/welcome.html new file mode 100644 index 00000000..14a7e06e --- /dev/null +++ b/drivers/sensor_co2/pair/welcome.html @@ -0,0 +1,60 @@ + + +

+ +

+ +

+ +

+ + + + +

+ +

+ +