homebridge-navilink 1.0.3 → 1.1.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0](https://github.com/tbaur/homebridge-navilink/compare/v1.0.4...v1.1.0) (2026-10-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * page appliance faults and a rejected sign-in ([#37](https://github.com/tbaur/homebridge-navilink/issues/37)) ([d517887](https://github.com/tbaur/homebridge-navilink/commit/d517887c223665cfadfb0916d4e10da051fb1b2c))
9
+
10
+ ## [1.0.4](https://github.com/tbaur/homebridge-navilink/compare/v1.0.3...v1.0.4) (2026-10-18)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * rename cached accessories through updateDisplayName ([#32](https://github.com/tbaur/homebridge-navilink/issues/32)) ([c03764b](https://github.com/tbaur/homebridge-navilink/commit/c03764ba55e2e0fa794ec0607a47d6355e719234))
16
+
3
17
  ## [1.0.3](https://github.com/tbaur/homebridge-navilink/compare/v1.0.2...v1.0.3) (2026-09-20)
4
18
 
5
19
 
package/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # homebridge-navilink
2
2
 
3
- ![Tests](https://github.com/tbaur/homebridge-navilink/actions/workflows/test.yml/badge.svg)
4
- ![npm version](https://img.shields.io/npm/v/homebridge-navilink?style=flat-square)
5
- ![npm downloads](https://img.shields.io/npm/dt/homebridge-navilink?label=downloads&style=flat-square)
6
- ![Node.js](https://img.shields.io/badge/node-22%20%7C%7C%2024%20%7C%7C%2026-green)
7
- ![Homebridge](https://img.shields.io/badge/homebridge-2.x-purple)
8
- ![License](https://img.shields.io/badge/license-Apache--2.0-blue)
3
+ [![Tests](https://github.com/tbaur/homebridge-navilink/actions/workflows/test.yml/badge.svg)](https://github.com/tbaur/homebridge-navilink/actions/workflows/test.yml)
4
+ [![npm version](https://img.shields.io/npm/v/homebridge-navilink?style=flat-square)](https://www.npmjs.com/package/homebridge-navilink)
5
+ [![npm downloads](https://img.shields.io/npm/dt/homebridge-navilink?label=downloads&style=flat-square)](https://www.npmjs.com/package/homebridge-navilink)
6
+ [![Node.js](https://img.shields.io/badge/node-22%20%7C%7C%2024%20%7C%7C%2026-green)](https://nodejs.org)
7
+ [![verified-by-homebridge](https://img.shields.io/badge/homebridge-verified-blueviolet?color=%23491F59&style=flat)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
8
+ [![Homebridge](https://img.shields.io/badge/homebridge-2.x-purple)](https://homebridge.io)
9
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
9
10
 
10
11
  **Navien combi boilers and water heaters in Apple HomeKit.** Hot water and space-heating thermostats, recirculation, faults and temperature probes, with changes arriving as they happen rather than on a polling loop. Verified against an NCB-240E (firmware 4352).
11
12
 
@@ -142,10 +143,26 @@ Only one `NaviLink` platform block is supported. It can hold as many appliances
142
143
  | `options.diagnosticsInterval` | | Seconds between health lines in the log; `0` is off (default), else `30`–`3600` |
143
144
  | `options.structuredLogs` | | With diagnostics, also emit a JSON line (default false) |
144
145
  | `options.accessoryPrefix` | | Prefix for every HomeKit name. Blank uses each appliance's name |
146
+ | `options.pagerdutySignals` | | Send alert conditions to homebridge-pagerduty (default off). See [PagerDuty](#pagerduty) |
145
147
 
146
148
 
147
149
  Each entry in `devices[]` takes `id` and `name`, plus an optional `channel` and one flag per accessory: `dhw`, `heating`, `power`, `recirculation`, `fault`, `temperatureSensors` and `outdoorSensor`. The [detailed documentation](docs/README-DETAILED.md#devices-entries) describes each one.
148
150
 
151
+ ## PagerDuty
152
+
153
+ This plugin can page through [homebridge-pagerduty](https://github.com/tbaur/homebridge-pagerduty) when something needs attention. It needs Node 22.13 or later.
154
+
155
+ 1. Turn on **Send Signals to PagerDuty** (`options.pagerdutySignals`) in this plugin's settings.
156
+ 2. Restart Homebridge.
157
+ 3. In homebridge-pagerduty's settings, allow homebridge-navilink to page, save, and restart Homebridge again. [Signals from other plugins](https://github.com/tbaur/homebridge-pagerduty/blob/main/docs/SIGNALS.md#let-a-plugin-page) explains each step and what else you can set for each signal.
158
+
159
+ Each condition below then opens a PagerDuty alert while it is present, and resolves it when it clears.
160
+
161
+ | Signal | Severity | Active when |
162
+ | --- | --- | --- |
163
+ | `fault.<gateway>.<channel>` | critical | That appliance's latest status frame has a non-zero error code |
164
+ | `auth-failed` | error | NaviLink rejected the email or password and sign-in has stopped |
165
+
149
166
  ## Not Working?
150
167
 
151
168
  1. **"NaviLink rejected the email address or password."** Sign in to the NaviLink app with the same credentials. The plugin has stopped trying on purpose, so fix the password and restart Homebridge
@@ -182,6 +199,12 @@ This plugin needs your NaviLink password, stores it in the Homebridge configurat
182
199
 
183
200
 
184
201
 
202
+ ## Trademarks
203
+
204
+ homebridge-navilink is an independent project. It is not affiliated with or endorsed by Navien. Navien and NaviLink are trademarks of Kyungdong Navien Co., Ltd.
205
+
206
+
207
+
185
208
  ## License
186
209
 
187
210
  Copyright 2026 tbaur
@@ -77,6 +77,12 @@
77
77
  "maxLength": 64,
78
78
  "examples": ["Zone One"],
79
79
  "description": "HomeKit tiles become this plus the accessory: \"Zone One Hot Water\", \"Zone One Heating\", and so on. Leave blank to use each appliance's own name. Changing it renames the tiles; it does not detach rooms or automations."
80
+ },
81
+ "pagerdutySignals": {
82
+ "title": "Send Signals to PagerDuty",
83
+ "type": "boolean",
84
+ "default": false,
85
+ "description": "Write this plugin's alert conditions to homebridge-pagerduty's signal store. Then allow homebridge-navilink to page in homebridge-pagerduty's settings. Needs Node 22.13 or later."
80
86
  }
81
87
  }
82
88
  },
@@ -244,6 +244,7 @@ function redactConfig(config) {
244
244
  structuredLogs: options?.structuredLogs ?? false,
245
245
  readOnly: options?.readOnly === true,
246
246
  allowPowerOff: options?.allowPowerOff === true,
247
+ pagerdutySignals: options?.pagerdutySignals === true,
247
248
  accessoryPrefix: typeof options?.accessoryPrefix === 'string'
248
249
  && options.accessoryPrefix.trim().length > 0,
249
250
  devices: Array.isArray(config.devices) ? config.devices.length : 0,
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Copyright (c) 2026 tbaur
3
+ *
4
+ * Licensed under the Apache License, Version 2.0
5
+ * See LICENSE file for full license text
6
+ *
7
+ * @fileoverview Turns appliance faults and a rejected NaviLink sign-in into
8
+ * homebridge-pagerduty signals.
9
+ *
10
+ * The store writer is the copied module. This file decides which conditions
11
+ * are worth a page, and remembers which appliances were configured so a
12
+ * removed one can be cleared. The remembered file is this plugin's own. It
13
+ * is not the signal store, and it is never logged.
14
+ */
15
+ import type { PagerDutySignalsOptions, SignalState } from './pagerduty-signals';
16
+ /** Logged once, with the pattern rather than each gateway. */
17
+ export declare const PAGERDUTY_STARTUP_LOG = "homebridge-pagerduty support is enabled (fault.<gateway>.<channel>, auth-failed)";
18
+ export declare const SIGNAL_AUTH_FAILED = "auth-failed";
19
+ /** The subset of the store writer this class uses. */
20
+ export interface SignalWriter {
21
+ write(signal: string, state: SignalState): void;
22
+ close(): void;
23
+ }
24
+ /**
25
+ * The signal name for one appliance.
26
+ *
27
+ * The device id is `{mac}:{channel}`. A signal name cannot contain a colon,
28
+ * so the separator becomes a dot. Undefined when the id is not one this
29
+ * plugin would configure.
30
+ */
31
+ export declare function faultSignalName(deviceId: string): string | undefined;
32
+ /**
33
+ * The PagerDuty title for an appliance fault.
34
+ *
35
+ * The name is the one in config. The error code stays in the Homebridge log,
36
+ * because a saved PagerDuty message is fixed text and would keep an old code.
37
+ */
38
+ export declare function faultSummary(name: string): string;
39
+ /** Where the remembered appliance list lives. Local storage, not the repo. */
40
+ export declare function rememberedDevicesPath(storagePath: string): string;
41
+ /**
42
+ * Fault and sign-in signals for this plugin.
43
+ *
44
+ * Fault rows are written when a status frame arrives, not before: a clear
45
+ * written at startup would resolve a lockout that is still in progress.
46
+ * Auth is written when sign-in is accepted or refused, and left alone for
47
+ * every failure the session will retry.
48
+ */
49
+ export declare class NaviLinkSignals {
50
+ private readonly writer;
51
+ private readonly storagePath;
52
+ private readonly log;
53
+ private readonly warned;
54
+ constructor(writer: SignalWriter, storagePath: string, log: {
55
+ warn(message: string): void;
56
+ });
57
+ /**
58
+ * Clear fault signals for appliances that are no longer configured, then
59
+ * remember the current set. Does not write the current appliances: their
60
+ * fault state is not known until a status frame arrives.
61
+ */
62
+ syncDevices(devices: readonly {
63
+ id: string;
64
+ name: string;
65
+ }[]): void;
66
+ /** Record whether this appliance's latest status frame has an error code. */
67
+ setFault(deviceId: string, name: string, isActive: boolean): void;
68
+ /** Record whether NaviLink has rejected the account and stopped sign-in. */
69
+ setAuthenticationRejected(isRejected: boolean): void;
70
+ /** Close the store. Does not clear any signal. */
71
+ close(): void;
72
+ private readRemembered;
73
+ private writeRemembered;
74
+ private warnOnce;
75
+ }
76
+ /** Build the signals for this plugin, backed by the homebridge-pagerduty store. */
77
+ export declare function createNaviLinkSignals(options: PagerDutySignalsOptions): NaviLinkSignals;
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2026 tbaur
4
+ *
5
+ * Licensed under the Apache License, Version 2.0
6
+ * See LICENSE file for full license text
7
+ *
8
+ * @fileoverview Turns appliance faults and a rejected NaviLink sign-in into
9
+ * homebridge-pagerduty signals.
10
+ *
11
+ * The store writer is the copied module. This file decides which conditions
12
+ * are worth a page, and remembers which appliances were configured so a
13
+ * removed one can be cleared. The remembered file is this plugin's own. It
14
+ * is not the signal store, and it is never logged.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.NaviLinkSignals = exports.SIGNAL_AUTH_FAILED = exports.PAGERDUTY_STARTUP_LOG = void 0;
18
+ exports.faultSignalName = faultSignalName;
19
+ exports.faultSummary = faultSummary;
20
+ exports.rememberedDevicesPath = rememberedDevicesPath;
21
+ exports.createNaviLinkSignals = createNaviLinkSignals;
22
+ const node_fs_1 = require("node:fs");
23
+ const node_path_1 = require("node:path");
24
+ const identity_1 = require("./api/identity");
25
+ const pagerduty_signals_1 = require("./pagerduty-signals");
26
+ /** Logged once, with the pattern rather than each gateway. */
27
+ exports.PAGERDUTY_STARTUP_LOG = 'homebridge-pagerduty support is enabled (fault.<gateway>.<channel>, auth-failed)';
28
+ exports.SIGNAL_AUTH_FAILED = 'auth-failed';
29
+ const AUTH_FAILED_SUMMARY = 'NaviLink rejected the account email or password. Sign-in has stopped until it is corrected in Homebridge.';
30
+ const FAULT_SUMMARY_FALLBACK = 'Navien appliance is reporting a fault';
31
+ /** Directory under Homebridge storage for the remembered appliance list. */
32
+ const REMEMBERED_DIR = 'homebridge-navilink';
33
+ const REMEMBERED_FILE = 'pagerduty-devices.json';
34
+ const CONTROL_CHARACTERS = /[\u0000-\u001F\u007F]+/g;
35
+ /**
36
+ * The signal name for one appliance.
37
+ *
38
+ * The device id is `{mac}:{channel}`. A signal name cannot contain a colon,
39
+ * so the separator becomes a dot. Undefined when the id is not one this
40
+ * plugin would configure.
41
+ */
42
+ function faultSignalName(deviceId) {
43
+ const parsed = (0, identity_1.parseDeviceId)(deviceId);
44
+ if (parsed === undefined) {
45
+ return undefined;
46
+ }
47
+ return `fault.${parsed.mac}.${parsed.channel}`;
48
+ }
49
+ /**
50
+ * The PagerDuty title for an appliance fault.
51
+ *
52
+ * The name is the one in config. The error code stays in the Homebridge log,
53
+ * because a saved PagerDuty message is fixed text and would keep an old code.
54
+ */
55
+ function faultSummary(name) {
56
+ const cleaned = name.replace(CONTROL_CHARACTERS, ' ').replace(/\s+/g, ' ').trim();
57
+ if (cleaned.length === 0) {
58
+ return FAULT_SUMMARY_FALLBACK;
59
+ }
60
+ return `Navien ${cleaned} is reporting a fault`;
61
+ }
62
+ /** Where the remembered appliance list lives. Local storage, not the repo. */
63
+ function rememberedDevicesPath(storagePath) {
64
+ return (0, node_path_1.join)(storagePath, REMEMBERED_DIR, REMEMBERED_FILE);
65
+ }
66
+ /**
67
+ * Fault and sign-in signals for this plugin.
68
+ *
69
+ * Fault rows are written when a status frame arrives, not before: a clear
70
+ * written at startup would resolve a lockout that is still in progress.
71
+ * Auth is written when sign-in is accepted or refused, and left alone for
72
+ * every failure the session will retry.
73
+ */
74
+ class NaviLinkSignals {
75
+ writer;
76
+ storagePath;
77
+ log;
78
+ warned = new Set();
79
+ constructor(writer, storagePath, log) {
80
+ this.writer = writer;
81
+ this.storagePath = storagePath;
82
+ this.log = log;
83
+ }
84
+ /**
85
+ * Clear fault signals for appliances that are no longer configured, then
86
+ * remember the current set. Does not write the current appliances: their
87
+ * fault state is not known until a status frame arrives.
88
+ */
89
+ syncDevices(devices) {
90
+ const current = devices.map((device) => ({ id: device.id, name: device.name }));
91
+ const currentIds = new Set(current.map((device) => device.id));
92
+ for (const previous of this.readRemembered()) {
93
+ if (!currentIds.has(previous.id)) {
94
+ this.setFault(previous.id, previous.name, false);
95
+ }
96
+ }
97
+ this.writeRemembered(current);
98
+ }
99
+ /** Record whether this appliance's latest status frame has an error code. */
100
+ setFault(deviceId, name, isActive) {
101
+ const signal = faultSignalName(deviceId);
102
+ if (signal === undefined) {
103
+ return;
104
+ }
105
+ this.writer.write(signal, {
106
+ active: isActive,
107
+ severity: 'critical',
108
+ summary: faultSummary(name),
109
+ });
110
+ }
111
+ /** Record whether NaviLink has rejected the account and stopped sign-in. */
112
+ setAuthenticationRejected(isRejected) {
113
+ this.writer.write(exports.SIGNAL_AUTH_FAILED, {
114
+ active: isRejected,
115
+ severity: 'error',
116
+ summary: AUTH_FAILED_SUMMARY,
117
+ });
118
+ }
119
+ /** Close the store. Does not clear any signal. */
120
+ close() {
121
+ this.writer.close();
122
+ }
123
+ readRemembered() {
124
+ const file = rememberedDevicesPath(this.storagePath);
125
+ if (!(0, node_fs_1.existsSync)(file)) {
126
+ return [];
127
+ }
128
+ try {
129
+ const parsed = JSON.parse((0, node_fs_1.readFileSync)(file, 'utf8'));
130
+ const devices = rememberedDevices(parsed);
131
+ if (devices === undefined) {
132
+ this.warnOnce('PagerDuty device list could not be read; removed appliances will not be cleared this start');
133
+ return [];
134
+ }
135
+ return devices;
136
+ }
137
+ catch {
138
+ this.warnOnce('PagerDuty device list could not be read; removed appliances will not be cleared this start');
139
+ return [];
140
+ }
141
+ }
142
+ writeRemembered(devices) {
143
+ const dir = (0, node_path_1.join)(this.storagePath, REMEMBERED_DIR);
144
+ const file = rememberedDevicesPath(this.storagePath);
145
+ const temporary = `${file}.tmp`;
146
+ try {
147
+ (0, node_fs_1.mkdirSync)(dir, { recursive: true, mode: 0o700 });
148
+ (0, node_fs_1.chmodSync)(dir, 0o700);
149
+ const payload = JSON.stringify({ devices });
150
+ const fd = (0, node_fs_1.openSync)(temporary, 'w', 0o600);
151
+ try {
152
+ (0, node_fs_1.writeFileSync)(fd, payload);
153
+ }
154
+ finally {
155
+ (0, node_fs_1.closeSync)(fd);
156
+ }
157
+ (0, node_fs_1.chmodSync)(temporary, 0o600);
158
+ (0, node_fs_1.renameSync)(temporary, file);
159
+ (0, node_fs_1.chmodSync)(file, 0o600);
160
+ }
161
+ catch {
162
+ try {
163
+ (0, node_fs_1.unlinkSync)(temporary);
164
+ }
165
+ catch {
166
+ // The temporary file may not exist. The warning below is the outcome.
167
+ }
168
+ this.warnOnce('PagerDuty device list could not be saved');
169
+ }
170
+ }
171
+ warnOnce(message) {
172
+ if (this.warned.has(message)) {
173
+ return;
174
+ }
175
+ this.warned.add(message);
176
+ this.log.warn(message);
177
+ }
178
+ }
179
+ exports.NaviLinkSignals = NaviLinkSignals;
180
+ /** Build the signals for this plugin, backed by the homebridge-pagerduty store. */
181
+ function createNaviLinkSignals(options) {
182
+ return new NaviLinkSignals(new pagerduty_signals_1.PagerDutySignals(options), options.storagePath, options.log);
183
+ }
184
+ /**
185
+ * The appliance list in the remembered file, or undefined when the file is
186
+ * not that list. A bad entry fails the whole file, so a partial read cannot
187
+ * clear the wrong appliance.
188
+ */
189
+ function rememberedDevices(value) {
190
+ if (typeof value !== 'object' || value === null) {
191
+ return undefined;
192
+ }
193
+ const devices = value.devices;
194
+ if (!Array.isArray(devices)) {
195
+ return undefined;
196
+ }
197
+ const parsed = [];
198
+ for (const entry of devices) {
199
+ if (typeof entry !== 'object' || entry === null) {
200
+ return undefined;
201
+ }
202
+ const id = entry.id;
203
+ const name = entry.name;
204
+ if (typeof id !== 'string' || typeof name !== 'string' || (0, identity_1.parseDeviceId)(id) === undefined) {
205
+ return undefined;
206
+ }
207
+ parsed.push({ id, name });
208
+ }
209
+ return parsed;
210
+ }
@@ -0,0 +1,34 @@
1
+ export type SignalSeverity = 'info' | 'warning' | 'error' | 'critical';
2
+ export interface SignalState {
3
+ active: boolean;
4
+ severity: SignalSeverity;
5
+ summary: string;
6
+ }
7
+ export interface PagerDutySignalsOptions {
8
+ /** This plugin's npm package name, exactly as in package.json. */
9
+ plugin: string;
10
+ /** `api.user.storagePath()` */
11
+ storagePath: string;
12
+ log: {
13
+ warn(message: string): void;
14
+ };
15
+ }
16
+ /**
17
+ * Writes this plugin's conditions to the homebridge-pagerduty signal store.
18
+ * Never throws: a failure is logged once, and the next write tries again.
19
+ */
20
+ export declare class PagerDutySignals {
21
+ private readonly options;
22
+ private db;
23
+ private readonly lastWritten;
24
+ private isDisabled;
25
+ private hasWarned;
26
+ constructor(options: PagerDutySignalsOptions);
27
+ /** Record a signal's current state. Skipped when nothing changed since the last write. */
28
+ write(signal: string, state: SignalState): void;
29
+ /** Close the connection. Call on Homebridge `shutdown`. Never clears a signal. */
30
+ close(): void;
31
+ private open;
32
+ private disable;
33
+ private warnOnce;
34
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PagerDutySignals = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const STORE_DIR = 'homebridge-pagerduty';
7
+ // The signal store interface this module writes. Change it only by copying a
8
+ // newer version of this module from homebridge-pagerduty's docs/SIGNALS-AGENT.md.
9
+ const INTERFACE_ID = 'signals-2026-10-24';
10
+ const STORE_FILE = 'signals.sqlite';
11
+ const MAX_SUMMARY_LENGTH = 1024;
12
+ const CONTROL_CHARACTERS = /[\u0000-\u001F\u007F]+/g;
13
+ // The table definition of interface signals-2026-10-24. Every writer must run
14
+ // this exact text: the first process to run it defines the table.
15
+ const SCHEMA = `PRAGMA journal_mode = WAL;
16
+ CREATE TABLE IF NOT EXISTS signals (
17
+ plugin TEXT NOT NULL CHECK (length(plugin) BETWEEN 1 AND 128 AND plugin NOT GLOB '*[^a-z0-9@/._-]*'),
18
+ signal TEXT NOT NULL CHECK (length(signal) BETWEEN 1 AND 64 AND signal NOT GLOB '*[^a-z0-9._-]*'),
19
+ active INTEGER NOT NULL CHECK (active IN (0, 1)),
20
+ severity TEXT NOT NULL CHECK (severity IN ('info', 'warning', 'error', 'critical')),
21
+ summary TEXT NOT NULL CHECK (length(summary) BETWEEN 1 AND 1024),
22
+ updated_at INTEGER NOT NULL,
23
+ PRIMARY KEY (plugin, signal)
24
+ ) STRICT;`;
25
+ const UPSERT = 'INSERT INTO signals (plugin, signal, active, severity, summary, updated_at) VALUES (?, ?, ?, ?, ?, ?) '
26
+ + 'ON CONFLICT (plugin, signal) DO UPDATE SET active = excluded.active, severity = excluded.severity, '
27
+ + 'summary = excluded.summary, updated_at = excluded.updated_at';
28
+ /**
29
+ * Writes this plugin's conditions to the homebridge-pagerduty signal store.
30
+ * Never throws: a failure is logged once, and the next write tries again.
31
+ */
32
+ class PagerDutySignals {
33
+ options;
34
+ db;
35
+ lastWritten = new Map();
36
+ isDisabled = false;
37
+ hasWarned = false;
38
+ constructor(options) {
39
+ this.options = options;
40
+ }
41
+ /** Record a signal's current state. Skipped when nothing changed since the last write. */
42
+ write(signal, state) {
43
+ const summary = state.summary.replace(CONTROL_CHARACTERS, ' ').slice(0, MAX_SUMMARY_LENGTH);
44
+ const fingerprint = `${state.active ? 1 : 0}|${state.severity}|${summary}`;
45
+ if (this.isDisabled || this.lastWritten.get(signal) === fingerprint) {
46
+ return;
47
+ }
48
+ try {
49
+ const db = this.db ?? this.open();
50
+ db.prepare(UPSERT).run(this.options.plugin, signal, state.active ? 1 : 0, state.severity, summary, Date.now());
51
+ this.lastWritten.set(signal, fingerprint);
52
+ this.hasWarned = false;
53
+ }
54
+ catch (error) {
55
+ this.warnOnce(`PagerDuty signal ${signal} was not written: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ }
58
+ /** Close the connection. Call on Homebridge `shutdown`. Never clears a signal. */
59
+ close() {
60
+ this.db?.close();
61
+ this.db = undefined;
62
+ }
63
+ open() {
64
+ // Loaded here, not imported at the top, so the plugin still loads on a
65
+ // Node version without node:sqlite.
66
+ const sqlite = typeof process.getBuiltinModule === 'function'
67
+ ? process.getBuiltinModule('node:sqlite')
68
+ : undefined;
69
+ if (sqlite === undefined) {
70
+ this.disable('PagerDuty signals need Node 22.13 or later; not writing signals');
71
+ }
72
+ const dir = (0, node_path_1.join)(this.options.storagePath, STORE_DIR, INTERFACE_ID);
73
+ const file = (0, node_path_1.join)(dir, STORE_FILE);
74
+ (0, node_fs_1.mkdirSync)(dir, { recursive: true, mode: 0o700 });
75
+ (0, node_fs_1.closeSync)((0, node_fs_1.openSync)(file, 'a', 0o600));
76
+ const db = new sqlite.DatabaseSync(file);
77
+ try {
78
+ db.exec('PRAGMA busy_timeout = 1000');
79
+ db.exec(SCHEMA);
80
+ }
81
+ catch (error) {
82
+ db.close();
83
+ throw error;
84
+ }
85
+ this.db = db;
86
+ return db;
87
+ }
88
+ disable(message) {
89
+ this.isDisabled = true;
90
+ this.hasWarned = false;
91
+ this.warnOnce(message);
92
+ throw new Error(message);
93
+ }
94
+ warnOnce(message) {
95
+ if (!this.hasWarned) {
96
+ this.hasWarned = true;
97
+ this.options.log.warn(message);
98
+ }
99
+ }
100
+ }
101
+ exports.PagerDutySignals = PagerDutySignals;
@@ -44,6 +44,10 @@ export declare class NaviLinkPlatform implements DynamicPlatformPlugin, Accessor
44
44
  private readonly devices;
45
45
  private options;
46
46
  private session;
47
+ /** PagerDuty signals, present only when the user turned them on. */
48
+ private signals;
49
+ /** The startup line is once per process, including a second call to start. */
50
+ private hasAnnouncedPagerDuty;
47
51
  private readonly platformConfig;
48
52
  private readonly diagnostics;
49
53
  private diagnosticsTimer;
@@ -60,6 +64,16 @@ export declare class NaviLinkPlatform implements DynamicPlatformPlugin, Accessor
60
64
  configureAccessory(accessory: PlatformAccessory): void;
61
65
  private start;
62
66
  private stop;
67
+ /**
68
+ * Open PagerDuty signals when the user asked for them.
69
+ *
70
+ * The log line comes before sign-in, so it is still there when sign-in
71
+ * then fails. Current fault state is not written here: that waits for a
72
+ * status frame, so a restart during a lockout does not resolve the page.
73
+ */
74
+ private openPagerDuty;
75
+ /** A status frame is the first moment a fault is known, tile or no tile. */
76
+ private noteFault;
63
77
  /** Keep cached accessories registered when configuration is unusable. */
64
78
  private keepRestoredRegistered;
65
79
  /**
package/dist/platform.js CHANGED
@@ -35,6 +35,7 @@ const protocol_1 = require("./api/protocol");
35
35
  const devices_1 = require("./devices");
36
36
  const collector_1 = require("./diagnostics/collector");
37
37
  const format_1 = require("./diagnostics/format");
38
+ const navilink_signals_1 = require("./navilink-signals");
38
39
  const session_1 = require("./session");
39
40
  const settings_1 = require("./settings");
40
41
  const types_1 = require("./types");
@@ -59,8 +60,13 @@ class NaviLinkPlatform {
59
60
  diagnosticsInterval: 0,
60
61
  structuredLogs: false,
61
62
  accessoryPrefix: '',
63
+ pagerdutySignals: false,
62
64
  };
63
65
  session;
66
+ /** PagerDuty signals, present only when the user turned them on. */
67
+ signals;
68
+ /** The startup line is once per process, including a second call to start. */
69
+ hasAnnouncedPagerDuty = false;
64
70
  platformConfig;
65
71
  diagnostics;
66
72
  diagnosticsTimer;
@@ -124,6 +130,7 @@ class NaviLinkPlatform {
124
130
  this.log.warn(warning);
125
131
  }
126
132
  this.syncAccessories(accessories);
133
+ this.openPagerDuty(devices);
127
134
  const session = new session_1.NaviLinkSession({
128
135
  log: this.log,
129
136
  account,
@@ -131,8 +138,12 @@ class NaviLinkPlatform {
131
138
  statusIntervalSec: this.options.statusIntervalSec,
132
139
  metrics: this.diagnostics,
133
140
  onCircuitOpen: () => this.diagnostics.breakerTrip(),
141
+ onAuthentication: (result) => {
142
+ this.signals?.setAuthenticationRejected(result === 'rejected');
143
+ },
134
144
  });
135
145
  session.onObservation((deviceId, observation, reason) => {
146
+ this.noteFault(deviceId, observation);
136
147
  this.distribute(deviceId, observation, reason);
137
148
  });
138
149
  session.onUnreachable((error) => this.markAllUnreachable(error));
@@ -148,8 +159,51 @@ class NaviLinkPlatform {
148
159
  handler.stop();
149
160
  }
150
161
  this.handlers.clear();
151
- await this.session?.stop();
152
- this.session = undefined;
162
+ try {
163
+ await this.session?.stop();
164
+ }
165
+ finally {
166
+ this.session = undefined;
167
+ this.signals?.close();
168
+ this.signals = undefined;
169
+ }
170
+ }
171
+ /**
172
+ * Open PagerDuty signals when the user asked for them.
173
+ *
174
+ * The log line comes before sign-in, so it is still there when sign-in
175
+ * then fails. Current fault state is not written here: that waits for a
176
+ * status frame, so a restart during a lockout does not resolve the page.
177
+ */
178
+ openPagerDuty(devices) {
179
+ if (!this.options.pagerdutySignals) {
180
+ return;
181
+ }
182
+ if (!this.hasAnnouncedPagerDuty) {
183
+ this.hasAnnouncedPagerDuty = true;
184
+ this.log.info(navilink_signals_1.PAGERDUTY_STARTUP_LOG);
185
+ }
186
+ if (this.signals === undefined) {
187
+ const storagePath = this.api.user.storagePath();
188
+ if (storagePath.length === 0) {
189
+ this.log.warn('PagerDuty signals need a Homebridge storage directory; not writing signals');
190
+ return;
191
+ }
192
+ this.signals = (0, navilink_signals_1.createNaviLinkSignals)({
193
+ plugin: settings_1.PLUGIN_NAME,
194
+ storagePath,
195
+ log: this.log,
196
+ });
197
+ }
198
+ this.signals.syncDevices(devices);
199
+ }
200
+ /** A status frame is the first moment a fault is known, tile or no tile. */
201
+ noteFault(deviceId, observation) {
202
+ const device = this.devices.get(deviceId);
203
+ if (device === undefined) {
204
+ return;
205
+ }
206
+ this.signals?.setFault(device.id, device.name, observation.readings.errorCode !== 0);
153
207
  }
154
208
  /** Keep cached accessories registered when configuration is unusable. */
155
209
  keepRestoredRegistered() {
@@ -236,8 +290,11 @@ class NaviLinkPlatform {
236
290
  }
237
291
  if (accessory.displayName !== resolved.name) {
238
292
  this.log.info(`${(0, utils_1.forLog)(accessory.displayName)} is now named ${(0, utils_1.forLog)(resolved.name)}`);
293
+ // Assigning `displayName` only changes the wrapper. Homebridge publishes
294
+ // and restores the HAP accessory's name, so a cached tile keeps the old
295
+ // one until `updateDisplayName` writes both.
296
+ accessory.updateDisplayName(resolved.name);
239
297
  }
240
- accessory.displayName = resolved.name;
241
298
  const init = {
242
299
  host: this,
243
300
  accessory,
package/dist/session.d.ts CHANGED
@@ -74,6 +74,14 @@ export interface NaviLinkSessionOptions {
74
74
  metrics?: SessionMetrics;
75
75
  /** Fired when REST trips OPEN, so diagnostics can count a trip. */
76
76
  onCircuitOpen?: () => void;
77
+ /**
78
+ * Sign-in finished one way or the other.
79
+ *
80
+ * `accepted` means the account was taken. A later network failure or a
81
+ * rejected session token is not this. `rejected` means NaviLink refused
82
+ * the email or password and sign-in has stopped.
83
+ */
84
+ onAuthentication?: (result: 'accepted' | 'rejected') => void;
77
85
  }
78
86
  /** Owns the plugin's entire relationship with the NaviLink cloud. */
79
87
  export declare class NaviLinkSession {
@@ -202,6 +210,8 @@ export declare class NaviLinkSession {
202
210
  private waitForSessionEnd;
203
211
  /** Stop trying, and say why exactly once. */
204
212
  private stopPermanently;
213
+ /** Tell the platform, and keep a thrown listener from stopping the session. */
214
+ private reportAuthentication;
205
215
  /** True when the session has given up for a reason the user must fix. */
206
216
  get hasStoppedPermanently(): boolean;
207
217
  private requestChannelInfo;
package/dist/session.js CHANGED
@@ -301,6 +301,7 @@ class NaviLinkSession {
301
301
  this.clearTimers();
302
302
  this.dropConnection();
303
303
  const tokens = await this.rest.signIn(this.options.account.email, this.options.account.password);
304
+ this.reportAuthentication('accepted');
304
305
  this.expiresAt = tokens.expiresAt;
305
306
  if (this.lastRefreshAt !== undefined) {
306
307
  this.options.metrics?.sessionRefresh();
@@ -509,8 +510,18 @@ class NaviLinkSession {
509
510
  this.clearTimers();
510
511
  this.dropConnection();
511
512
  this.log.error(`${error.message}; sign-in stopped`);
513
+ this.reportAuthentication('rejected');
512
514
  this.notifyUnreachable(error);
513
515
  }
516
+ /** Tell the platform, and keep a thrown listener from stopping the session. */
517
+ reportAuthentication(result) {
518
+ try {
519
+ this.options.onAuthentication?.(result);
520
+ }
521
+ catch (error) {
522
+ this.log.debug(`an authentication listener threw: ${(0, utils_1.describeError)(error)}`);
523
+ }
524
+ }
514
525
  /** True when the session has given up for a reason the user must fix. */
515
526
  get hasStoppedPermanently() {
516
527
  return this.fatal !== undefined;
@@ -122,6 +122,13 @@ export interface NaviLinkPlatformOptions {
122
122
  * attached if you rename later.
123
123
  */
124
124
  accessoryPrefix?: string;
125
+ /**
126
+ * Write fault and sign-in conditions to homebridge-pagerduty's signal store.
127
+ *
128
+ * Off by default. The plugin does not page until the user also allows it
129
+ * in homebridge-pagerduty. Needs Node 22.13 or later.
130
+ */
131
+ pagerdutySignals?: boolean;
125
132
  }
126
133
  /** Shape of one `platforms[]` entry in `config.json`. */
127
134
  export interface NaviLinkPlatformConfig {
@@ -32,6 +32,7 @@ export interface ResolvedPlatformOptions {
32
32
  diagnosticsInterval: number;
33
33
  structuredLogs: boolean;
34
34
  accessoryPrefix: string;
35
+ pagerdutySignals: boolean;
35
36
  }
36
37
  /** The account, once it is known to be usable. */
37
38
  export interface ResolvedAccount {
@@ -293,6 +293,7 @@ function validateConfig(config) {
293
293
  diagnosticsInterval: 0,
294
294
  structuredLogs: false,
295
295
  accessoryPrefix: '',
296
+ pagerdutySignals: false,
296
297
  };
297
298
  if (typeof config !== 'object' || config === null) {
298
299
  return { errors: ['platform configuration is missing'], warnings, account: undefined, devices: [], options: defaults };
@@ -306,6 +307,7 @@ function validateConfig(config) {
306
307
  diagnosticsInterval: resolveDiagnosticsIntervalSec(platform.options?.diagnosticsInterval, warnings),
307
308
  structuredLogs: platform.options?.structuredLogs === true,
308
309
  accessoryPrefix: resolveAccessoryPrefix(platform.options?.accessoryPrefix, warnings),
310
+ pagerdutySignals: platform.options?.pagerdutySignals === true,
309
311
  };
310
312
  const rawDevices = platform.devices;
311
313
  if (rawDevices === undefined) {
package/docs/FEATURES.md CHANGED
@@ -22,6 +22,7 @@ A checklist of what is built. The plugin aims to cover everything about a Navien
22
22
 
23
23
  - ✅ **Push, not polling.** A change made in the NaviLink app or at the wall controller reaches HomeKit in about a second. The poll is only a backstop
24
24
  - ✅ **A rejected password is never retried.** The session stops and logs `NaviLink rejected the email address or password; sign-in stopped`
25
+ - ✅ **PagerDuty signals** (`options.pagerdutySignals`, off by default): `fault.<gateway>.<channel>` when an appliance reports an error code, and `auth-failed` when NaviLink rejects the account and sign-in stops
25
26
  - ✅ **Credentials are renewed on a clock,** a few minutes before they expire. A planned refresh is not logged as an outage; tiles stay current
26
27
  - ✅ **A connected socket is not a live appliance.** Readings carry the time they were taken, and a stale one becomes No Response
27
28
  - ✅ **State:** No Response until the appliance has actually been read, and not a value it cannot confirm
@@ -71,6 +71,8 @@ A ContactSensor that reads **open** when the appliance reports a non-zero error
71
71
 
72
72
  The code and sub-code go to the log once per change (`error 12.3`, then `fault cleared`). Look the number up in your installation manual; naming them in the plugin is on the [roadmap](#roadmap).
73
73
 
74
+ Paging this condition through homebridge-pagerduty does not require this tile. See [PagerDuty](#pagerduty).
75
+
74
76
  ### Temperature sensors (`temperatureSensors`)
75
77
 
76
78
  One tick, four sensors:
@@ -126,6 +128,7 @@ An appliance with no probe reports `0`. The plugin treats that as absent, not as
126
128
  | `options.diagnosticsInterval` | integer | `0` | Health heartbeat in the log, in seconds. `0` is off; otherwise `30`–`3600` |
127
129
  | `options.structuredLogs` | boolean | `false` | With diagnostics, also emit each report as JSON |
128
130
  | `options.accessoryPrefix` | string | *(blank)* | HomeKit names become `Prefix Hot Water`, `Prefix Heating`, and so on. Blank uses each appliance's name. Two appliances with the same prefix keep the appliance name in the tile so Siri can tell them apart |
131
+ | `options.pagerdutySignals` | boolean | `false` | Write `fault.<gateway>.<channel>` and `auth-failed` to homebridge-pagerduty. See [PagerDuty](#pagerduty) |
129
132
 
130
133
  A trailing space on the password is trimmed. A password manager will happily paste one. The trim is mentioned once in the log. Without that, the cloud rejects a password that looks right and the failure is unexplainable.
131
134
 
@@ -298,6 +301,23 @@ In rough order, matching [FEATURES.md](FEATURES.md#not-built-yet):
298
301
 
299
302
  Weekly schedules, commissioning settings and descaling reminders are [not planned](FEATURES.md#not-planned).
300
303
 
304
+ ## PagerDuty
305
+
306
+ This plugin can page through [homebridge-pagerduty](https://github.com/tbaur/homebridge-pagerduty) when something needs attention. It needs Node 22.13 or later.
307
+
308
+ 1. Turn on **Send Signals to PagerDuty** (`options.pagerdutySignals`) in this plugin's settings.
309
+ 2. Restart Homebridge.
310
+ 3. In homebridge-pagerduty's settings, allow homebridge-navilink to page, save, and restart Homebridge again. [Signals from other plugins](https://github.com/tbaur/homebridge-pagerduty/blob/main/docs/SIGNALS.md#let-a-plugin-page) explains each step and what else you can set for each signal.
311
+
312
+ Each condition below then opens a PagerDuty alert while it is present, and resolves it when it clears.
313
+
314
+ | Signal | Severity | Active when |
315
+ | --- | --- | --- |
316
+ | `fault.<gateway>.<channel>` | critical | That appliance's latest status frame has a non-zero error code. One signal per configured appliance, whether or not the HomeKit fault tile is on. The error code stays in the Homebridge log |
317
+ | `auth-failed` | error | NaviLink rejected the email or password and sign-in has stopped. A network failure, an open circuit breaker, or a rejected session token does not turn this on |
318
+
319
+ A fault is written when the first status frame for that appliance arrives, and again when the code changes. It is not written clear before that frame, so a restart during a lockout does not resolve the page and open it again. Shutdown does not clear a signal. An appliance removed from the configuration is cleared on the next start with the setting on. A configuration that fails validation does not change the store.
320
+
301
321
  ## Troubleshooting
302
322
 
303
323
  **1. "NaviLink rejected the email address or password."**
@@ -353,7 +373,7 @@ See [SECURITY.md](../SECURITY.md) for the detail, including what a raw capture c
353
373
  - **Strict TypeScript,** with `noUncheckedIndexedAccess` and type-aware lint; warnings are failures
354
374
  - **Tested:** a behavioural Jest suite against fixtures recorded from real hardware, gated at 80% of statements, with a guard that fails the build if a MAC address, email or token that is not the documented example appears in `tests/fixtures/`
355
375
  - A CI step that rejects credential-shaped strings in the published docs, fixtures, schema and issue templates. Unit tests that hold fake JWTs are outside that scan on purpose
356
- - `npm audit` on the runtime tree on every PR; OSV-Scanner on the full tree, weekly and on every PR
376
+ - `npm audit` on the runtime tree on every PR; OSV-Scanner on the full tree, on every PR, on every push to `main`, and weekly
357
377
  - **No analytics:** nothing is sent anywhere except Navien's own service
358
378
  - **One runtime dependency:** Homebridge's own UI helper. The MQTT client is a small in-repo codec, not a `mqtt.js` dependency tree
359
379
 
@@ -144,6 +144,16 @@
144
144
  Also emit each diagnostics report as JSON
145
145
  </label>
146
146
  </div>
147
+
148
+ <div class="nl-options">
149
+ <label class="nl-check">
150
+ <input type="checkbox" id="pagerduty-signals" />
151
+ Send signals to PagerDuty
152
+ </label>
153
+ </div>
154
+ <div class="nl-meta">
155
+ Write fault and sign-in conditions to homebridge-pagerduty. Then allow homebridge-navilink to page in that plugin's settings. Needs Node 22.13 or later.
156
+ </div>
147
157
  </div>
148
158
 
149
159
  <div class="nl-actions">
@@ -257,6 +257,7 @@
257
257
  byId('diagnostics-interval').value = String(diagnostics)
258
258
  syncDiagnosticsLabel()
259
259
  byId('structured-logs').checked = platformConfig.options.structuredLogs === true
260
+ byId('pagerduty-signals').checked = platformConfig.options.pagerdutySignals === true
260
261
  }
261
262
 
262
263
  /** Keep the slider's number in step with the thumb. 0 is Off. */
@@ -295,6 +296,7 @@
295
296
  platformConfig.options.diagnosticsInterval = diagnostics
296
297
  }
297
298
  setFlag('structuredLogs', byId('structured-logs').checked === true)
299
+ setFlag('pagerdutySignals', byId('pagerduty-signals').checked === true)
298
300
 
299
301
  const email = byId('email').value.trim()
300
302
  const password = byId('password').value.trim()
@@ -520,6 +522,7 @@
520
522
  changed()
521
523
  })
522
524
  byId('structured-logs').addEventListener('change', () => changed())
525
+ byId('pagerduty-signals').addEventListener('change', () => changed())
523
526
  byId('toggle-json').addEventListener('click', () => {
524
527
  schemaFormVisible = !schemaFormVisible
525
528
  if (schemaFormVisible) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "homebridge-navilink",
3
3
  "displayName": "Homebridge NaviLink",
4
- "version": "1.0.3",
4
+ "version": "1.1.0",
5
5
  "description": "Homebridge plugin for Navien combi boilers and water heaters through the North American NaviLink cloud: hot water and space-heating thermostats, power, recirculation, fault and temperature accessories. Verified on an NCB-240E (firmware 4352)",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -41,7 +41,8 @@
41
41
  "homepage": "https://github.com/tbaur/homebridge-navilink#readme",
42
42
  "overrides": {
43
43
  "js-yaml": "^4.3.2",
44
- "brace-expansion": "^5.0.12"
44
+ "brace-expansion": "^5.0.12",
45
+ "handlebars": "^4.7.10"
45
46
  },
46
47
  "dependencies": {
47
48
  "@homebridge/plugin-ui-utils": "2.2.6"
@@ -55,7 +56,7 @@
55
56
  "globals": "^17.12.0",
56
57
  "homebridge": "^2.4.0",
57
58
  "jest": "^30.5.2",
58
- "ts-jest": "29.4.12",
59
+ "ts-jest": "29.4.14",
59
60
  "typescript": "^6.0.3"
60
61
  },
61
62
  "engines": {