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 a custom cluster for Perenio PEHPL0X #8007

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all 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
55 changes: 36 additions & 19 deletions src/devices/perenio.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Zcl} from 'zigbee-herdsman';

import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import * as exposes from '../lib/exposes';
import {deviceAddCustomCluster} from '../lib/modernExtend';
import * as ota from '../lib/ota';
import * as reporting from '../lib/reporting';
import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types';
Expand All @@ -13,6 +16,19 @@ const switchTypeValues = ['maintained_state', 'maintained_toggle', 'momentary_st

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

const manufacturerOptions = {manufacturerCode: Zcl.ManufacturerCode.CUSTOM_PERENIO};

const perenioExtend = {
addCustomClusterPerenio: () =>
deviceAddCustomCluster('perenioSpecific', {
ID: 64635,
manufacturerCode: Zcl.ManufacturerCode.CUSTOM_PERENIO,
attributes: {},
commands: {},
commandsResponse: {},
}),
};

const fzPerenio = {
diagnostic: {
cluster: 'haDiagnostic',
Expand Down Expand Up @@ -48,7 +64,7 @@ const fzPerenio = {
},
} satisfies Fz.Converter,
smart_plug: {
cluster: '64635',
cluster: 'perenioSpecific',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const result: KeyValue = {};
Expand Down Expand Up @@ -142,55 +158,55 @@ const tzPerenio = {
on: 1,
previous: 2,
};
await entity.write(64635, {0: {value: powerOnStateLookup[val], type: 0x20}}, {manufacturerCode: 0x007b});
await entity.write('perenioSpecific', {0: {value: powerOnStateLookup[val], type: 0x20}}, manufacturerOptions);
return {state: {default_on_off_state: val}};
},
convertGet: async (entity, key, meta) => {
await entity.read(64635, [0]);
await entity.read('perenioSpecific', [0]);
},
} satisfies Tz.Converter,
alarms_reset: {
key: ['alarm_voltage_min', 'alarm_voltage_max', 'alarm_power_max', 'alarm_consumed_energy'],
convertSet: async (entity, key, val, meta) => {
await entity.write(64635, {1: {value: 0, type: 0x20}}, {manufacturerCode: 0x007b});
await entity.write('perenioSpecific', {1: {value: 0, type: 0x20}}, manufacturerOptions);
return {state: {alarm_voltage_min: false, alarm_voltage_max: false, alarm_power_max: false, alarm_consumed_energy: false}};
},
convertGet: async (entity, key, meta) => {
await entity.read(64635, [1]);
await entity.read('perenioSpecific', [1]);
},
} satisfies Tz.Converter,
alarms_limits: {
key: ['voltage_min', 'voltage_max', 'power_max', 'consumed_energy_limit'],
convertSet: async (entity, key, val, meta) => {
switch (key) {
case 'voltage_min':
await entity.write(64635, {4: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
await entity.write('perenioSpecific', {4: {value: val, type: 0x21}}, manufacturerOptions);
break;
case 'voltage_max':
await entity.write(64635, {5: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
await entity.write('perenioSpecific', {5: {value: val, type: 0x21}}, manufacturerOptions);
break;
case 'power_max':
await entity.write(64635, {11: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
await entity.write('perenioSpecific', {11: {value: val, type: 0x21}}, manufacturerOptions);
break;
case 'consumed_energy_limit':
await entity.write(64635, {15: {value: val, type: 0x21}}, {manufacturerCode: 0x007b});
await entity.write('perenioSpecific', {15: {value: val, type: 0x21}}, manufacturerOptions);
break;
}
return {state: {[key]: val}};
},
convertGet: async (entity, key, meta) => {
switch (key) {
case 'voltage_min':
await entity.read(64635, [4]);
await entity.read('perenioSpecific', [4]);
break;
case 'voltage_max':
await entity.read(64635, [5]);
await entity.read('perenioSpecific', [5]);
break;
case 'power_max':
await entity.read(64635, [11]);
await entity.read('perenioSpecific', [11]);
break;
case 'consumed_energy_limit':
await entity.read(64635, [15]);
await entity.read('perenioSpecific', [15]);
break;
}
},
Expand Down Expand Up @@ -347,11 +363,12 @@ const definitions: DefinitionWithExtend[] = [
model: 'PEHPL0X',
vendor: 'Perenio',
description: 'Power link',
extend: [perenioExtend.addCustomClusterPerenio()],
fromZigbee: [fz.on_off, fzPerenio.smart_plug, fz.metering],
toZigbee: [tzPerenio.on_off_mod, tzPerenio.default_state, tzPerenio.alarms_reset, tzPerenio.alarms_limits],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 64635]);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'perenioSpecific']);
const payload = [
{
attribute: 'onOff',
Expand All @@ -361,32 +378,32 @@ const definitions: DefinitionWithExtend[] = [
},
];
await endpoint.configureReporting('genOnOff', payload);
await endpoint.configureReporting(64635, [
await endpoint.configureReporting('perenioSpecific', [
{
attribute: {ID: 0x000a, type: 0x21},
minimumReportInterval: 5,
maximumReportInterval: 60,
reportableChange: 0,
},
]);
await endpoint.configureReporting(64635, [
await endpoint.configureReporting('perenioSpecific', [
{
attribute: {ID: 0x000e, type: 0x23},
minimumReportInterval: 5,
maximumReportInterval: 60,
reportableChange: 0,
},
]);
await endpoint.configureReporting(64635, [
await endpoint.configureReporting('perenioSpecific', [
{
attribute: {ID: 0x0003, type: 0x21},
minimumReportInterval: 5,
maximumReportInterval: 5,
reportableChange: 0,
},
]);
await endpoint.read(64635, [0, 1, 2, 3]);
await endpoint.read(64635, [4, 5, 11, 15]);
await endpoint.read('perenioSpecific', [0, 1, 2, 3]);
await endpoint.read('perenioSpecific', [4, 5, 11, 15]);
},
exposes: [
e.switch(),
Expand Down
Loading