homebridge-securitysystem 0.0.1-matter
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +46 -0
- package/.github/ISSUE_TEMPLATE/feature-request.yml +17 -0
- package/.github/ISSUE_TEMPLATE/questions-answers.yml +40 -0
- package/.github/demo.jpg +0 -0
- package/.github/dependabot.yml +19 -0
- package/.github/release.yml +36 -0
- package/.github/workflows/build-package.yml +49 -0
- package/.github/workflows/bump-version.yml +59 -0
- package/.github/workflows/dependency-review.yml +26 -0
- package/.github/workflows/publish.yml +155 -0
- package/.github/workflows/stale-activity.yml +27 -0
- package/AGENTS.md +247 -0
- package/CHANGELOG.md +572 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +5 -0
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/SECURITY.md +12 -0
- package/config.schema.json +934 -0
- package/dist/conditions/already-triggered-condition.d.ts +10 -0
- package/dist/conditions/already-triggered-condition.js +22 -0
- package/dist/conditions/already-triggered-condition.js.map +1 -0
- package/dist/conditions/arming-in-progress-condition.d.ts +10 -0
- package/dist/conditions/arming-in-progress-condition.js +21 -0
- package/dist/conditions/arming-in-progress-condition.js.map +1 -0
- package/dist/conditions/arming-lock-condition.d.ts +10 -0
- package/dist/conditions/arming-lock-condition.js +43 -0
- package/dist/conditions/arming-lock-condition.js.map +1 -0
- package/dist/conditions/condition.d.ts +22 -0
- package/dist/conditions/condition.js +19 -0
- package/dist/conditions/condition.js.map +1 -0
- package/dist/conditions/double-knock-condition.d.ts +24 -0
- package/dist/conditions/double-knock-condition.js +73 -0
- package/dist/conditions/double-knock-condition.js.map +1 -0
- package/dist/conditions/not-armed-condition.d.ts +10 -0
- package/dist/conditions/not-armed-condition.js +26 -0
- package/dist/conditions/not-armed-condition.js.map +1 -0
- package/dist/conditions/trigger-already-running-condition.d.ts +10 -0
- package/dist/conditions/trigger-already-running-condition.js +21 -0
- package/dist/conditions/trigger-already-running-condition.js.map +1 -0
- package/dist/constants/default-constant.d.ts +24 -0
- package/dist/constants/default-constant.js +27 -0
- package/dist/constants/default-constant.js.map +1 -0
- package/dist/constants/homekit-constant.d.ts +2 -0
- package/dist/constants/homekit-constant.js +3 -0
- package/dist/constants/homekit-constant.js.map +1 -0
- package/dist/constants/matter-constant.d.ts +21 -0
- package/dist/constants/matter-constant.js +61 -0
- package/dist/constants/matter-constant.js.map +1 -0
- package/dist/handlers/sensor-handler.d.ts +24 -0
- package/dist/handlers/sensor-handler.js +63 -0
- package/dist/handlers/sensor-handler.js.map +1 -0
- package/dist/handlers/state-handler.d.ts +49 -0
- package/dist/handlers/state-handler.js +204 -0
- package/dist/handlers/state-handler.js.map +1 -0
- package/dist/handlers/switch-handler.d.ts +28 -0
- package/dist/handlers/switch-handler.js +95 -0
- package/dist/handlers/switch-handler.js.map +1 -0
- package/dist/handlers/trip-handler.d.ts +44 -0
- package/dist/handlers/trip-handler.js +156 -0
- package/dist/handlers/trip-handler.js.map +1 -0
- package/dist/homekit/homekit-registrar.d.ts +12 -0
- package/dist/homekit/homekit-registrar.js +23 -0
- package/dist/homekit/homekit-registrar.js.map +1 -0
- package/dist/homekit/service-factory.d.ts +12 -0
- package/dist/homekit/service-factory.js +24 -0
- package/dist/homekit/service-factory.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/condition-context-interface.d.ts +14 -0
- package/dist/interfaces/condition-context-interface.js +2 -0
- package/dist/interfaces/condition-context-interface.js.map +1 -0
- package/dist/interfaces/hap-types-interface.d.ts +9 -0
- package/dist/interfaces/hap-types-interface.js +2 -0
- package/dist/interfaces/hap-types-interface.js.map +1 -0
- package/dist/interfaces/mqtt-status-payload-interface.d.ts +6 -0
- package/dist/interfaces/mqtt-status-payload-interface.js +2 -0
- package/dist/interfaces/mqtt-status-payload-interface.js.map +1 -0
- package/dist/interfaces/options-interface.d.ts +87 -0
- package/dist/interfaces/options-interface.js +2 -0
- package/dist/interfaces/options-interface.js.map +1 -0
- package/dist/interfaces/persisted-state-interface.d.ts +6 -0
- package/dist/interfaces/persisted-state-interface.js +2 -0
- package/dist/interfaces/persisted-state-interface.js.map +1 -0
- package/dist/interfaces/service-registry-interface.d.ts +10 -0
- package/dist/interfaces/service-registry-interface.js +2 -0
- package/dist/interfaces/service-registry-interface.js.map +1 -0
- package/dist/interfaces/system-state-interface.d.ts +22 -0
- package/dist/interfaces/system-state-interface.js +2 -0
- package/dist/interfaces/system-state-interface.js.map +1 -0
- package/dist/schemas/arming-lock-schema.d.ts +10 -0
- package/dist/schemas/arming-lock-schema.js +12 -0
- package/dist/schemas/arming-lock-schema.js.map +1 -0
- package/dist/schemas/error-schema.d.ts +4 -0
- package/dist/schemas/error-schema.js +7 -0
- package/dist/schemas/error-schema.js.map +1 -0
- package/dist/schemas/mode-request-schema.d.ts +10 -0
- package/dist/schemas/mode-request-schema.js +18 -0
- package/dist/schemas/mode-request-schema.js.map +1 -0
- package/dist/schemas/status-response-schema.d.ts +7 -0
- package/dist/schemas/status-response-schema.js +10 -0
- package/dist/schemas/status-response-schema.js.map +1 -0
- package/dist/schemas/trip-mode-request-schema.d.ts +9 -0
- package/dist/schemas/trip-mode-request-schema.js +24 -0
- package/dist/schemas/trip-mode-request-schema.js.map +1 -0
- package/dist/security-system-platform.d.ts +19 -0
- package/dist/security-system-platform.js +56 -0
- package/dist/security-system-platform.js.map +1 -0
- package/dist/security-system.d.ts +28 -0
- package/dist/security-system.js +169 -0
- package/dist/security-system.js.map +1 -0
- package/dist/services/command-service.d.ts +16 -0
- package/dist/services/command-service.js +65 -0
- package/dist/services/command-service.js.map +1 -0
- package/dist/services/configuration-service.d.ts +24 -0
- package/dist/services/configuration-service.js +189 -0
- package/dist/services/configuration-service.js.map +1 -0
- package/dist/services/event-bus-service.d.ts +12 -0
- package/dist/services/event-bus-service.js +17 -0
- package/dist/services/event-bus-service.js.map +1 -0
- package/dist/services/matter-service.d.ts +69 -0
- package/dist/services/matter-service.js +363 -0
- package/dist/services/matter-service.js.map +1 -0
- package/dist/services/mqtt-service.d.ts +16 -0
- package/dist/services/mqtt-service.js +97 -0
- package/dist/services/mqtt-service.js.map +1 -0
- package/dist/services/server-service.d.ts +28 -0
- package/dist/services/server-service.js +275 -0
- package/dist/services/server-service.js.map +1 -0
- package/dist/services/storage-service.d.ts +14 -0
- package/dist/services/storage-service.js +70 -0
- package/dist/services/storage-service.js.map +1 -0
- package/dist/services/webhook-service.d.ts +16 -0
- package/dist/services/webhook-service.js +68 -0
- package/dist/services/webhook-service.js.map +1 -0
- package/dist/tests/conditions.test.d.ts +1 -0
- package/dist/tests/conditions.test.js +175 -0
- package/dist/tests/conditions.test.js.map +1 -0
- package/dist/tests/matter-service.test.d.ts +1 -0
- package/dist/tests/matter-service.test.js +475 -0
- package/dist/tests/matter-service.test.js.map +1 -0
- package/dist/tests/mqtt-service.test.d.ts +1 -0
- package/dist/tests/mqtt-service.test.js +168 -0
- package/dist/tests/mqtt-service.test.js.map +1 -0
- package/dist/tests/sensor-handler.test.d.ts +1 -0
- package/dist/tests/sensor-handler.test.js +87 -0
- package/dist/tests/sensor-handler.test.js.map +1 -0
- package/dist/tests/server-service.test.d.ts +1 -0
- package/dist/tests/server-service.test.js +188 -0
- package/dist/tests/server-service.test.js.map +1 -0
- package/dist/tests/state-handler.test.d.ts +1 -0
- package/dist/tests/state-handler.test.js +276 -0
- package/dist/tests/state-handler.test.js.map +1 -0
- package/dist/tests/switch-handler.test.d.ts +1 -0
- package/dist/tests/switch-handler.test.js +186 -0
- package/dist/tests/switch-handler.test.js.map +1 -0
- package/dist/tests/trip-handler.test.d.ts +1 -0
- package/dist/tests/trip-handler.test.js +179 -0
- package/dist/tests/trip-handler.test.js.map +1 -0
- package/dist/timers/timer-manager.d.ts +31 -0
- package/dist/timers/timer-manager.js +118 -0
- package/dist/timers/timer-manager.js.map +1 -0
- package/dist/types/event-payload-map-type.d.ts +15 -0
- package/dist/types/event-payload-map-type.js +2 -0
- package/dist/types/event-payload-map-type.js.map +1 -0
- package/dist/types/event-type.d.ts +44 -0
- package/dist/types/event-type.js +20 -0
- package/dist/types/event-type.js.map +1 -0
- package/dist/types/matter-accessory-key-type.d.ts +7 -0
- package/dist/types/matter-accessory-key-type.js +2 -0
- package/dist/types/matter-accessory-key-type.js.map +1 -0
- package/dist/types/mode-type.d.ts +4 -0
- package/dist/types/mode-type.js +2 -0
- package/dist/types/mode-type.js.map +1 -0
- package/dist/types/origin-type.d.ts +9 -0
- package/dist/types/origin-type.js +11 -0
- package/dist/types/origin-type.js.map +1 -0
- package/dist/types/security-state-type.d.ts +11 -0
- package/dist/types/security-state-type.js +13 -0
- package/dist/types/security-state-type.js.map +1 -0
- package/dist/types/sensor-kind-type.d.ts +2 -0
- package/dist/types/sensor-kind-type.js +2 -0
- package/dist/types/sensor-kind-type.js.map +1 -0
- package/dist/types/service-result-type.d.ts +4 -0
- package/dist/types/service-result-type.js +2 -0
- package/dist/types/service-result-type.js.map +1 -0
- package/dist/utils/arming-util.d.ts +19 -0
- package/dist/utils/arming-util.js +24 -0
- package/dist/utils/arming-util.js.map +1 -0
- package/dist/utils/state-util.d.ts +8 -0
- package/dist/utils/state-util.js +29 -0
- package/dist/utils/state-util.js.map +1 -0
- package/docs/MQTT.md +50 -0
- package/package.json +64 -0
- package/src/@types/homebridge-lib.d.ts +11 -0
- package/src/conditions/already-triggered-condition.ts +24 -0
- package/src/conditions/arming-in-progress-condition.ts +23 -0
- package/src/conditions/arming-lock-condition.ts +50 -0
- package/src/conditions/condition.ts +31 -0
- package/src/conditions/double-knock-condition.ts +84 -0
- package/src/conditions/not-armed-condition.ts +30 -0
- package/src/conditions/trigger-already-running-condition.ts +23 -0
- package/src/constants/default-constant.ts +28 -0
- package/src/constants/homekit-constant.ts +2 -0
- package/src/constants/matter-constant.ts +69 -0
- package/src/handlers/sensor-handler.ts +78 -0
- package/src/handlers/state-handler.ts +257 -0
- package/src/handlers/switch-handler.ts +111 -0
- package/src/handlers/trip-handler.ts +193 -0
- package/src/homekit/homekit-registrar.ts +28 -0
- package/src/homekit/service-factory.ts +35 -0
- package/src/index.ts +9 -0
- package/src/interfaces/condition-context-interface.ts +15 -0
- package/src/interfaces/hap-types-interface.ts +11 -0
- package/src/interfaces/mqtt-status-payload-interface.ts +6 -0
- package/src/interfaces/options-interface.ts +116 -0
- package/src/interfaces/persisted-state-interface.ts +7 -0
- package/src/interfaces/service-registry-interface.ts +11 -0
- package/src/interfaces/system-state-interface.ts +25 -0
- package/src/schemas/arming-lock-schema.ts +12 -0
- package/src/schemas/error-schema.ts +7 -0
- package/src/schemas/mode-request-schema.ts +18 -0
- package/src/schemas/status-response-schema.ts +10 -0
- package/src/schemas/trip-mode-request-schema.ts +24 -0
- package/src/security-system-platform.ts +68 -0
- package/src/security-system.ts +199 -0
- package/src/services/command-service.ts +76 -0
- package/src/services/configuration-service.ts +224 -0
- package/src/services/event-bus-service.ts +21 -0
- package/src/services/matter-service.ts +446 -0
- package/src/services/mqtt-service.ts +123 -0
- package/src/services/server-service.ts +327 -0
- package/src/services/storage-service.ts +80 -0
- package/src/services/webhook-service.ts +77 -0
- package/src/tests/conditions.test.ts +212 -0
- package/src/tests/matter-service.test.ts +610 -0
- package/src/tests/mqtt-service.test.ts +231 -0
- package/src/tests/sensor-handler.test.ts +116 -0
- package/src/tests/server-service.test.ts +238 -0
- package/src/tests/state-handler.test.ts +371 -0
- package/src/tests/switch-handler.test.ts +234 -0
- package/src/tests/trip-handler.test.ts +244 -0
- package/src/timers/timer-manager.ts +141 -0
- package/src/types/event-payload-map-type.ts +25 -0
- package/src/types/event-type.ts +61 -0
- package/src/types/matter-accessory-key-type.ts +33 -0
- package/src/types/mode-type.ts +4 -0
- package/src/types/origin-type.ts +9 -0
- package/src/types/security-state-type.ts +11 -0
- package/src/types/sensor-kind-type.ts +2 -0
- package/src/types/service-result-type.ts +4 -0
- package/src/utils/arming-util.ts +44 -0
- package/src/utils/state-util.ts +32 -0
- package/tsconfig.json +26 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { SecurityState } from '../types/security-state-type.js';
|
|
3
|
+
import { OriginType } from '../types/origin-type.js';
|
|
4
|
+
import type { ConditionContext } from '../interfaces/condition-context-interface.js';
|
|
5
|
+
import type { SystemState } from '../interfaces/system-state-interface.js';
|
|
6
|
+
import type { SecuritySystemOptions } from '../interfaces/options-interface.js';
|
|
7
|
+
import { NotArmedCondition } from '../conditions/not-armed-condition.js';
|
|
8
|
+
import { ArmingInProgressCondition } from '../conditions/arming-in-progress-condition.js';
|
|
9
|
+
import { AlreadyTriggeredCondition } from '../conditions/already-triggered-condition.js';
|
|
10
|
+
import { DoubleKnockCondition } from '../conditions/double-knock-condition.js';
|
|
11
|
+
import { ArmingLockCondition } from '../conditions/arming-lock-condition.js';
|
|
12
|
+
|
|
13
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
function makeState(overrides: Partial<SystemState> = {}): SystemState {
|
|
16
|
+
return {
|
|
17
|
+
currentState: SecurityState.HOME,
|
|
18
|
+
targetState: SecurityState.HOME,
|
|
19
|
+
defaultState: SecurityState.OFF,
|
|
20
|
+
availableTargetStates: [SecurityState.HOME, SecurityState.AWAY, SecurityState.NIGHT, SecurityState.OFF],
|
|
21
|
+
isArming: false,
|
|
22
|
+
isTripping: false,
|
|
23
|
+
isKnocked: false,
|
|
24
|
+
serverAuthenticationAttempts: 0,
|
|
25
|
+
pausedCurrentState: null,
|
|
26
|
+
armingLocks: { global: false, home: false, away: false, night: false },
|
|
27
|
+
modeAwayExtended: false,
|
|
28
|
+
...overrides,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function makeOptions(overrides: Partial<SecuritySystemOptions> = {}): SecuritySystemOptions {
|
|
33
|
+
return {
|
|
34
|
+
overrideOff: false,
|
|
35
|
+
doubleKnock: false,
|
|
36
|
+
doubleKnockSeconds: 90,
|
|
37
|
+
doubleKnockModes: [],
|
|
38
|
+
homeDoubleKnockSeconds: null,
|
|
39
|
+
awayDoubleKnockSeconds: null,
|
|
40
|
+
nightDoubleKnockSeconds: null,
|
|
41
|
+
armingLockSwitch: false,
|
|
42
|
+
armingLockSwitches: false,
|
|
43
|
+
...overrides,
|
|
44
|
+
} as unknown as SecuritySystemOptions;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function makeLog() {
|
|
48
|
+
return { info: vi.fn(), warn: vi.fn(), debug: vi.fn(), error: vi.fn(), success: vi.fn() };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function makeCtx(state: SystemState, options: SecuritySystemOptions, value: boolean, origin = OriginType.REGULAR_SWITCH): ConditionContext {
|
|
52
|
+
return { state, options, value, origin, log: makeLog() as unknown as ConditionContext['log'] };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── ArmingLockCondition ───────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
describe('ArmingLockCondition', () => {
|
|
58
|
+
const cond = new ArmingLockCondition();
|
|
59
|
+
|
|
60
|
+
it('blocks when the global lock is active and arming to an armed mode', () => {
|
|
61
|
+
const state = makeState({ armingLocks: { global: true, home: false, away: false, night: false } });
|
|
62
|
+
expect(cond.evaluate(makeCtx(state, makeOptions({ armingLockSwitch: true }), true))).toBe(true);
|
|
63
|
+
expect(cond.failureReason).toBe('arming is blocked by the global arming lock switch');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('blocks when the matching mode lock is active', () => {
|
|
67
|
+
const state = makeState({ targetState: SecurityState.AWAY, armingLocks: { global: false, home: false, away: true, night: false } });
|
|
68
|
+
expect(cond.evaluate(makeCtx(state, makeOptions({ armingLockSwitches: true }), true))).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('does not block when the lock feature is disabled', () => {
|
|
72
|
+
const state = makeState({ armingLocks: { global: true, home: false, away: false, night: false } });
|
|
73
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), true))).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('does not block disarming', () => {
|
|
77
|
+
const state = makeState({ targetState: SecurityState.OFF, armingLocks: { global: true, home: false, away: false, night: false } });
|
|
78
|
+
expect(cond.evaluate(makeCtx(state, makeOptions({ armingLockSwitch: true }), true))).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('allows when no lock is active', () => {
|
|
82
|
+
const state = makeState();
|
|
83
|
+
expect(cond.evaluate(makeCtx(state, makeOptions({ armingLockSwitch: true }), true))).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ── NotArmedCondition ─────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
describe('NotArmedCondition', () => {
|
|
90
|
+
const cond = new NotArmedCondition();
|
|
91
|
+
|
|
92
|
+
it('blocks when disarmed and override_off is false', () => {
|
|
93
|
+
const state = makeState({ currentState: SecurityState.OFF });
|
|
94
|
+
const opts = makeOptions({ overrideOff: false });
|
|
95
|
+
expect(cond.evaluate(makeCtx(state, opts, true))).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('allows when disarmed but override_off is true', () => {
|
|
99
|
+
const state = makeState({ currentState: SecurityState.OFF });
|
|
100
|
+
const opts = makeOptions({ overrideOff: true });
|
|
101
|
+
expect(cond.evaluate(makeCtx(state, opts, true))).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('allows when disarmed but origin is OVERRIDE_SWITCH', () => {
|
|
105
|
+
const state = makeState({ currentState: SecurityState.OFF });
|
|
106
|
+
const opts = makeOptions({ overrideOff: false });
|
|
107
|
+
expect(cond.evaluate(makeCtx(state, opts, true, OriginType.OVERRIDE_SWITCH))).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('allows when system is armed', () => {
|
|
111
|
+
const state = makeState({ currentState: SecurityState.HOME });
|
|
112
|
+
const opts = makeOptions({ overrideOff: false });
|
|
113
|
+
expect(cond.evaluate(makeCtx(state, opts, true))).toBe(false);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('does not block on value=false', () => {
|
|
117
|
+
const state = makeState({ currentState: SecurityState.OFF });
|
|
118
|
+
const opts = makeOptions({ overrideOff: false });
|
|
119
|
+
expect(cond.evaluate(makeCtx(state, opts, false))).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// ── ArmingInProgressCondition ─────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
describe('ArmingInProgressCondition', () => {
|
|
126
|
+
const cond = new ArmingInProgressCondition();
|
|
127
|
+
|
|
128
|
+
it('blocks when isArming is true and value is true', () => {
|
|
129
|
+
const state = makeState({ isArming: true });
|
|
130
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), true))).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('allows when not arming', () => {
|
|
134
|
+
const state = makeState({ isArming: false });
|
|
135
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), true))).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('does not block on value=false', () => {
|
|
139
|
+
const state = makeState({ isArming: true });
|
|
140
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), false))).toBe(false);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// ── AlreadyTriggeredCondition ─────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
describe('AlreadyTriggeredCondition', () => {
|
|
147
|
+
const cond = new AlreadyTriggeredCondition();
|
|
148
|
+
|
|
149
|
+
it('blocks when currently triggered and value is true', () => {
|
|
150
|
+
const state = makeState({ currentState: SecurityState.TRIGGERED });
|
|
151
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), true))).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('allows when not triggered', () => {
|
|
155
|
+
const state = makeState({ currentState: SecurityState.HOME });
|
|
156
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), true))).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('does not block on value=false (cancel)', () => {
|
|
160
|
+
const state = makeState({ currentState: SecurityState.TRIGGERED });
|
|
161
|
+
expect(cond.evaluate(makeCtx(state, makeOptions(), false))).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// ── DoubleKnockCondition ──────────────────────────────────────────────────────
|
|
166
|
+
|
|
167
|
+
describe('DoubleKnockCondition', () => {
|
|
168
|
+
it('allows through when doubleKnock option is disabled', () => {
|
|
169
|
+
const onFirstKnock = vi.fn();
|
|
170
|
+
const cond = new DoubleKnockCondition(onFirstKnock, vi.fn());
|
|
171
|
+
const state = makeState({ isKnocked: false });
|
|
172
|
+
const opts = makeOptions({ doubleKnock: false, doubleKnockModes: ['home'] });
|
|
173
|
+
expect(cond.evaluate(makeCtx(state, opts, true))).toBe(false);
|
|
174
|
+
expect(onFirstKnock).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('allows override switch to bypass double-knock', () => {
|
|
178
|
+
const onFirstKnock = vi.fn();
|
|
179
|
+
const cond = new DoubleKnockCondition(onFirstKnock, vi.fn());
|
|
180
|
+
const state = makeState({ isKnocked: false, currentState: SecurityState.HOME });
|
|
181
|
+
const opts = makeOptions({ doubleKnock: true, doubleKnockModes: ['home'], doubleKnockSeconds: 90 });
|
|
182
|
+
expect(cond.evaluate(makeCtx(state, opts, true, OriginType.OVERRIDE_SWITCH))).toBe(false);
|
|
183
|
+
expect(onFirstKnock).not.toHaveBeenCalled();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('blocks first knock and calls onFirstKnock', () => {
|
|
187
|
+
const onFirstKnock = vi.fn();
|
|
188
|
+
const cond = new DoubleKnockCondition(onFirstKnock, vi.fn());
|
|
189
|
+
const state = makeState({ isKnocked: false, currentState: SecurityState.HOME });
|
|
190
|
+
const opts = makeOptions({ doubleKnock: true, doubleKnockModes: ['home'], doubleKnockSeconds: 90 });
|
|
191
|
+
expect(cond.evaluate(makeCtx(state, opts, true))).toBe(true);
|
|
192
|
+
expect(state.isKnocked).toBe(true);
|
|
193
|
+
expect(onFirstKnock).toHaveBeenCalledWith(90, expect.any(Function));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('allows second knock through and clears isKnocked', () => {
|
|
197
|
+
const cond = new DoubleKnockCondition(vi.fn(), vi.fn());
|
|
198
|
+
const state = makeState({ isKnocked: true, currentState: SecurityState.HOME });
|
|
199
|
+
const opts = makeOptions({ doubleKnock: true, doubleKnockModes: ['home'], doubleKnockSeconds: 90 });
|
|
200
|
+
expect(cond.evaluate(makeCtx(state, opts, true))).toBe(false);
|
|
201
|
+
expect(state.isKnocked).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('uses mode-specific knock window when configured', () => {
|
|
205
|
+
const onFirstKnock = vi.fn();
|
|
206
|
+
const cond = new DoubleKnockCondition(onFirstKnock, vi.fn());
|
|
207
|
+
const state = makeState({ isKnocked: false, currentState: SecurityState.AWAY });
|
|
208
|
+
const opts = makeOptions({ doubleKnock: true, doubleKnockModes: ['away'], doubleKnockSeconds: 90, awayDoubleKnockSeconds: 30 });
|
|
209
|
+
cond.evaluate(makeCtx(state, opts, true));
|
|
210
|
+
expect(onFirstKnock).toHaveBeenCalledWith(30, expect.any(Function));
|
|
211
|
+
});
|
|
212
|
+
});
|