Skip to content

Commit aac55d8

Browse files
committed
Add custom cluster for Perenio PEHPL0X
1 parent a687fe3 commit aac55d8

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

src/devices/perenio.ts

+35-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as ota from '../lib/ota';
55
import * as reporting from '../lib/reporting';
66
import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types';
77
import * as utils from '../lib/utils';
8+
import {Zcl} from 'zigbee-herdsman';
9+
import {deviceAddCustomCluster} from '../lib/modernExtend';
810

911
const e = exposes.presets;
1012
const ea = exposes.access;
@@ -13,6 +15,19 @@ const switchTypeValues = ['maintained_state', 'maintained_toggle', 'momentary_st
1315

1416
const defaultOnOffStateValues = ['on', 'off', 'previous'];
1517

18+
const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.CUSTOM_PERENIO};
19+
20+
const perenioExtend = {
21+
addCustomClusterPerenio: () =>
22+
deviceAddCustomCluster('perenioSpecific', {
23+
ID: 64635,
24+
manufacturerCode: Zcl.ManufacturerCode.CUSTOM_PERENIO,
25+
attributes: {},
26+
commands: {},
27+
commandsResponse: {},
28+
}),
29+
};
30+
1631
const fzPerenio = {
1732
diagnostic: {
1833
cluster: 'haDiagnostic',
@@ -48,7 +63,7 @@ const fzPerenio = {
4863
},
4964
} satisfies Fz.Converter,
5065
smart_plug: {
51-
cluster: '64635',
66+
cluster: 'perenioSpecific',
5267
type: ['attributeReport', 'readResponse'],
5368
convert: (model, msg, publish, options, meta) => {
5469
const result: KeyValue = {};
@@ -142,55 +157,55 @@ const tzPerenio = {
142157
on: 1,
143158
previous: 2,
144159
};
145-
await entity.write(64635, {0: {value: powerOnStateLookup[val], type: 0x20}}, {manufacturerCode: 0x007b});
160+
await entity.write('perenioSpecific', {0: {value: powerOnStateLookup[val], type: 0x20}}, manufacturerOptions);
146161
return {state: {default_on_off_state: val}};
147162
},
148163
convertGet: async (entity, key, meta) => {
149-
await entity.read(64635, [0]);
164+
await entity.read('perenioSpecific', [0]);
150165
},
151166
} satisfies Tz.Converter,
152167
alarms_reset: {
153168
key: ['alarm_voltage_min', 'alarm_voltage_max', 'alarm_power_max', 'alarm_consumed_energy'],
154169
convertSet: async (entity, key, val, meta) => {
155-
await entity.write(64635, {1: {value: 0, type: 0x20}}, {manufacturerCode: 0x007b});
170+
await entity.write('perenioSpecific', {1: {value: 0, type: 0x20}}, manufacturerOptions);
156171
return {state: {alarm_voltage_min: false, alarm_voltage_max: false, alarm_power_max: false, alarm_consumed_energy: false}};
157172
},
158173
convertGet: async (entity, key, meta) => {
159-
await entity.read(64635, [1]);
174+
await entity.read('perenioSpecific', [1]);
160175
},
161176
} satisfies Tz.Converter,
162177
alarms_limits: {
163178
key: ['voltage_min', 'voltage_max', 'power_max', 'consumed_energy_limit'],
164179
convertSet: async (entity, key, val, meta) => {
165180
switch (key) {
166181
case 'voltage_min':
167-
await entity.write(64635, {4: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
182+
await entity.write('perenioSpecific', {4: {value: val, type: 0x21}}, manufacturerOptions);
168183
break;
169184
case 'voltage_max':
170-
await entity.write(64635, {5: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
185+
await entity.write('perenioSpecific', {5: {value: val, type: 0x21}}, manufacturerOptions);
171186
break;
172187
case 'power_max':
173-
await entity.write(64635, {11: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
188+
await entity.write('perenioSpecific', {11: {value: val, type: 0x21}}, manufacturerOptions);
174189
break;
175190
case 'consumed_energy_limit':
176-
await entity.write(64635, {15: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
191+
await entity.write('perenioSpecific', {15: {value: val, type: 0x21}}, manufacturerOptions);
177192
break;
178193
}
179194
return {state: {[key]: val}};
180195
},
181196
convertGet: async (entity, key, meta) => {
182197
switch (key) {
183198
case 'voltage_min':
184-
await entity.read(64635, [4]);
199+
await entity.read('perenioSpecific', [4]);
185200
break;
186201
case 'voltage_max':
187-
await entity.read(64635, [5]);
202+
await entity.read('perenioSpecific', [5]);
188203
break;
189204
case 'power_max':
190-
await entity.read(64635, [11]);
205+
await entity.read('perenioSpecific', [11]);
191206
break;
192207
case 'consumed_energy_limit':
193-
await entity.read(64635, [15]);
208+
await entity.read('perenioSpecific', [15]);
194209
break;
195210
}
196211
},
@@ -347,11 +362,12 @@ const definitions: DefinitionWithExtend[] = [
347362
model: 'PEHPL0X',
348363
vendor: 'Perenio',
349364
description: 'Power link',
365+
extend: [perenioExtend.addCustomClusterPerenio()],
350366
fromZigbee: [fz.on_off, fzPerenio.smart_plug, fz.metering],
351367
toZigbee: [tzPerenio.on_off_mod, tzPerenio.default_state, tzPerenio.alarms_reset, tzPerenio.alarms_limits],
352368
configure: async (device, coordinatorEndpoint) => {
353369
const endpoint = device.getEndpoint(1);
354-
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 64635]);
370+
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'perenioSpecific']);
355371
const payload = [
356372
{
357373
attribute: 'onOff',
@@ -361,32 +377,32 @@ const definitions: DefinitionWithExtend[] = [
361377
},
362378
];
363379
await endpoint.configureReporting('genOnOff', payload);
364-
await endpoint.configureReporting(64635, [
380+
await endpoint.configureReporting('perenioSpecific', [
365381
{
366382
attribute: {ID: 0x000a, type: 0x21},
367383
minimumReportInterval: 5,
368384
maximumReportInterval: 60,
369385
reportableChange: 0,
370386
},
371387
]);
372-
await endpoint.configureReporting(64635, [
388+
await endpoint.configureReporting('perenioSpecific', [
373389
{
374390
attribute: {ID: 0x000e, type: 0x23},
375391
minimumReportInterval: 5,
376392
maximumReportInterval: 60,
377393
reportableChange: 0,
378394
},
379395
]);
380-
await endpoint.configureReporting(64635, [
396+
await endpoint.configureReporting('perenioSpecific', [
381397
{
382398
attribute: {ID: 0x0003, type: 0x21},
383399
minimumReportInterval: 5,
384400
maximumReportInterval: 5,
385401
reportableChange: 0,
386402
},
387403
]);
388-
await endpoint.read(64635, [0, 1, 2, 3]);
389-
await endpoint.read(64635, [4, 5, 11, 15]);
404+
await endpoint.read('perenioSpecific', [0, 1, 2, 3]);
405+
await endpoint.read('perenioSpecific', [4, 5, 11, 15]);
390406
},
391407
exposes: [
392408
e.switch(),

0 commit comments

Comments
 (0)