diff --git a/src/devices/sonoff.ts b/src/devices/sonoff.ts index e00bd9ffc993e..be9d9e3012f03 100644 --- a/src/devices/sonoff.ts +++ b/src/devices/sonoff.ts @@ -8,6 +8,7 @@ import * as reporting from '../lib/reporting'; import { binary, enumLookup, forcePowerSource, numeric, onOff, customTimeResponse, battery, ota, deviceAddCustomCluster, + temperature, humidity, bindCluster, } from '../lib/modernExtend'; import {Definition, Fz, KeyValue, KeyValueAny, ModernExtend, Tz} from '../lib/types'; import * as utils from '../lib/utils'; @@ -622,19 +623,13 @@ const definitions: Definition[] = [ model: 'SNZB-02D', vendor: 'SONOFF', description: 'Temperature and humidity sensor with screen', - exposes: [e.battery(), e.temperature(), e.humidity()], - fromZigbee: [fz.temperature, fz.humidity, fz.battery], - toZigbee: [], - configure: async (device, coordinatorEndpoint) => { - const endpoint = device.getEndpoint(1); - const bindClusters = ['msTemperatureMeasurement', 'msRelativeHumidity', 'genPowerCfg']; - await reporting.bind(endpoint, coordinatorEndpoint, bindClusters); - await reporting.temperature(endpoint, {min: 30, max: constants.repInterval.MINUTES_5, change: 20}); - await reporting.humidity(endpoint, {min: 30, max: constants.repInterval.MINUTES_5, change: 100}); - await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200}); - device.powerSource = 'Battery'; - device.save(); - }, + extend: [ + forcePowerSource({powerSource: 'Battery'}), + battery({percentage: true}), + temperature(), + humidity(), + bindCluster({cluster: 'genPollCtrl', clusterType: 'input'}), + ], }, { fingerprint: [ @@ -737,22 +732,12 @@ const definitions: Definition[] = [ model: 'SNZB-02P', vendor: 'SONOFF', description: 'Temperature and humidity sensor', - exposes: [e.battery(), e.temperature(), e.humidity(), e.battery_low(), e.battery_voltage()], - fromZigbee: [fz.temperature, fz.humidity, fz.battery], - configure: async (device, coordinatorEndpoint) => { - try { - const endpoint = device.getEndpoint(1); - const bindClusters = ['msTemperatureMeasurement', 'msRelativeHumidity', 'genPowerCfg']; - await reporting.bind(endpoint, coordinatorEndpoint, bindClusters); - await reporting.temperature(endpoint, {min: 30, max: constants.repInterval.MINUTES_5, change: 20}); - await reporting.humidity(endpoint, {min: 30, max: constants.repInterval.MINUTES_5, change: 100}); - await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200}); - } catch (e) {/* Not required for all: https://github.com/Koenkk/zigbee2mqtt/issues/5562 */ - logger.error(`Configure failed: ${e}`, NS); - } - }, extend: [ - ota(), + forcePowerSource({powerSource: 'Battery'}), + battery({percentage: true}), + temperature(), + humidity(), + bindCluster({cluster: 'genPollCtrl', clusterType: 'input'}), ], }, { diff --git a/test/sonoff.test.ts b/test/sonoff.test.ts index 6895f4ec9b60f..8052da3663e78 100644 --- a/test/sonoff.test.ts +++ b/test/sonoff.test.ts @@ -1,5 +1,5 @@ import * as index from "../src/index"; -import {Definition, Fz, KeyValueAny, Tz, Zh} from "../lib/types"; +import {Definition, Fz, KeyValueAny, Tz, Zh} from "../src/lib/types"; import {Endpoint, Entity} from "zigbee-herdsman/dist/controller/model"; interface State {