Skip to content

Commit

Permalink
Merge pull request #161 from athombv/siren
Browse files Browse the repository at this point in the history
Add siren support
  • Loading branch information
bobvandevijver authored Aug 22, 2024
2 parents 99ef081 + 6f9589e commit dc22b39
Show file tree
Hide file tree
Showing 31 changed files with 493 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "com.tuya",
"version": "1.2.3",
"compatibility": ">=10.0.0",
"compatibility": ">=12.0.0",
"brandColor": "#FF4800",
"sdk": 3,
"platforms": [
Expand Down Expand Up @@ -305,4 +305,4 @@
},
"support": "https://homey.app/support",
"source": "https://github.com/athombv/com.tuya"
}
}
2 changes: 1 addition & 1 deletion .homeycompose/flow/actions/send_command_boolean.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/actions/send_command_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/actions/send_command_number.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/actions/send_command_string.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/triggers/receive_status_boolean.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/triggers/receive_status_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/triggers/receive_status_number.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
2 changes: 1 addition & 1 deletion .homeycompose/flow/triggers/receive_status_string.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down
169 changes: 160 additions & 9 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "com.tuya",
"version": "1.2.3",
"compatibility": ">=10.0.0",
"compatibility": ">=12.0.0",
"brandColor": "#FF4800",
"sdk": 3,
"platforms": [
Expand Down Expand Up @@ -399,7 +399,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -440,7 +440,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -481,7 +481,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -522,7 +522,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -870,7 +870,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -908,7 +908,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -946,7 +946,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -984,7 +984,7 @@
"name": "device",
"type": "device",
"filter": {
"driver_id": "doorbell|fan|light|other|sensor_contact|sensor_motion|sensor_smoke|socket|dimmer|heater|camera"
"driver_id": "camera|dimmer|doorbell|fan|heater|light|other|sensor_contact|sensor_motion|sensor_smoke|siren|socket"
},
"title": {
"en": "Device"
Expand Down Expand Up @@ -1494,6 +1494,55 @@
}
]
},
{
"id": "siren_alarm_volume",
"title": {
"en": "Set alarm volume"
},
"titleFormatted": {
"en": "Set alarm volume to [[value]]"
},
"args": [
{
"type": "device",
"name": "device",
"filter": "driver_id=siren"
},
{
"name": "value",
"type": "dropdown",
"title": {
"en": "Alarm volume"
},
"values": [
{
"id": "low",
"label": {
"en": "Low"
}
},
{
"id": "middle",
"label": {
"en": "Middle"
}
},
{
"id": "high",
"label": {
"en": "High"
}
},
{
"id": "mute",
"label": {
"en": "Muted"
}
}
]
}
]
},
{
"id": "socket_sub_switch_off",
"highlight": true,
Expand Down Expand Up @@ -2898,6 +2947,108 @@
}
]
},
{
"capabilities": [
"onoff"
],
"connectivity": [
"cloud"
],
"platforms": [
"local",
"cloud"
],
"images": {
"small": "/drivers/siren/assets/images/small.png",
"large": "/drivers/siren/assets/images/large.png",
"xlarge": "/drivers/siren/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": "siren",
"name": {
"en": "Siren",
"nl": "Sirene"
},
"id": "siren",
"settings": [
{
"id": "alarm_volume",
"type": "dropdown",
"label": {
"en": "Alarm volume level"
},
"hint": {
"en": "The volume level of the siren."
},
"value": "middle",
"values": [
{
"id": "low",
"label": {
"en": "Low"
}
},
{
"id": "middle",
"label": {
"en": "Middle"
}
},
{
"id": "high",
"label": {
"en": "High"
}
},
{
"id": "mute",
"label": {
"en": "Muted"
}
}
]
},
{
"id": "deviceSpecification",
"type": "label",
"label": {
"en": "Device Specification"
},
"hint": {
"en": "The Tuya specification of this device"
},
"value": "<not available>"
}
]
},
{
"capabilities": [
"onoff",
Expand Down
17 changes: 9 additions & 8 deletions drivers/camera/device.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TuyaOAuth2Device from '../../lib/TuyaOAuth2Device';
import * as TuyaOAuth2Util from '../../lib/TuyaOAuth2Util';
import { constIncludes } from '../../lib/TuyaOAuth2Util';
import { constIncludes, getFromMap } from '../../lib/TuyaOAuth2Util';
import { SettingsEvent, TuyaStatus } from '../../types/TuyaTypes';
import {
CAMERA_ALARM_EVENT_CAPABILITIES,
Expand Down Expand Up @@ -50,9 +50,8 @@ module.exports = class TuyaOAuth2DeviceCamera extends TuyaOAuth2Device {

// Reset alarms in case a timeout was interrupted
for (const tuyaCapability in CAMERA_ALARM_EVENT_CAPABILITIES) {
const capability =
CAMERA_ALARM_EVENT_CAPABILITIES[tuyaCapability as keyof typeof CAMERA_ALARM_EVENT_CAPABILITIES];
if (this.hasCapability(capability)) {
const capability = getFromMap(CAMERA_ALARM_EVENT_CAPABILITIES, tuyaCapability);
if (capability && this.hasCapability(capability)) {
await this.setCapabilityValue(capability, false);
}
}
Expand Down Expand Up @@ -112,8 +111,11 @@ module.exports = class TuyaOAuth2DeviceCamera extends TuyaOAuth2Device {

// Check if the event is for a known alarm
if (notificationType in CAMERA_ALARM_EVENT_CAPABILITIES) {
const alarmCapability =
CAMERA_ALARM_EVENT_CAPABILITIES[notificationType as keyof typeof CAMERA_ALARM_EVENT_CAPABILITIES];
const alarmCapability = getFromMap(CAMERA_ALARM_EVENT_CAPABILITIES, notificationType);
if (!alarmCapability) {
continue;
}

if (!this.hasCapability(alarmCapability)) {
await this.addCapability(alarmCapability).catch(this.error);
}
Expand Down Expand Up @@ -166,8 +168,7 @@ module.exports = class TuyaOAuth2DeviceCamera extends TuyaOAuth2Device {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async onSettings(event: SettingsEvent<any>): Promise<string | void> {
async onSettings(event: SettingsEvent<Record<string, unknown>>): Promise<string | void> {
return await TuyaOAuth2Util.onSettings(this, event, CAMERA_SETTING_LABELS);
}
};
Loading

0 comments on commit dc22b39

Please sign in to comment.