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

Tuya RB-SRAIN01: change 'water-leak' to 'rain'; remove 'battery_low' and 'tamper' #7946

Merged
merged 11 commits into from
Sep 7, 2024
Merged
6 changes: 2 additions & 4 deletions src/devices/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,16 +1896,14 @@ const definitions: DefinitionWithExtend[] = [
model: 'RB-SRAIN01',
vendor: 'Tuya',
description: 'Solar rain sensor',
fromZigbee: [tuya.fz.datapoints, fz.battery, fz.ias_water_leak_alarm_1],
toZigbee: [],
fromZigbee: [tuya.fz.datapoints],
extend: [iasZoneAlarm({zoneType: 'rain', zoneAttributes: ['alarm_1']}), battery({percentageReporting: false})],
exposes: [
e.water_leak().withDescription('Droplet detection (raining)'),
e.illuminance().withUnit('lx'),
e.numeric('illuminance_average_20min', ea.STATE).withUnit('lx').withDescription('Illuminance average for the last 20 minutes'),
e.numeric('illuminance_maximum_today', ea.STATE).withUnit('lx').withDescription('Illuminance maximum for the last 24 hours'),
e.binary('cleaning_reminder', ea.STATE, 'ON', 'OFF').withDescription('Cleaning reminder'),
e.numeric('rain_intensity', ea.STATE).withUnit('mV').withDescription('Rainfall intensity'),
e.battery(),
],
meta: {
tuyaDatapoints: [
Expand Down
56 changes: 43 additions & 13 deletions src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,18 @@ export function commandsWindowCovering(args?: CommandsWindowCoveringArgs): Moder

// #region Security and Safety

export type iasZoneType = 'occupancy' | 'contact' | 'smoke' | 'water_leak' | 'carbon_monoxide' | 'sos' | 'vibration' | 'alarm' | 'gas' | 'generic';
export type iasZoneType =
| 'occupancy'
| 'contact'
| 'smoke'
| 'water_leak'
| 'rain'
| 'carbon_monoxide'
| 'sos'
| 'vibration'
| 'alarm'
| 'gas'
| 'generic';
export type iasZoneAttribute =
| 'alarm_1'
| 'alarm_2'
Expand All @@ -1373,6 +1384,7 @@ export type iasZoneAttribute =
| 'restore_reports'
| 'ac_status'
| 'test'
| 'trouble'
| 'battery_defect';
export interface IasArgs {
zoneType: iasZoneType;
Expand All @@ -1393,6 +1405,7 @@ export function iasZoneAlarm(args: IasArgs): ModernExtend {
alarm_1: e.binary('alarm_1', ea.STATE, true, false).withDescription('Indicates whether IAS Zone alarm 1 is active'),
alarm_2: e.binary('alarm_2', ea.STATE, true, false).withDescription('Indicates whether IAS Zone alarm 2 is active'),
tamper: e.binary('tamper', ea.STATE, true, false).withDescription('Indicates whether the device is tampered').withCategory('diagnostic'),
rain: e.binary('rain', ea.STATE, true, false).withDescription('Indicates whether the device detected rainfall'),
battery_low: e
.binary('battery_low', ea.STATE, true, false)
.withDescription('Indicates whether the battery of the device is almost empty')
Expand All @@ -1413,6 +1426,10 @@ export function iasZoneAlarm(args: IasArgs): ModernExtend {
.binary('test', ea.STATE, true, false)
.withDescription('Indicates whether the device is currently performing a test')
.withCategory('diagnostic'),
trouble: e
.binary('trouble', ea.STATE, true, false)
.withDescription('Indicates whether the device is currently havin trouble')
.withCategory('diagnostic'),
battery_defect: e
.binary('battery_defect', ea.STATE, true, false)
.withDescription('Indicates whether the device battery is defective')
Expand Down Expand Up @@ -1473,18 +1490,31 @@ export function iasZoneAlarm(args: IasArgs): ModernExtend {
globalStore.putValue(msg.endpoint, 'timer', timer);
}
}

let payload = {
tamper: (zoneStatus & (1 << 2)) > 0,
battery_low: (zoneStatus & (1 << 3)) > 0,
supervision_reports: (zoneStatus & (1 << 4)) > 0,
restore_reports: (zoneStatus & (1 << 5)) > 0,
trouble: (zoneStatus & (1 << 6)) > 0,
ac_status: (zoneStatus & (1 << 7)) > 0,
test: (zoneStatus & (1 << 8)) > 0,
battery_defect: (zoneStatus & (1 << 9)) > 0,
};

let payload = {};
if (args.zoneAttributes.includes('tamper')) {
payload = {tamper: (zoneStatus & (1 << 2)) > 0, ...payload};
}
if (args.zoneAttributes.includes('battery_low')) {
payload = {battery_low: (zoneStatus & (1 << 3)) > 0, ...payload};
}
if (args.zoneAttributes.includes('supervision_reports')) {
payload = {supervision_reports: (zoneStatus & (1 << 4)) > 0, ...payload};
}
if (args.zoneAttributes.includes('restore_reports')) {
payload = {restore_reports: (zoneStatus & (1 << 5)) > 0, ...payload};
}
if (args.zoneAttributes.includes('trouble')) {
payload = {trouble: (zoneStatus & (1 << 6)) > 0, ...payload};
}
if (args.zoneAttributes.includes('ac_status')) {
payload = {ac_status: (zoneStatus & (1 << 7)) > 0, ...payload};
}
if (args.zoneAttributes.includes('test')) {
payload = {test: (zoneStatus & (1 << 8)) > 0, ...payload};
}
if (args.zoneAttributes.includes('battery_defect')) {
payload = {battery_defect: (zoneStatus & (1 << 9)) > 0, ...payload};
}
let alarm1Payload = (zoneStatus & 1) > 0;
let alarm2Payload = (zoneStatus & (1 << 1)) > 0;

Expand Down
Loading