Skip to content

Commit 2b8301d

Browse files
authored
feat: Manage exit/entry delay for IAS ACE devices (#10699)
1 parent a601d46 commit 2b8301d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/converters/toZigbee.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,21 @@ export const arm_mode: Tz.Converter = {
292292
panelStatus = mode !== 0 && mode !== 4 ? 0x80 : 0x00;
293293
}
294294

295+
let secondsRemain = 0;
296+
let delayUntil = 0;
297+
if ((mode === 4 || mode === 5) && value.delay != null) {
298+
utils.assertNumber(value.delay, "delay");
299+
if (!utils.isInRange(0, constants.iasMaxSecondsRemain, value.delay)) {
300+
throw new Error(`Invalid delay value: ${value.delay} (expected ${0} to ${constants.iasMaxSecondsRemain})`);
301+
}
302+
303+
secondsRemain = Math.round(value.delay);
304+
delayUntil = performance.now() + value.delay * 1000;
305+
}
306+
295307
globalStore.putValue(entity, "panelStatus", panelStatus);
296-
const payload = {panelstatus: panelStatus, secondsremain: 0, audiblenotif: 0, alarmstatus: 0};
308+
globalStore.putValue(entity, "delayUntil", delayUntil);
309+
const payload = {panelstatus: panelStatus, secondsremain: secondsRemain, audiblenotif: 0, alarmstatus: 0};
297310
await entity.commandResponse("ssIasAce", "panelStatusChanged", payload);
298311
},
299312
};

src/lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ export const armNotification = {
288288
6: "already_disarmed",
289289
};
290290

291+
export const iasMaxSecondsRemain = 255;
292+
291293
// ID's from ZCL mapped to ha names where appropriate
292294
// https://github.com/home-assistant/core/pull/47720
293295
export const ColorMode = {

src/lib/modernExtend.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,11 @@ export function iasGetPanelStatusResponse(): ModernExtend {
737737
type: ["commandGetPanelStatus"],
738738
convert: (model, msg, publish, options, meta) => {
739739
if (globalStore.hasValue(msg.endpoint, "panelStatus")) {
740+
const delayUntil = globalStore.getValue(msg.endpoint, "delayUntil", 0);
741+
const secondsRemain = delayUntil > 0 ? Math.round(Math.max(0, delayUntil - performance.now()) / 1000) : 0;
740742
const payload = {
741743
panelstatus: globalStore.getValue(msg.endpoint, "panelStatus"),
742-
secondsremain: 0x00,
744+
secondsremain: Math.min(secondsRemain, constants.iasMaxSecondsRemain),
743745
audiblenotif: 0x00,
744746
alarmstatus: 0x00,
745747
};

0 commit comments

Comments
 (0)