Skip to content

Commit

Permalink
Prepare airco driver
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver committed Aug 24, 2024
1 parent 6c97e8d commit c564d06
Show file tree
Hide file tree
Showing 14 changed files with 669 additions and 0 deletions.
238 changes: 238 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,29 @@
],
"id": "trigger_scene"
},
{
"id": "airco_set_child_lock",
"title": {
"en": "Set child lock"
},
"titleFormatted": {
"en": "Set child lock [[value]]"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=airco&capabilities=child_lock"
},
{
"name": "value",
"type": "checkbox",
"title": {
"en": "Value"
}
}
]
},
{
"id": "camera_cruise_switch",
"title": {
Expand Down Expand Up @@ -1718,6 +1741,221 @@
]
},
"drivers": [
{
"capabilities": [
"onoff",
"target_temperature",
"measure_temperature"
],
"connectivity": [
"cloud"
],
"platforms": [
"local",
"cloud"
],
"images": {
"small": "/drivers/airco/assets/images/small.png",
"large": "/drivers/airco/assets/images/large.png",
"xlarge": "/drivers/airco/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": "airconditioning",
"name": {
"en": "Air Conditioning",
"nl": "Airconditioning"
},
"id": "airco",
"settings": [
{
"id": "deviceSpecification",
"type": "label",
"label": {
"en": "Device Specification"
},
"hint": {
"en": "The Tuya specification of this device"
},
"value": "<not available>"
},
{
"id": "temp_set_scaling",
"type": "dropdown",
"label": {
"en": "Target Temperature Scale"
},
"hint": {
"en": "By how much the temperature targeted by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "temp_current_scaling",
"type": "dropdown",
"label": {
"en": "Measured Temperature Scale"
},
"hint": {
"en": "By how much the temperature measured by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "humidity_set_scaling",
"type": "dropdown",
"label": {
"en": "Target Humidity Scale"
},
"hint": {
"en": "By how much the humidity targeted by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "humidity_current_scaling",
"type": "dropdown",
"label": {
"en": "Measured Humidity Scale"
},
"hint": {
"en": "By how much the humidity measured by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
}
]
},
{
"capabilities": [
"alarm_motion",
Expand Down
15 changes: 15 additions & 0 deletions drivers/airco/TuyaAircoConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const AIRCO_CAPABILITIES_MAPPING = {
switch: 'onoff',
temp_set: 'target_temperature',
temp_current: 'measure_temperature',
humidity_set: 'target_humidity',
humidity_current: 'measure_humidity',
lock: 'child_lock',
} as const;

export type HomeySocketSettings = {
temp_set_scaling: '0' | '1' | '2' | '3';
temp_current_scaling: '0' | '1' | '2' | '3';
humidity_set_scaling: '0' | '1' | '2' | '3';
humidity_current_scaling: '0' | '1' | '2' | '3';
};
1 change: 1 addition & 0 deletions drivers/airco/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/airco/assets/images/large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/airco/assets/images/small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added drivers/airco/assets/images/xlarge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions drivers/airco/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import TuyaOAuth2Device from '../../lib/TuyaOAuth2Device';
import { TuyaStatus } from '../../types/TuyaTypes';

module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
async onOAuth2Init(): Promise<void> {
await super.onOAuth2Init();

if (this.hasCapability('onoff')) {
this.registerCapabilityListener('onoff', value => this.onOffCapabilityListener(value));
}

if (this.hasCapability('target_temperature')) {
this.registerCapabilityListener('target_temperature', value => this.targetTemperatureCapabilityListener(value));
}

if (this.hasCapability('target_humidity')) {
this.registerCapabilityListener('target_humidity', value => this.targetHumidityCapabilityListener(value));
}

if (this.hasCapability('child_lock')) {
this.registerCapabilityListener('child_lock', value => this.childLockCapabilityListener(value));
}
}

async onTuyaStatus(status: TuyaStatus, changedStatusCodes: string[]): Promise<void> {
await super.onTuyaStatus(status, changedStatusCodes);

if (typeof status['switch'] === 'boolean') {
this.setCapabilityValue('onoff', status['switch']).catch(this.error);
}

if (typeof status['temp_current'] === 'number') {
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_current_scaling') ?? '0', 10);
this.setCapabilityValue('measure_temperature', status['temp_current'] / scaling).catch(this.error);
}

if (typeof status['temp_set'] === 'number') {
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10);
this.setCapabilityValue('target_temperature', status['temp_set'] / scaling).catch(this.error);
}

if (typeof status['humidity_current'] === 'number') {
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_current_scaling') ?? '0', 10);
this.setCapabilityValue('measure_humidity', status['humidity_current'] / scaling).catch(this.error);
}

if (typeof status['humidity_set'] === 'number') {
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10);
this.setCapabilityValue('target_humidity', status['humidity_set'] / scaling).catch(this.error);
}

if (typeof status['lock'] === 'boolean') {
this.setCapabilityValue('child_lock', status['lock']).catch(this.error);
}
}

async onOffCapabilityListener(value: boolean): Promise<void> {
await this.sendCommand({
code: 'switch',
value: value,
});
}

async targetTemperatureCapabilityListener(value: number): Promise<void> {
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10);
await this.sendCommand({
code: 'temp_set',
value: value * scaling,
});
}

async targetHumidityCapabilityListener(value: number): Promise<void> {
const scaling = 10.0 ** Number.parseInt(this.getSetting('humidity_set_scaling') ?? '0', 10);
await this.sendCommand({
code: 'humidity_set',
value: value * scaling,
});
}

async childLockCapabilityListener(value: boolean): Promise<void> {
await this.sendCommand({
code: 'lock',
value: value,
});
}
};
9 changes: 9 additions & 0 deletions drivers/airco/driver.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$extends": "tuya",
"class": "airconditioning",
"name": {
"en": "Air Conditioning",
"nl": "Airconditioning"
},
"capabilities": ["onoff", "target_temperature", "measure_temperature"]
}
23 changes: 23 additions & 0 deletions drivers/airco/driver.flow.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"actions": [
{
"id": "airco_set_child_lock",
"$filter": "capabilities=child_lock",
"title": {
"en": "Set child lock"
},
"titleFormatted": {
"en": "Set child lock [[value]]"
},
"args": [
{
"name": "value",
"type": "checkbox",
"title": { "en": "Value" }
}
]
}
],
"conditions": [],
"triggers": []
}
Loading

0 comments on commit c564d06

Please sign in to comment.