Skip to content

Commit

Permalink
feat: move voc_battery to modernExtend
Browse files Browse the repository at this point in the history
  • Loading branch information
sjorge committed Jun 29, 2024
1 parent 38767e8 commit 995a05a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/devices/develco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {Zcl} from 'zigbee-herdsman';
import fz from '../converters/fromZigbee';
import tz from '../converters/toZigbee';
import * as constants from '../lib/constants';
import {develcoModernExtend} from '../lib/develco';
import * as exposes from '../lib/exposes';
import {logger} from '../lib/logger';
import {develcoModernExtend} from '../lib/develco';
import {illuminance} from '../lib/modernExtend';
import * as ota from '../lib/ota';
import * as reporting from '../lib/reporting';
Expand Down Expand Up @@ -130,21 +130,6 @@ const develco = {
return result;
},
} satisfies Fz.Converter,
voc_battery: {
cluster: 'genPowerCfg',
type: ['attributeReport', 'readResponse'],
convert: async (model, msg, publish, options, meta) => {
/*
* Per the technical documentation for AQSZB-110:
* To detect low battery the system can monitor the "BatteryVoltage" by setting up a reporting interval of every 12 hour.
* When a voltage of 2.5V is measured the battery should be replaced.
* Low batt LED indication–RED LED will blink twice every 60 second.
*/
const result = await fz.battery.convert(model, msg, publish, options, meta);
if (result) result.battery_low = result.voltage <= 2500;
return result;
},
} satisfies Fz.Converter,
led_control: {
cluster: 'genBasic',
type: ['attributeReport', 'readResponse'],
Expand Down Expand Up @@ -729,9 +714,13 @@ const definitions: Definition[] = [
fromZigbee: [fz.battery, develco.fz.temperature, fz.humidity],
toZigbee: [],
ota: ota.zigbeeOTA,
exposes: [e.battery(), e.battery_low(), e.temperature(), e.humidity()],
exposes: [e.battery(), e.temperature(), e.humidity()],
meta: {battery: {voltageToPercentage: '3V_2500_3200'}},
extend: [develcoModernExtend.addCustomClusterManuSpecificDevelcoGenBasic(), develcoModernExtend.readGenBasicPrimaryVersions()],
extend: [
develcoModernExtend.addCustomClusterManuSpecificDevelcoGenBasic(),
develcoModernExtend.readGenBasicPrimaryVersions(),
develcoModernExtend.batteryLowAA(),
],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(38);
await reporting.bind(endpoint, coordinatorEndpoint, ['msTemperatureMeasurement', 'msRelativeHumidity', 'genPowerCfg']);
Expand Down Expand Up @@ -819,16 +808,17 @@ const definitions: Definition[] = [
model: 'AQSZB-110',
vendor: 'Develco',
description: 'Air quality sensor',
fromZigbee: [develco.fz.voc_battery, develco.fz.temperature, fz.humidity],
toZigbee: [],
ota: ota.zigbeeOTA,
exposes: [e.temperature(), e.humidity(), e.battery(), e.battery_low()],
fromZigbee: [develco.fz.temperature, fz.humidity],
toZigbee: [],
exposes: [e.temperature(), e.humidity(), e.battery()],
extend: [
develcoModernExtend.addCustomClusterManuSpecificDevelcoGenBasic(),
develcoModernExtend.addCustomClusterManuSpecificDevelcoAirQuality(),
develcoModernExtend.readGenBasicPrimaryVersions(),
develcoModernExtend.voc(),
develcoModernExtend.airQuality(),
develcoModernExtend.batteryLowAA(),
],
meta: {battery: {voltageToPercentage: '3V_2500'}},
configure: async (device, coordinatorEndpoint) => {
Expand Down
30 changes: 30 additions & 0 deletions src/lib/develco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,36 @@ export const develcoModernExtend = {
},
];

return {exposes: [expose], fromZigbee, isModernExtend: true};
},
batteryLowAA: (): ModernExtend => {
/*
* Per the technical documentation for AQSZB-110:
* To detect low battery the system can monitor the "BatteryVoltage" by setting up a reporting interval of every 12 hour.
* When a voltage of 2.5V is measured the battery should be replaced.
* Low batt LED indication–RED LED will blink twice every 60 second.
*
* Similar notes found in other 2x AA powered Develco devices like HMSZB-110 and MOSZB-140
*/
const clusterName = 'genPowerCfg';
const attributeName = 'BatteryVoltage';
const propertyName = 'battery_low';

const expose = e.battery_low();

const fromZigbee: Fz.Converter[] = [
{
cluster: clusterName,
type: ['attributeReport', 'readResponse'],
convert: (model, msg, publish, options, meta) => {
if (msg.data.hasOwnProperty(attributeName) && msg.data[attributeName] < 255) {
const voltage = parseInt(msg.data[attributeName]);
return {[propertyName]: voltage <= 25};
}
},
},
];

return {exposes: [expose], fromZigbee, isModernExtend: true};
},
};

0 comments on commit 995a05a

Please sign in to comment.