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

Feat poll profalux remote battery #8877

Merged
merged 6 commits into from
Feb 24, 2025
Merged
Changes from 5 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
27 changes: 25 additions & 2 deletions src/devices/profalux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@ import fz from "../converters/fromZigbee";
import tz from "../converters/toZigbee";
import * as exposes from "../lib/exposes";
import {logger} from "../lib/logger";
import * as m from "../lib/modernExtend";
import * as reporting from "../lib/reporting";
import type {DefinitionWithExtend} from "../lib/types";
import * as globalStore from "../lib/store";
import type {DefinitionWithExtend, KeyValue, OnEventData, OnEventType, Zh} from "../lib/types";

const NS = "zhc:profalux";
const e = exposes.presets;
const ea = exposes.access;

const DAY = 86400000;

async function onEventBatteryPoll(type: OnEventType, data: OnEventData, device: Zh.Device, options: KeyValue) {
if (type === "message" && Date.now() > globalStore.getValue(device, "battery_nextpoll", 0)) {
const endpoint = device.getEndpoint(2);
logger.debug(`${device.ieeeAddr}: polling battery`, NS);
globalStore.putValue(device, "battery_nextpoll", Date.now() + DAY);
await endpoint.read("genPowerCfg", ["batteryVoltage"]);
}
}

export const definitions: DefinitionWithExtend[] = [
{
zigbeeModel: ["MAI-ZTS"],
Expand All @@ -30,7 +43,7 @@ export const definitions: DefinitionWithExtend[] = [
// using cluster 0x102 "closuresWindowCovering", so use that.
// 06/10/20/30 is the torque in Nm. 20/30 have not been seen but
// extracted from Profalux documentation. C/F seems to be a version. D
// and E have not been seen in the while. I suspect A is the earlier
// and E have not been seen in the wild. I suspect A is the earlier
// model covered below, NSAV061.
zigbeeModel: [
"MOT-C1Z06C\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
Expand Down Expand Up @@ -113,6 +126,11 @@ export const definitions: DefinitionWithExtend[] = [
fromZigbee: [],
toZigbee: [],
exposes: [],
extend: [
m.battery({voltage: true, voltageToPercentage: {min: 2200, max: 3100}, percentageReporting: false}),
m.forcePowerSource({powerSource: "Battery"}),
],
onEvent: onEventBatteryPoll,
},
{
// Newer remotes. These expose a bunch of things but they are bound to
Expand Down Expand Up @@ -148,5 +166,10 @@ export const definitions: DefinitionWithExtend[] = [
fromZigbee: [],
toZigbee: [],
exposes: [],
extend: [
m.battery({voltage: true, voltageToPercentage: {min: 2200, max: 3100}, percentageReporting: false}),
m.forcePowerSource({powerSource: "Battery"}),
],
onEvent: onEventBatteryPoll,
},
];