Skip to content

Commit

Permalink
Add universal IR remote
Browse files Browse the repository at this point in the history
  • Loading branch information
JELoohuis committed Oct 31, 2024
1 parent bdae8bb commit 7854e97
Show file tree
Hide file tree
Showing 15 changed files with 755 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .homeycompose/capabilities/mute_button.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "boolean",
"title": {
"en": "Mute"
},
"getable": false,
"setable": true,
"uiComponent": "button"
}
9 changes: 9 additions & 0 deletions .homeycompose/capabilities/off_button.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "boolean",
"title": {
"en": "Off"
},
"getable": false,
"setable": true,
"uiComponent": "button"
}
9 changes: 9 additions & 0 deletions .homeycompose/capabilities/on_button.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "boolean",
"title": {
"en": "On"
},
"getable": false,
"setable": true,
"uiComponent": "button"
}
9 changes: 9 additions & 0 deletions .homeycompose/capabilities/power_button.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "boolean",
"title": {
"en": "Power"
},
"getable": false,
"setable": true,
"uiComponent": "button"
}
178 changes: 178 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,81 @@
}
]
},
{
"id": "infrared_remote_press",
"title": {
"en": "Press button"
},
"titleFormatted": {
"en": "Press [[button]]"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=infrared_remote"
},
{
"name": "button",
"type": "autocomplete",
"title": {
"en": "Button"
}
}
]
},
{
"id": "infrared_remote_mute_button",
"title": {
"en": "Press mute button"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=infrared_remote&capabilities=mute_button"
}
]
},
{
"id": "infrared_remote_power_button",
"title": {
"en": "Press power button"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=infrared_remote&capabilities=power_button"
}
]
},
{
"id": "infrared_remote_on_button",
"title": {
"en": "Press on button"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=infrared_remote&capabilities=on_button"
}
]
},
{
"id": "infrared_remote_off_button",
"title": {
"en": "Press off button"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=infrared_remote&capabilities=off_button"
}
]
},
{
"id": "light_switch_pir",
"title": {
Expand Down Expand Up @@ -4557,6 +4632,73 @@
}
]
},
{
"capabilities": [
"on_button",
"off_button",
"mute_button"
],
"connectivity": [
"cloud"
],
"platforms": [
"local",
"cloud"
],
"images": {
"small": "/drivers/infrared_remote/assets/images/small.png",
"large": "/drivers/infrared_remote/assets/images/large.png",
"xlarge": "/drivers/infrared_remote/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": "remote",
"name": {
"en": "Infrared Remote",
"nl": "Infrarood Afstandsbediening"
},
"id": "infrared_remote",
"settings": [
{
"id": "deviceSpecification",
"type": "label",
"label": {
"en": "Device Specification"
},
"hint": {
"en": "The Tuya specification of this device"
},
"value": "<not available>"
}
]
},
{
"capabilities": [
"measure_water",
Expand Down Expand Up @@ -6955,6 +7097,15 @@
}
]
},
"mute_button": {
"type": "boolean",
"title": {
"en": "Mute"
},
"getable": false,
"setable": true,
"uiComponent": "button"
},
"night_mode": {
"title": {
"en": "Night Mode"
Expand All @@ -6965,6 +7116,24 @@
"setable": true,
"icon": "assets/capabilities/sleep_mode.svg"
},
"off_button": {
"type": "boolean",
"title": {
"en": "Off"
},
"getable": false,
"setable": true,
"uiComponent": "button"
},
"on_button": {
"type": "boolean",
"title": {
"en": "On"
},
"getable": false,
"setable": true,
"uiComponent": "button"
},
"open_window_sensor": {
"type": "boolean",
"title": {
Expand All @@ -6982,6 +7151,15 @@
},
"icon": "assets/capabilities/open_window.svg"
},
"power_button": {
"type": "boolean",
"title": {
"en": "Power"
},
"getable": false,
"setable": true,
"uiComponent": "button"
},
"ptz_control_horizontal": {
"type": "enum",
"title": {
Expand Down
39 changes: 39 additions & 0 deletions drivers/infrared_remote/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import TuyaOAuth2Device from '../../lib/TuyaOAuth2Device';

class TuyaOAuth2DeviceIrController extends TuyaOAuth2Device {
async onOAuth2Init(): Promise<void> {
await super.onOAuth2Init();

if (this.hasCapability('on_button')) {
this.registerCapabilityListener('on_button', () => this.sendKeyCommand(undefined, 'PowerOn').then());
}

if (this.hasCapability('off_button')) {
this.registerCapabilityListener('off_button', () => this.sendKeyCommand(undefined, 'PowerOff').then());
}

if (this.hasCapability('power_button')) {
this.registerCapabilityListener('power_button', () => this.sendKeyCommand(undefined, 'Power').then());
}

if (this.hasCapability('mute_button')) {
this.registerCapabilityListener('mute_button', () =>
this.sendKeyCommand(undefined, this.getStoreValue('tuya_mute_key')).then(),
);
}
}

async sendKeyCommand(keyId?: number, keyString?: string): Promise<boolean> {
const { deviceId, controllerId } = this.getData();
const categoryId = this.getStoreValue('tuya_remote_category') as number;
return this.oAuth2Client.sendKeyCommand(controllerId, deviceId, categoryId, keyId, keyString);
}

async sendAircoCommand(code: string, value: number): Promise<boolean> {
const { deviceId, controllerId } = this.getData();
return this.oAuth2Client.sendAircoCommand(controllerId, deviceId, code, value);
}
}

export default TuyaOAuth2DeviceIrController;
module.exports = TuyaOAuth2DeviceIrController;
9 changes: 9 additions & 0 deletions drivers/infrared_remote/driver.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$extends": "tuya",
"class": "remote",
"name": {
"en": "Infrared Remote",
"nl": "Infrarood Afstandsbediening"
},
"capabilities": ["on_button", "off_button", "mute_button"]
}
50 changes: 50 additions & 0 deletions drivers/infrared_remote/driver.flow.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"actions": [
{
"id": "infrared_remote_press",
"title": {
"en": "Press button"
},
"titleFormatted": {
"en": "Press [[button]]"
},
"args": [
{
"name": "button",
"type": "autocomplete",
"title": { "en": "Button" }
}
]
},
{
"id": "infrared_remote_mute_button",
"title": {
"en": "Press mute button"
},
"$filter": "capabilities=mute_button"
},
{
"id": "infrared_remote_power_button",
"title": {
"en": "Press power button"
},
"$filter": "capabilities=power_button"
},
{
"id": "infrared_remote_on_button",
"title": {
"en": "Press on button"
},
"$filter": "capabilities=on_button"
},
{
"id": "infrared_remote_off_button",
"title": {
"en": "Press off button"
},
"$filter": "capabilities=off_button"
}
],
"conditions": [],
"triggers": []
}
5 changes: 5 additions & 0 deletions drivers/infrared_remote/driver.settings.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"$extends": "deviceSpecification"
}
]
Loading

0 comments on commit 7854e97

Please sign in to comment.