Skip to content

Commit

Permalink
Rework climate sensor to new sensor style
Browse files Browse the repository at this point in the history
  • Loading branch information
JELoohuis committed Aug 29, 2024
1 parent 7b3a10e commit b20dd07
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
45 changes: 34 additions & 11 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2974,17 +2974,6 @@
},
"id": "sensor_climate",
"settings": [
{
"id": "deviceSpecification",
"type": "label",
"label": {
"en": "Device Specification"
},
"hint": {
"en": "The Tuya specification of this device"
},
"value": "<not available>"
},
{
"id": "va_temperature_scaling",
"type": "dropdown",
Expand Down Expand Up @@ -3095,6 +3084,40 @@
}
}
]
},
{
"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": "deviceSpecification",
"type": "label",
"label": {
"en": "Device Specification"
},
"hint": {
"en": "The Tuya specification of this device"
},
"value": "<not available>"
}
]
},
Expand Down
5 changes: 1 addition & 4 deletions drivers/sensor_climate/TuyaClimateSensorConstants.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
/** capabilities that map one to one to a Homey capability */
export const CLIMATE_SENSOR_CAPABILITIES = {
read_write: ['switch'],
read_only: ['temper_alarm', 'battery_percentage'],
read_only: ['temper_alarm'],
read_only_scaled: ['va_temperature', 'va_humidity', 'bright_value'],
setting: [],
} as const;

export const CLIMATE_CAPABILITY_MAPPING = {
switch: 'onoff',
temper_alarm: 'alarm_tamper',
va_temperature: 'measure_temperature',
va_humidity: 'measure_humidity',
bright_value: 'measure_luminance',
battery_state: 'alarm_battery',
battery_percentage: 'measure_battery',
battery_value: 'measure_battery',
va_battery: 'measure_battery',
} as const;
Expand Down
3 changes: 1 addition & 2 deletions drivers/sensor_climate/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = class TuyaOAuth2DeviceSensorClimate extends TuyaOAuth2DeviceSen
}

async onTuyaStatus(status: TuyaStatus, changedStatusCodes: string[]): Promise<void> {
// battery_state, battery_percentage and temper_alarm are handled by the superclass
await super.onTuyaStatus(status, changedStatusCodes);

for (const tuyaCapability in status) {
Expand All @@ -38,8 +39,6 @@ module.exports = class TuyaOAuth2DeviceSensorClimate extends TuyaOAuth2DeviceSen
}

// Battery
// battery_state is handled by superclass

if (tuyaCapability === 'battery_value') {
const scaledValue = (value as number) / 300;
this.setCapabilityValue(homeyCapability, scaledValue).catch(this.error);
Expand Down
12 changes: 9 additions & 3 deletions drivers/sensor_climate/driver.settings.compose.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[
{
"$extends": "deviceSpecification"
},
{
"id": "va_temperature_scaling",
"type": "dropdown",
Expand Down Expand Up @@ -112,5 +109,14 @@
}
}
]
},
{
"$extends": "useAlarmTimeout"
},
{
"$extends": "alarmTimeout"
},
{
"$extends": "deviceSpecification"
}
]
1 change: 1 addition & 0 deletions drivers/sensor_climate/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = class TuyaOAuth2DriverSensorClimate extends TuyaOAuth2DriverSen
device: TuyaDeviceResponse,
specifications: TuyaDeviceSpecificationResponse,
): ListDeviceProperties {
// battery_state, battery_percentage and temper_alarm are handled by the superclass
const props = super.onTuyaPairListDeviceProperties(device, specifications);

for (const status of device.status) {
Expand Down

0 comments on commit b20dd07

Please sign in to comment.