Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add siren support #161

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 8 additions & 6 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
Loading
Loading