Skip to content

Commit 770439c

Browse files
authored
fix: Universal Electronics Inc XHS2-UE: fix battery voltage curve (#12609)
1 parent 48c97f1 commit 770439c

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/devices/universal_electronics_inc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const definitions: DefinitionWithExtend[] = [
3232
description: "Magnetic door & window contact sensor",
3333
fromZigbee: [fz.ias_contact_alarm_1, fz.temperature, fz.battery],
3434
toZigbee: [],
35-
meta: {battery: {voltageToPercentage: "3V_2100"}},
35+
meta: {battery: {voltageToPercentage: {min: 2500, max: 2800}}},
3636
configure: async (device, coordinatorEndpoint) => {
3737
const endpoint = device.getEndpoint(1);
3838
await reporting.bind(endpoint, coordinatorEndpoint, ["msTemperatureMeasurement", "genPowerCfg"]);

test/fromZigbee.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {describe, expect, it} from "vitest";
22
import {definitions as develcoDefinitions} from "../src/devices/develco";
3-
import {fromZigbee} from "../src/index";
3+
import {findByDevice, fromZigbee} from "../src/index";
44
import {mockDevice} from "./utils";
55

66
describe("converters/fromZigbee", () => {
@@ -221,6 +221,37 @@ describe("converters/fromZigbee", () => {
221221
});
222222
});
223223

224+
it("XHS2-UE uses voltage curve instead of stale reported battery percentage", async () => {
225+
const definition = await findByDevice(mockDevice({modelID: "URC4460BC0-X-R", endpoints: []}));
226+
227+
const payload = fromZigbee.battery.convert(
228+
definition,
229+
{
230+
data: {
231+
batteryVoltage: 28,
232+
batteryPercentageRemaining: 54,
233+
},
234+
endpoint: null,
235+
device: null,
236+
meta: null,
237+
groupID: null,
238+
type: "attributeReport",
239+
cluster: "genPowerCfg",
240+
linkquality: 0,
241+
},
242+
null,
243+
{},
244+
{
245+
meta: {},
246+
}.meta,
247+
);
248+
249+
expect(payload).toStrictEqual({
250+
battery: 100,
251+
voltage: 2800,
252+
});
253+
});
254+
224255
describe("command_step_color_temperature", () => {
225256
const makeMsg = (stepmode: number, stepsize: number, transtime?: number) => ({
226257
data: {stepmode, stepsize, ...(transtime !== undefined ? {transtime} : {})},

0 commit comments

Comments
 (0)