Skip to content

Commit

Permalink
feat(ignore): Refactor more to modernExtend (#7168)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Mar 6, 2024
1 parent c5c9d14 commit ed7ed68
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 446 deletions.
14 changes: 4 additions & 10 deletions src/devices/bticino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
import * as ota from '../lib/ota';
import {fzLegrand, tzLegrand} from '../lib/legrand';
import {light} from '../lib/modernExtend';
const e = exposes.presets;
const ea = exposes.access;

Expand Down Expand Up @@ -39,10 +40,9 @@ const definitions: Definition[] = [
vendor: 'BTicino',
description: 'Dimmer switch with neutral',
ota: ota.zigbeeOTA,
fromZigbee: [fz.brightness, fz.identify, fz.on_off, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01],
toZigbee: [tz.light_onoff_brightness, tzLegrand.led_mode, tz.legrand_device_mode, tz.legrand_identify, tz.ballast_config],
fromZigbee: [fz.identify, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01],
toZigbee: [tzLegrand.led_mode, tz.legrand_device_mode, tz.legrand_identify, tz.ballast_config],
exposes: [
e.light_brightness(),
e.numeric('ballast_minimum_level', ea.ALL).withValueMin(1).withValueMax(254)
.withDescription('Specifies the minimum brightness value'),
e.numeric('ballast_maximum_level', ea.ALL).withValueMin(1).withValueMax(254)
Expand All @@ -56,13 +56,7 @@ const definitions: Definition[] = [
e.enum('identify', ea.SET, ['blink'])
.withDescription('Blinks the built-in LED to make it easier to find the device'),
],
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genOnOff', 'genLevelCtrl', 'genBinaryInput', 'lightingBallastCfg']);
await reporting.onOff(endpoint);
await reporting.brightness(endpoint);
},
extend: [light({configureReporting: true})],
},
{
zigbeeModel: ['Bticino Din power consumption module '],
Expand Down
18 changes: 6 additions & 12 deletions src/devices/hampton_bay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as exposes from '../lib/exposes';
import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
import {light} from '../lib/modernExtend';
import {forcePowerSource, light} from '../lib/modernExtend';

const e = exposes.presets;

Expand All @@ -14,20 +13,15 @@ const definitions: Definition[] = [
model: '99432',
vendor: 'Hampton Bay',
description: 'Universal wink enabled white ceiling fan premier remote control',
fromZigbee: extend.light_onoff_brightness().fromZigbee.concat([fz.fan]),
toZigbee: extend.light_onoff_brightness().toZigbee.concat([tz.fan_mode]),
exposes: [e.light_brightness(), e.fan().withModes(['low', 'medium', 'high', 'on', 'smart'])],
fromZigbee: [fz.fan],
toZigbee: [tz.fan_mode],
exposes: [e.fan().withModes(['low', 'medium', 'high', 'on', 'smart'])],
meta: {disableDefaultResponse: true},
extend: [light({configureReporting: true}), forcePowerSource({powerSource: 'Mains (single phase)'})],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genLevelCtrl', 'hvacFanCtrl']);
await reporting.onOff(endpoint);
await reporting.brightness(endpoint);
await reporting.bind(endpoint, coordinatorEndpoint, ['hvacFanCtrl']);
await reporting.fanMode(endpoint);

// Has Unknown power source, force it here.
device.powerSource = 'Mains (single phase)';
device.save();
},
},
{
Expand Down
69 changes: 16 additions & 53 deletions src/devices/legrand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
import * as ota from '../lib/ota';
import {tzLegrand, fzLegrand, readInitialBatteryState, _067776, legrandOptions} from '../lib/legrand';
import {deviceEndpoints, light} from '../lib/modernExtend';
const e = exposes.presets;
const ea = exposes.access;

Expand Down Expand Up @@ -284,12 +285,9 @@ const definitions: Definition[] = [
vendor: 'Legrand',
description: 'Wired switch without neutral',
ota: ota.zigbeeOTA,
fromZigbee: [fz.brightness, fz.identify, fz.on_off, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01,
fz.power_on_behavior],
toZigbee: [tz.light_onoff_brightness, tzLegrand.led_mode, tz.legrand_device_mode,
tz.legrand_identify, tz.ballast_config, tz.power_on_behavior],
fromZigbee: [fz.identify, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01],
toZigbee: [tzLegrand.led_mode, tz.legrand_device_mode, tz.legrand_identify, tz.ballast_config],
exposes: [
e.light_brightness(),
e.numeric('ballast_minimum_level', ea.ALL).withValueMin(1).withValueMax(254)
.withDescription('Specifies the minimum brightness value'),
e.numeric('ballast_maximum_level', ea.ALL).withValueMin(1).withValueMax(254)
Expand All @@ -300,14 +298,11 @@ const definitions: Definition[] = [
.withDescription('Enables the LED when the light is turned off, allowing to see the switch in the dark'),
e.binary('led_if_on', ea.ALL, 'ON', 'OFF')
.withDescription('Enables the LED when the light is turned on'),
e.power_on_behavior(),
],
extend: [light({configureReporting: true})],
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genOnOff', 'genLevelCtrl', 'genBinaryInput', 'lightingBallastCfg']);
await reporting.onOff(endpoint);
await reporting.brightness(endpoint);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genBinaryInput', 'lightingBallastCfg']);
},
},
{
Expand All @@ -316,12 +311,9 @@ const definitions: Definition[] = [
vendor: 'Legrand',
description: 'Wired switch without neutral',
ota: ota.zigbeeOTA,
fromZigbee: [fz.brightness, fz.identify, fz.on_off, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01,
fz.power_on_behavior],
toZigbee: [tz.light_onoff_brightness, tzLegrand.led_mode, tz.legrand_device_mode,
tz.legrand_identify, tz.ballast_config, tz.power_on_behavior],
fromZigbee: [fz.identify, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01],
toZigbee: [tzLegrand.led_mode, tz.legrand_device_mode, tz.legrand_identify, tz.ballast_config],
exposes: [
e.light_brightness(),
e.numeric('ballast_minimum_level', ea.ALL).withValueMin(1).withValueMax(254)
.withDescription('Specifies the minimum brightness value'),
e.numeric('ballast_maximum_level', ea.ALL).withValueMin(1).withValueMax(254)
Expand All @@ -332,14 +324,11 @@ const definitions: Definition[] = [
.withDescription('Enables the LED when the light is turned off, allowing to see the switch in the dark'),
e.binary('led_if_on', ea.ALL, 'ON', 'OFF')
.withDescription('Enables the LED when the light is turned on'),
e.power_on_behavior(),
],
extend: [light({configureReporting: true})],
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genOnOff', 'genLevelCtrl', 'genBinaryInput', 'lightingBallastCfg']);
await reporting.onOff(endpoint);
await reporting.brightness(endpoint);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genBinaryInput', 'lightingBallastCfg']);
},
},
{
Expand Down Expand Up @@ -552,14 +541,9 @@ const definitions: Definition[] = [
vendor: 'Legrand',
description: 'Double wired switch with neutral',
ota: ota.zigbeeOTA,
meta: {multiEndpoint: true},
fromZigbee: [fz.brightness, fz.identify, fz.on_off, fz.legrand_binary_input_on_off, fz.lighting_ballast_configuration,
fzLegrand.cluster_fc01, fz.power_on_behavior],
toZigbee: [tz.light_onoff_brightness, tz.legrand_identify, tz.legrand_device_mode, tz.on_off, tzLegrand.led_mode,
tz.ballast_config, tz.power_on_behavior],
fromZigbee: [fz.identify, fz.legrand_binary_input_on_off, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01],
toZigbee: [tz.legrand_identify, tz.legrand_device_mode, tzLegrand.led_mode, tz.ballast_config],
exposes: [
e.light_brightness().withEndpoint('left'),
e.light_brightness().withEndpoint('right'),
e.numeric('ballast_minimum_level', ea.ALL).withValueMin(1).withValueMax(254)
.withDescription('Specifies the minimum brightness value').withEndpoint('left'),
e.numeric('ballast_maximum_level', ea.ALL).withValueMin(1).withValueMax(254)
Expand All @@ -576,22 +560,8 @@ const definitions: Definition[] = [
.withDescription('Enables the LED when the light is turned off, allowing to see the switch in the dark'),
e.binary('led_if_on', ea.ALL, 'ON', 'OFF')
.withDescription('Enables the LED when the light is turned on'),
e.power_on_behavior(),
],
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpointLeft = device.getEndpoint(2);
await reporting.bind(endpointLeft, coordinatorEndpoint, ['genOnOff', 'genBinaryInput', 'lightingBallastCfg']);
await reporting.brightness(endpointLeft);
await reporting.onOff(endpointLeft);
const endpointRight = device.getEndpoint(1);
await reporting.bind(endpointRight, coordinatorEndpoint, ['genOnOff', 'genBinaryInput', 'lightingBallastCfg']);
await reporting.brightness(endpointRight);
await reporting.onOff(endpointRight);
},
endpoint: (device) => {
return {left: 2, right: 1};
},
extend: [deviceEndpoints({endpoints: {'left': 2, 'right': 1}}), light({configureReporting: true, endpointNames: ['left', 'right']})],
},
{
zigbeeModel: [' Mobile outlet\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000'],
Expand Down Expand Up @@ -639,12 +609,9 @@ const definitions: Definition[] = [
model: 'WNAL50/WNRL50',
vendor: 'Legrand',
description: 'Smart dimmer switch with Netatmo',
fromZigbee: [fz.brightness, fz.identify, fz.on_off, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01,
fz.power_on_behavior],
toZigbee: [tz.light_onoff_brightness, tzLegrand.led_mode, tz.legrand_device_mode, tz.legrand_identify,
tz.ballast_config, tz.power_on_behavior],
fromZigbee: [fz.identify, fz.lighting_ballast_configuration, fzLegrand.cluster_fc01],
toZigbee: [tzLegrand.led_mode, tz.legrand_device_mode, tz.legrand_identify, tz.ballast_config],
exposes: [
e.light_brightness(),
e.numeric('ballast_minimum_level', ea.ALL).withValueMin(1).withValueMax(254)
.withDescription('Specifies the minimum brightness value'),
e.numeric('ballast_maximum_level', ea.ALL).withValueMin(1).withValueMax(254)
Expand All @@ -655,14 +622,11 @@ const definitions: Definition[] = [
.withDescription('Enables the LED when the light is turned off, allowing to see the switch in the dark'),
e.binary('led_if_on', ea.ALL, 'ON', 'OFF')
.withDescription('Enables the LED when the light is turned on'),
e.power_on_behavior(),
],
extend: [light({configureReporting: true})],
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genOnOff', 'genLevelCtrl', 'genBinaryInput', 'lightingBallastCfg']);
await reporting.onOff(endpoint);
await reporting.brightness(endpoint);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genBinaryInput', 'lightingBallastCfg']);
},
},
{
Expand All @@ -680,7 +644,6 @@ const definitions: Definition[] = [
],
onEvent: readInitialBatteryState,
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genIdentify', 'genOnOff', 'genLevelCtrl']);
},
Expand Down
22 changes: 2 additions & 20 deletions src/devices/micromatic.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
import {Definition} from '../lib/types';
import fz from '../converters/fromZigbee';
import * as exposes from '../lib/exposes';
import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
const e = exposes.presets;
import {electricityMeter, light} from '../lib/modernExtend';

const definitions: Definition[] = [
{
zigbeeModel: ['SZ1000'],
model: 'ZB250',
vendor: 'Micro Matic Norge AS',
description: 'Zigbee dimmer for LED',
fromZigbee: extend.light_onoff_brightness().fromZigbee.concat([fz.electrical_measurement, fz.metering]),
toZigbee: extend.light_onoff_brightness().toZigbee,
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genLevelCtrl', 'haElectricalMeasurement', 'seMetering']);
await reporting.brightness(endpoint);
await reporting.readEletricalMeasurementMultiplierDivisors(endpoint);
await reporting.readMeteringMultiplierDivisor(endpoint);
await reporting.rmsVoltage(endpoint, {min: 10, change: 20}); // Voltage - Min change of 2V
await reporting.rmsCurrent(endpoint, {min: 10, change: 10}); // A - z2m displays only the first decimals, change of 10 / 0,01A
await reporting.activePower(endpoint, {min: 10, change: 15}); // W - Min change of 1,5W
await reporting.currentSummDelivered(endpoint, {min: 300}); // Report KWH every 5min
},
exposes: [e.light_brightness(), e.power(), e.current(), e.voltage(), e.energy()],
extend: [light({configureReporting: true}), electricityMeter()],
},
];

Expand Down
45 changes: 9 additions & 36 deletions src/devices/robb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as exposes from '../lib/exposes';
import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import * as reporting from '../lib/reporting';
import extend from '../lib/extend';
import {deviceEndpoints, light, onOff} from '../lib/modernExtend';
import {deviceEndpoints, electricityMeter, light, onOff} from '../lib/modernExtend';

const e = exposes.presets;

Expand Down Expand Up @@ -68,24 +67,10 @@ const definitions: Definition[] = [
model: 'ROB_200-011-0',
vendor: 'ROBB',
description: 'ZigBee AC phase-cut dimmer',
fromZigbee: extend.light_onoff_brightness().fromZigbee.concat([fz.electrical_measurement, fz.metering, fz.ignore_genOta]),
toZigbee: extend.light_onoff_brightness().toZigbee,
exposes: [...extend.light_onoff_brightness({noConfigure: true}).exposes, e.power(), e.voltage(), e.energy(), e.current()],
configure: async (device, coordinatorEndpoint, logger) => {
await extend.light_onoff_brightness().configure(device, coordinatorEndpoint, logger);
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genLevelCtrl', 'haElectricalMeasurement', 'seMetering']);
await reporting.onOff(endpoint);
await reporting.activePower(endpoint);
await reporting.readMeteringMultiplierDivisor(endpoint);
await reporting.rmsVoltage(endpoint);
await reporting.rmsCurrent(endpoint);
endpoint.saveClusterAttributeKeyValue('haElectricalMeasurement', {
acVoltageMultiplier: 1, acVoltageDivisor: 10,
acCurrentMultiplier: 1, acCurrentDivisor: 1000,
acPowerMultiplier: 1, acPowerDivisor: 10,
});
},
extend: [
light({configureReporting: true}),
electricityMeter({current: {divisor: 1000}, voltage: {divisor: 10}, power: {divisor: 10}}),
],
},
{
zigbeeModel: ['ROB_200-003-0'],
Expand Down Expand Up @@ -113,23 +98,11 @@ const definitions: Definition[] = [
model: 'ROB_200-014-0',
vendor: 'ROBB',
description: 'ZigBee AC phase-cut rotary dimmer',
fromZigbee: extend.light_onoff_brightness().fromZigbee.concat([fz.electrical_measurement, fz.metering, fz.ignore_genOta]),
toZigbee: extend.light_onoff_brightness().toZigbee,
exposes: [e.light_brightness(), e.power(), e.voltage(), e.current(), e.energy()],
extend: [
light({configureReporting: true}),
electricityMeter(),
],
whiteLabel: [{vendor: 'YPHIX', model: '50208695'}, {vendor: 'Samotech', model: 'SM311'}],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
const binds = ['genOnOff', 'genLevelCtrl', 'haElectricalMeasurement', 'seMetering'];
await reporting.bind(endpoint, coordinatorEndpoint, binds);
await reporting.onOff(endpoint);
await reporting.brightness(endpoint);
await reporting.readEletricalMeasurementMultiplierDivisors(endpoint);
await reporting.activePower(endpoint);
await reporting.rmsCurrent(endpoint, {min: 10, change: 10});
await reporting.rmsVoltage(endpoint, {min: 10});
await reporting.readMeteringMultiplierDivisor(endpoint);
await reporting.currentSummDelivered(endpoint);
},
},
{
zigbeeModel: ['ZG2833K8_EU05', 'ROB_200-007-0'],
Expand Down

0 comments on commit ed7ed68

Please sign in to comment.