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

Create and use wire pilot preset + refactoring #6597

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
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
34 changes: 17 additions & 17 deletions src/converters/fromZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3674,22 +3674,22 @@ const converters1 = {
}
},
} satisfies Fz.Converter,
legrand_cable_outlet_mode: {
legrand_pilot_wire_mode: {
cluster: 'manuSpecificLegrandDevices2',
type: ['readResponse'],
convert: (model, msg, publish, options, meta) => {
const payload: KeyValueAny = {};
const mode = msg.data['0'];

if (mode === 0x00) payload.cable_outlet_mode = 'comfort';
else if (mode === 0x01) payload.cable_outlet_mode = 'comfort-1';
else if (mode === 0x02) payload.cable_outlet_mode = 'comfort-2';
else if (mode === 0x03) payload.cable_outlet_mode = 'eco';
else if (mode === 0x04) payload.cable_outlet_mode = 'frost_protection';
else if (mode === 0x05) payload.cable_outlet_mode = 'off';
if (mode === 0x00) payload.pilot_wire_mode = 'comfort';
else if (mode === 0x01) payload.pilot_wire_mode = 'comfort_-1';
else if (mode === 0x02) payload.pilot_wire_mode = 'comfort_-2';
else if (mode === 0x03) payload.pilot_wire_mode = 'eco';
else if (mode === 0x04) payload.pilot_wire_mode = 'frost_protection';
else if (mode === 0x05) payload.pilot_wire_mode = 'off';
else {
meta.logger.warn(`Bad mode : ${mode}`);
payload.cable_outlet_mode = 'unknown';
payload.pilot_wire_mode = 'unknown';
}
return payload;
},
Expand Down Expand Up @@ -6294,22 +6294,22 @@ const converters2 = {
}
},
} satisfies Fz.Converter,
nodon_fil_pilote_mode: {
cluster: 'manuSpecificNodOnFilPilote',
nodon_pilot_wire_mode: {
cluster: 'manuSpecificNodOnPilotWire',
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
const payload: KeyValueAny = {};
const mode = msg.data['mode'];

if (mode === 0x00) payload.mode = 'stop';
else if (mode === 0x01) payload.mode = 'comfort';
else if (mode === 0x02) payload.mode = 'eco';
else if (mode === 0x03) payload.mode = 'anti-freeze';
else if (mode === 0x04) payload.mode = 'comfort_-1';
else if (mode === 0x05) payload.mode = 'comfort_-2';
if (mode === 0x00) payload.pilot_wire_mode = 'off';
else if (mode === 0x01) payload.pilot_wire_mode = 'comfort';
else if (mode === 0x02) payload.pilot_wire_mode = 'eco';
else if (mode === 0x03) payload.pilot_wire_mode = 'frost_protection';
else if (mode === 0x04) payload.pilot_wire_mode = 'comfort_-1';
else if (mode === 0x05) payload.pilot_wire_mode = 'comfort_-2';
else {
meta.logger.warn(`wrong mode : ${mode}`);
payload.mode = 'unknown';
payload.pilot_wire_mode = 'unknown';
}
return payload;
},
Expand Down
24 changes: 12 additions & 12 deletions src/converters/toZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3799,20 +3799,20 @@ const converters2 = {
await entity.read('manuSpecificLegrandDevices', [0x0000, 0x0001, 0x0002], manufacturerOptions.legrand);
},
} satisfies Tz.Converter,
legrand_cable_outlet_mode: {
key: ['cable_outlet_mode'],
legrand_pilot_wire_mode: {
key: ['pilot_wire_mode'],
convertSet: async (entity, key, value, meta) => {
const mode = {
'comfort': 0x00,
'comfort-1': 0x01,
'comfort-2': 0x02,
'comfort_-1': 0x01,
'comfort_-2': 0x02,
'eco': 0x03,
'frost_protection': 0x04,
'off': 0x05,
};
const payload = {data: Buffer.from([utils.getFromLookup(value, mode)])};
await entity.command('manuSpecificLegrandDevices2', 'command0', payload);
return {state: {'cable_outlet_mode': value}};
return {state: {'pilot_wire_mode': value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('manuSpecificLegrandDevices2', [0x0000], manufacturerOptions.legrand);
Expand Down Expand Up @@ -5029,23 +5029,23 @@ const converters2 = {
await entity.read('ssIasZone', [0x4000], {manufacturerCode: 4919});
},
} satisfies Tz.Converter,
nodon_fil_pilote_mode: {
key: ['mode'],
nodon_pilot_wire_mode: {
key: ['pilot_wire_mode'],
convertSet: async (entity, key, value, meta) => {
const mode = utils.getFromLookup(value, {
'off': 0x00,
'comfort': 0x01,
'eco': 0x02,
'anti-freeze': 0x03,
'stop': 0x00,
'frost_protection': 0x03,
'comfort_-1': 0x04,
'comfort_-2': 0x05,
});
const payload = {'mode': mode};
await entity.command('manuSpecificNodOnFilPilote', 'setMode', payload);
return {state: {'mode': value}};
await entity.command('manuSpecificNodOnPilotWire', 'setMode', payload);
return {state: {'pilot_wire_mode': value}};
},
convertGet: async (entity, key, meta) => {
await entity.read('manuSpecificNodOnFilPilote', [0x0000], manufacturerOptions.nodon);
await entity.read('manuSpecificNodOnPilotWire', [0x0000], manufacturerOptions.nodon);
},
} satisfies Tz.Converter,
// #endregion
Expand Down
10 changes: 5 additions & 5 deletions src/devices/adeo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,23 @@ const definitions: Definition[] = [
model: 'SIN-4-FP-21_EQU',
vendor: 'ADEO',
description: 'Equation pilot wire heating module',
fromZigbee: [fz.on_off, fz.metering, fz.nodon_fil_pilote_mode],
toZigbee: [tz.on_off, tz.nodon_fil_pilote_mode],
fromZigbee: [fz.on_off, fz.metering, fz.nodon_pilot_wire_mode],
toZigbee: [tz.on_off, tz.nodon_pilot_wire_mode],
exposes: [
e.switch(),
e.power(),
e.energy(),
e.enum('mode', ea.ALL, ['comfort', 'eco', 'anti-freeze', 'stop', 'comfort_-1', 'comfort_-2']),
e.pilot_wire_mode(),
],
configure: async (device, coordinatorEndpoint, logger) => {
const ep = device.getEndpoint(1);
await reporting.bind(ep, coordinatorEndpoint, ['genBasic', 'genIdentify', 'genOnOff', 'seMetering', 'manuSpecificNodOnFilPilote']);
await reporting.bind(ep, coordinatorEndpoint, ['genBasic', 'genIdentify', 'genOnOff', 'seMetering', 'manuSpecificNodOnPilotWire']);
await reporting.onOff(ep, {min: 1, max: 3600, change: 0});
await reporting.readMeteringMultiplierDivisor(ep);
await reporting.instantaneousDemand(ep);
await reporting.currentSummDelivered(ep);
const p = reporting.payload('mode', 0, 120, 0, {min: 1, max: 3600, change: 0});
await ep.configureReporting('manuSpecificNodOnFilPilote', p);
await ep.configureReporting('manuSpecificNodOnPilotWire', p);
},
},
];
Expand Down
6 changes: 3 additions & 3 deletions src/devices/legrand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ const definitions: Definition[] = [
vendor: 'Legrand',
description: 'Cable outlet with pilot wire and consumption measurement',
ota: ota.zigbeeOTA,
fromZigbee: [fzLegrand.cluster_fc01, fz.legrand_cable_outlet_mode, fz.on_off, fz.electrical_measurement, fz.power_on_behavior],
toZigbee: [tz.legrand_device_mode, tz.legrand_cable_outlet_mode, tz.on_off, tz.electrical_measurement_power, tz.power_on_behavior],
fromZigbee: [fzLegrand.cluster_fc01, fz.legrand_pilot_wire_mode, fz.on_off, fz.electrical_measurement, fz.power_on_behavior],
toZigbee: [tz.legrand_device_mode, tz.legrand_pilot_wire_mode, tz.on_off, tz.electrical_measurement_power, tz.power_on_behavior],
exposes: [
e.binary('device_mode', ea.ALL, 'pilot_on', 'pilot_off'),
e.enum('cable_outlet_mode', ea.ALL, ['comfort', 'comfort-1', 'comfort-2', 'eco', 'frost_protection', 'off']),
e.pilot_wire_mode(),
e.switch().withState('state', true, 'Works only when the pilot wire is deactivated'),
e.power().withAccess(ea.STATE_GET),
e.power_apparent(),
Expand Down
21 changes: 10 additions & 11 deletions src/devices/nodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
import * as ota from '../lib/ota';
const e = exposes.presets;
const ea = exposes.access;
import tz from '../converters/toZigbee';
import fz from '../converters/fromZigbee';

Expand Down Expand Up @@ -123,22 +122,22 @@ const definitions: Definition[] = [
vendor: 'NodOn',
description: 'Pilot wire heating module',
ota: ota.zigbeeOTA,
fromZigbee: [fz.on_off, fz.metering, fz.nodon_fil_pilote_mode],
toZigbee: [tz.on_off, tz.nodon_fil_pilote_mode],
fromZigbee: [fz.on_off, fz.metering, fz.nodon_pilot_wire_mode],
toZigbee: [tz.on_off, tz.nodon_pilot_wire_mode],
exposes: [
e.switch(),
e.power(),
e.energy(),
e.enum('mode', ea.ALL, ['comfort', 'eco', 'anti-freeze', 'stop', 'comfort_-1', 'comfort_-2']),
e.pilot_wire_mode(),
],
configure: async (device, coordinatorEndpoint, logger) => {
const ep = device.getEndpoint(1);
await reporting.bind(ep, coordinatorEndpoint, ['genBasic', 'genIdentify', 'genOnOff', 'seMetering', 'manuSpecificNodOnFilPilote']);
await reporting.bind(ep, coordinatorEndpoint, ['genBasic', 'genIdentify', 'genOnOff', 'seMetering', 'manuSpecificNodOnPilotWire']);
await reporting.onOff(ep, {min: 1, max: 3600, change: 0});
await reporting.readMeteringMultiplierDivisor(ep);
await reporting.instantaneousDemand(ep);
await reporting.currentSummDelivered(ep);
await ep.read('manuSpecificNodOnFilPilote', ['mode']);
await ep.read('manuSpecificNodOnPilotWire', ['mode']);
},
},
{
Expand All @@ -147,22 +146,22 @@ const definitions: Definition[] = [
vendor: 'NodOn',
description: 'Pilot wire heating module',
ota: ota.zigbeeOTA,
fromZigbee: [fz.on_off, fz.metering, fz.nodon_fil_pilote_mode],
toZigbee: [tz.on_off, tz.nodon_fil_pilote_mode],
fromZigbee: [fz.on_off, fz.metering, fz.nodon_pilot_wire_mode],
toZigbee: [tz.on_off, tz.nodon_pilot_wire_mode],
exposes: [
e.switch(),
e.power(),
e.energy(),
e.enum('mode', ea.ALL, ['comfort', 'eco', 'anti-freeze', 'stop', 'comfort_-1', 'comfort_-2']),
e.pilot_wire_mode(),
],
configure: async (device, coordinatorEndpoint, logger) => {
const ep = device.getEndpoint(1);
await reporting.bind(ep, coordinatorEndpoint, ['genBasic', 'genIdentify', 'genOnOff', 'seMetering', 'manuSpecificNodOnFilPilote']);
await reporting.bind(ep, coordinatorEndpoint, ['genBasic', 'genIdentify', 'genOnOff', 'seMetering', 'manuSpecificNodOnPilotWire']);
await reporting.onOff(ep, {min: 1, max: 3600, change: 0});
await reporting.readMeteringMultiplierDivisor(ep);
await reporting.instantaneousDemand(ep);
await reporting.currentSummDelivered(ep);
await ep.read('manuSpecificNodOnFilPilote', ['mode']);
await ep.read('manuSpecificNodOnPilotWire', ['mode']);
},
},
{
Expand Down
1 change: 1 addition & 0 deletions src/lib/exposes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ export const presets = {
voltage_phase_b: () => new Numeric('voltage_phase_b', access.STATE).withLabel('Voltage phase B').withUnit('V').withDescription('Measured electrical potential value on phase B'),
voltage_phase_c: () => new Numeric('voltage_phase_c', access.STATE).withLabel('Voltage phase C').withUnit('V').withDescription('Measured electrical potential value on phase C'),
water_leak: () => new Binary('water_leak', access.STATE, true, false).withDescription('Indicates whether the device detected a water leak'),
pilot_wire_mode: (values=['comfort', 'eco', 'frost_protection', 'off', 'comfort_-1', 'comfort_-2']) => new Enum('pilot_wire_mode', access.ALL, ['comfort', 'eco', 'frost_protection', 'off', 'comfort_-1', 'comfort_-2']).withDescription('Controls the target temperature of the heater, with respect to the temperature set on that heater. Possible values: comfort (target temperature = heater set temperature) eco (target temperature = heater set temperature - 3.5°C), frost_protection (target temperature = 7 to 8°C), off (heater stops heating), and the less commonly used comfort_-1 (target temperature = heater set temperature - 1°C), comfort_-2 (target temperature = heater set temperature - 2°C),.'),
rain: () => new Binary('rain', access.STATE, true, false).withDescription('Indicates whether the device detected rainfall'),
warning: () => new Composite('warning', 'warning', access.SET)
.withFeature(new Enum('mode', access.SET, ['stop', 'burglar', 'fire', 'emergency', 'police_panic', 'fire_panic', 'emergency_panic']).withDescription('Mode of the warning (sound effect)'))
Expand Down