Skip to content

Commit 03b2255

Browse files
authored
fix: Add custom cluster for Perenio PEHPL0X (#8007)
1 parent 89962a5 commit 03b2255

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

src/devices/perenio.ts

+36-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import {Zcl} from 'zigbee-herdsman';
2+
13
import fz from '../converters/fromZigbee';
24
import tz from '../converters/toZigbee';
35
import * as exposes from '../lib/exposes';
6+
import {deviceAddCustomCluster} from '../lib/modernExtend';
47
import * as ota from '../lib/ota';
58
import * as reporting from '../lib/reporting';
69
import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types';
@@ -13,6 +16,19 @@ const switchTypeValues = ['maintained_state', 'maintained_toggle', 'momentary_st
1316

1417
const defaultOnOffStateValues = ['on', 'off', 'previous'];
1518

19+
const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.CUSTOM_PERENIO};
20+
21+
const perenioExtend = {
22+
addCustomClusterPerenio: () =>
23+
deviceAddCustomCluster('perenioSpecific', {
24+
ID: 64635,
25+
manufacturerCode: Zcl.ManufacturerCode.CUSTOM_PERENIO,
26+
attributes: {},
27+
commands: {},
28+
commandsResponse: {},
29+
}),
30+
};
31+
1632
const fzPerenio = {
1733
diagnostic: {
1834
cluster: 'haDiagnostic',
@@ -48,7 +64,7 @@ const fzPerenio = {
4864
},
4965
} satisfies Fz.Converter,
5066
smart_plug: {
51-
cluster: '64635',
67+
cluster: 'perenioSpecific',
5268
type: ['attributeReport', 'readResponse'],
5369
convert: (model, msg, publish, options, meta) => {
5470
const result: KeyValue = {};
@@ -142,55 +158,55 @@ const tzPerenio = {
142158
on: 1,
143159
previous: 2,
144160
};
145-
await entity.write(64635, {0: {value: powerOnStateLookup[val], type: 0x20}}, {manufacturerCode: 0x007b});
161+
await entity.write('perenioSpecific', {0: {value: powerOnStateLookup[val], type: 0x20}}, manufacturerOptions);
146162
return {state: {default_on_off_state: val}};
147163
},
148164
convertGet: async (entity, key, meta) => {
149-
await entity.read(64635, [0]);
165+
await entity.read('perenioSpecific', [0]);
150166
},
151167
} satisfies Tz.Converter,
152168
alarms_reset: {
153169
key: ['alarm_voltage_min', 'alarm_voltage_max', 'alarm_power_max', 'alarm_consumed_energy'],
154170
convertSet: async (entity, key, val, meta) => {
155-
await entity.write(64635, {1: {value: 0, type: 0x20}}, {manufacturerCode: 0x007b});
171+
await entity.write('perenioSpecific', {1: {value: 0, type: 0x20}}, manufacturerOptions);
156172
return {state: {alarm_voltage_min: false, alarm_voltage_max: false, alarm_power_max: false, alarm_consumed_energy: false}};
157173
},
158174
convertGet: async (entity, key, meta) => {
159-
await entity.read(64635, [1]);
175+
await entity.read('perenioSpecific', [1]);
160176
},
161177
} satisfies Tz.Converter,
162178
alarms_limits: {
163179
key: ['voltage_min', 'voltage_max', 'power_max', 'consumed_energy_limit'],
164180
convertSet: async (entity, key, val, meta) => {
165181
switch (key) {
166182
case 'voltage_min':
167-
await entity.write(64635, {4: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
183+
await entity.write('perenioSpecific', {4: {value: val, type: 0x21}}, manufacturerOptions);
168184
break;
169185
case 'voltage_max':
170-
await entity.write(64635, {5: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
186+
await entity.write('perenioSpecific', {5: {value: val, type: 0x21}}, manufacturerOptions);
171187
break;
172188
case 'power_max':
173-
await entity.write(64635, {11: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
189+
await entity.write('perenioSpecific', {11: {value: val, type: 0x21}}, manufacturerOptions);
174190
break;
175191
case 'consumed_energy_limit':
176-
await entity.write(64635, {15: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
192+
await entity.write('perenioSpecific', {15: {value: val, type: 0x21}}, manufacturerOptions);
177193
break;
178194
}
179195
return {state: {[key]: val}};
180196
},
181197
convertGet: async (entity, key, meta) => {
182198
switch (key) {
183199
case 'voltage_min':
184-
await entity.read(64635, [4]);
200+
await entity.read('perenioSpecific', [4]);
185201
break;
186202
case 'voltage_max':
187-
await entity.read(64635, [5]);
203+
await entity.read('perenioSpecific', [5]);
188204
break;
189205
case 'power_max':
190-
await entity.read(64635, [11]);
206+
await entity.read('perenioSpecific', [11]);
191207
break;
192208
case 'consumed_energy_limit':
193-
await entity.read(64635, [15]);
209+
await entity.read('perenioSpecific', [15]);
194210
break;
195211
}
196212
},
@@ -347,11 +363,12 @@ const definitions: DefinitionWithExtend[] = [
347363
model: 'PEHPL0X',
348364
vendor: 'Perenio',
349365
description: 'Power link',
366+
extend: [perenioExtend.addCustomClusterPerenio()],
350367
fromZigbee: [fz.on_off, fzPerenio.smart_plug, fz.metering],
351368
toZigbee: [tzPerenio.on_off_mod, tzPerenio.default_state, tzPerenio.alarms_reset, tzPerenio.alarms_limits],
352369
configure: async (device, coordinatorEndpoint) => {
353370
const endpoint = device.getEndpoint(1);
354-
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 64635]);
371+
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'perenioSpecific']);
355372
const payload = [
356373
{
357374
attribute: 'onOff',
@@ -361,32 +378,32 @@ const definitions: DefinitionWithExtend[] = [
361378
},
362379
];
363380
await endpoint.configureReporting('genOnOff', payload);
364-
await endpoint.configureReporting(64635, [
381+
await endpoint.configureReporting('perenioSpecific', [
365382
{
366383
attribute: {ID: 0x000a, type: 0x21},
367384
minimumReportInterval: 5,
368385
maximumReportInterval: 60,
369386
reportableChange: 0,
370387
},
371388
]);
372-
await endpoint.configureReporting(64635, [
389+
await endpoint.configureReporting('perenioSpecific', [
373390
{
374391
attribute: {ID: 0x000e, type: 0x23},
375392
minimumReportInterval: 5,
376393
maximumReportInterval: 60,
377394
reportableChange: 0,
378395
},
379396
]);
380-
await endpoint.configureReporting(64635, [
397+
await endpoint.configureReporting('perenioSpecific', [
381398
{
382399
attribute: {ID: 0x0003, type: 0x21},
383400
minimumReportInterval: 5,
384401
maximumReportInterval: 5,
385402
reportableChange: 0,
386403
},
387404
]);
388-
await endpoint.read(64635, [0, 1, 2, 3]);
389-
await endpoint.read(64635, [4, 5, 11, 15]);
405+
await endpoint.read('perenioSpecific', [0, 1, 2, 3]);
406+
await endpoint.read('perenioSpecific', [4, 5, 11, 15]);
390407
},
391408
exposes: [
392409
e.switch(),

0 commit comments

Comments
 (0)