Skip to content

Commit

Permalink
fix: Convert Bosch BWA-1 to modernExtend (#7523)
Browse files Browse the repository at this point in the history
* Convert Bosch BWA-1 to `modernExtend`

* Add missing imports

* Fix for `zoneAttributes`

* Use correct type for `zoneAttributes`
  • Loading branch information
burmistrzak committed May 15, 2024
1 parent 4625587 commit 7456646
Showing 1 changed file with 45 additions and 52 deletions.
97 changes: 45 additions & 52 deletions src/devices/bosch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
identify, light, onOff, quirkCheckinInterval,
deviceAddCustomCluster, binary, numeric, enumLookup,
battery, humidity,
battery, humidity, iasZoneAlarm, bindCluster,
} from '../lib/modernExtend';
import {Zcl, ZSpec} from 'zigbee-herdsman';
import * as exposes from '../lib/exposes';
Expand Down Expand Up @@ -606,25 +606,6 @@ const tzLocal = {
}
},
} satisfies Tz.Converter,
bwa1_alarm_on_motion: {
key: ['alarm_on_motion'],
convertSet: async (entity, key, value, meta) => {
if (key === 'alarm_on_motion') {
const index = utils.getFromLookup(value, stateOffOn);
await entity.write('manuSpecificBosch11', {alarmOnMotion: index}, manufacturerOptions);
return {state: {alarm_on_motion: value}};
}
},
convertGet: async (entity, key, meta) => {
switch (key) {
case 'alarm_on_motion':
await entity.read('manuSpecificBosch11', ['alarmOnMotion'], manufacturerOptions);
break;
default: // Unknown key
throw new Error(`Unhandled key toZigbee.bwa1_alarm_on_motion.convertGet ${key}`);
}
},
} satisfies Tz.Converter,
bosch_twinguard: {
key: ['sensitivity', 'pre_alarm', 'self_test', 'alarm', 'heartbeat'],
convertSet: async (entity, key, value, meta) => {
Expand Down Expand Up @@ -775,17 +756,6 @@ const fzLocal = {
return result;
},
} satisfies Fz.Converter,
bwa1_alarm_on_motion: {
cluster: 'manuSpecificBosch11',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: KeyValue = {};
if (msg.data.hasOwnProperty('alarmOnMotion')) {
result.alarm_on_motion = (Object.keys(stateOffOn)[msg.data['alarmOnMotion']]);
}
return result;
},
} satisfies Fz.Converter,
bosch_contact: {
cluster: 'ssIasZone',
type: 'commandStatusChangeNotification',
Expand Down Expand Up @@ -1018,31 +988,54 @@ const definitions: Definition[] = [
zigbeeModel: ['RBSH-WS-ZB-EU'],
model: 'BWA-1',
vendor: 'Bosch',
description: 'Zigbee smart water leak detector',
fromZigbee: [
fz.battery,
fz.ias_water_leak_alarm_1,
fzLocal.bwa1_alarm_on_motion,
],
toZigbee: [
tzLocal.bwa1_alarm_on_motion,
description: 'Smart water alarm',
exposes: [],
fromZigbee: [],
toZigbee: [],
extend: [
deviceAddCustomCluster(
'boschSpecific',
{
ID: 0xfcac,
attributes: {
alarmOnMotion: {
ID: 0x0003,
type: Zcl.DataType.BOOLEAN,
manufacturerCode: Zcl.ManufacturerCode.ROBERT_BOSCH_GMBH,
},
},
commands: {},
commandsResponse: {},
},
),
battery({
percentage: true,
lowStatus: true,
}),
iasZoneAlarm({
zoneType: 'water_leak',
zoneAttributes: ['tamper'],
}),
binary({
name: 'alarm_on_motion',
cluster: 'boschSpecific',
attribute: 'alarmOnMotion',
description: 'Toggle audible alarm on motion',
valueOn: ['ON', 0x01],
valueOff: ['OFF', 0x00],
zigbeeCommandOptions: manufacturerOptions,
entityCategory: 'config',
}),
bindCluster({
cluster: 'genPollCtrl',
clusterType: 'input',
}),
],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, [
'genPowerCfg',
'genPollCtrl',
]);
await reporting.batteryPercentageRemaining(endpoint);
await endpoint.read('manuSpecificBosch11', ['alarmOnMotion'], manufacturerOptions);
await endpoint.read('ssIasZone', ['zoneStatus']);
await endpoint.read('boschSpecific', ['alarmOnMotion'], manufacturerOptions);
},
exposes: [
e.water_leak(),
e.tamper(),
e.battery(),
e.battery_low(),
e.binary('alarm_on_motion', ea.ALL, 'ON', 'OFF').withDescription('Enable/Disable sound alarm on motion'),
],
},
{
zigbeeModel: ['RBSH-SD-ZB-EU'],
Expand Down

0 comments on commit 7456646

Please sign in to comment.