homebridge-philips-air-purifier-complete 3.2.0 → 3.2.2
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 +40 -0
- package/config.schema.json +2 -1
- package/eslint.config.js +1 -0
- package/homebridge-ui/public/index.html +521 -301
- package/index.js +4 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,46 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [3.2.2] — 15/06/2026
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Fixed a Homebridge crash loop when restoring cached purifier accessories after the first
|
|
14
|
+
successful v3 platform startup. Optional HomeKit characteristics are now reused instead of
|
|
15
|
+
added again on restored services.
|
|
16
|
+
- Corrected package lockfile version metadata after the v3.2.1 release.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## [3.2.1] — 15/06/2026
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Replaced the broken native schema form device editor with a fully custom device manager UI.
|
|
25
|
+
Config UI X v5.24.0 does not correctly load existing array item values into either `tabarray`
|
|
26
|
+
or `array` layout types, making the native form unusable for editing saved devices. The new
|
|
27
|
+
custom UI reads and writes the `devices[]` array directly via `homebridge.getPluginConfig()` /
|
|
28
|
+
`updatePluginConfig()`, bypassing the schema form entirely.
|
|
29
|
+
- Clicking the "Plugin Config" button now opens the full custom UI (device manager + Air+ OAuth)
|
|
30
|
+
instead of the broken native tabarray form. Requires `"customUi": true` in `config.schema.json`
|
|
31
|
+
for Config UI X v5 to route through the custom UI.
|
|
32
|
+
- The "clicking Add Device creates new devices" UX bug is eliminated — the Add Device button is
|
|
33
|
+
now a clearly labelled `+ Add Device` button at the bottom of the Devices panel.
|
|
34
|
+
- Each device card shows the correct name, protocol, host, and protocol-specific fields (HomeID
|
|
35
|
+
credentials, Air+ UUID/token) loaded from the saved config.
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- `config.schema.json` gains `"customUi": true` (needed by Config UI X v5 to route Plugin Config
|
|
40
|
+
clicks through the custom UI iframe, not the native schema form modal).
|
|
41
|
+
- `homebridge-ui/public/index.html` rewritten as a full device manager: per-device cards with
|
|
42
|
+
collapsible forms, protocol-aware conditional fields, Add / Remove device support, and the
|
|
43
|
+
existing Air+ OAuth flow.
|
|
44
|
+
- `headerDisplay` updated to point users to Plugin Settings for the full experience.
|
|
45
|
+
- `eslint.config.js` ignores `test-*.cjs` files (local Playwright test scripts).
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
9
49
|
## [3.2.0] — 15/06/2026
|
|
10
50
|
|
|
11
51
|
### Added
|
package/config.schema.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"pluginAlias": "PhilipsAirPurifier",
|
|
3
3
|
"pluginType": "platform",
|
|
4
4
|
"singular": true,
|
|
5
|
-
"
|
|
5
|
+
"customUi": true,
|
|
6
|
+
"headerDisplay": "<p align='center'><img src='https://raw.githubusercontent.com/MaddogWarner/homebridge-philips-air-purifier-complete/main/icon.png' width='150' alt='Philips Air Purifier'></p><div style='margin-top:16px;padding:12px 16px;background:#eaf4ff;border-left:4px solid #2f80c9;border-radius:4px;color:#17324d;font-size:14px;'><strong>Use the Plugin Settings button for the best experience.</strong><br>Click the <strong>Plugin Settings</strong> button (wrench icon or cog on the plugin card) to open the full device manager. You can also add and edit devices in the tabs below.</div>",
|
|
6
7
|
"schema": {
|
|
7
8
|
"type": "object",
|
|
8
9
|
"properties": {
|
package/eslint.config.js
CHANGED
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Philips Air Purifier Settings</title>
|
|
7
7
|
<style>
|
|
8
|
-
* {
|
|
9
|
-
box-sizing: border-box;
|
|
10
|
-
}
|
|
8
|
+
* { box-sizing: border-box; }
|
|
11
9
|
|
|
12
10
|
:root {
|
|
13
11
|
--bg: #161616;
|
|
@@ -33,40 +31,14 @@
|
|
|
33
31
|
padding: 24px;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
h1
|
|
37
|
-
h2
|
|
38
|
-
h3
|
|
39
|
-
p
|
|
40
|
-
margin-top: 0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
h1 {
|
|
44
|
-
font-size: 24px;
|
|
45
|
-
font-weight: 650;
|
|
46
|
-
margin-bottom: 10px;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
h2 {
|
|
50
|
-
font-size: 18px;
|
|
51
|
-
font-weight: 650;
|
|
52
|
-
margin-bottom: 12px;
|
|
53
|
-
}
|
|
34
|
+
h1 { font-size: 24px; font-weight: 650; margin: 0 0 10px; }
|
|
35
|
+
h2 { font-size: 18px; font-weight: 650; margin: 0 0 12px; }
|
|
36
|
+
h3 { font-size: 15px; font-weight: 650; margin: 0 0 4px; }
|
|
37
|
+
p { margin-top: 0; }
|
|
54
38
|
|
|
55
|
-
|
|
56
|
-
font-size: 15px;
|
|
57
|
-
font-weight: 650;
|
|
58
|
-
margin-bottom: 4px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
[hidden] {
|
|
62
|
-
display: none !important;
|
|
63
|
-
}
|
|
39
|
+
[hidden] { display: none !important; }
|
|
64
40
|
|
|
65
|
-
.layout {
|
|
66
|
-
display: grid;
|
|
67
|
-
gap: 14px;
|
|
68
|
-
max-width: 1040px;
|
|
69
|
-
}
|
|
41
|
+
.layout { display: grid; gap: 14px; max-width: 860px; }
|
|
70
42
|
|
|
71
43
|
.panel {
|
|
72
44
|
background: var(--panel);
|
|
@@ -75,56 +47,43 @@
|
|
|
75
47
|
padding: 16px;
|
|
76
48
|
}
|
|
77
49
|
|
|
78
|
-
.toolbar {
|
|
79
|
-
display: flex;
|
|
80
|
-
flex-wrap: wrap;
|
|
81
|
-
gap: 10px;
|
|
82
|
-
margin-bottom: 12px;
|
|
83
|
-
}
|
|
50
|
+
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
|
|
84
51
|
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
}
|
|
52
|
+
.field { display: grid; gap: 4px; margin-bottom: 12px; }
|
|
53
|
+
.field label { font-size: 13px; color: var(--muted); }
|
|
54
|
+
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
88
55
|
|
|
89
|
-
|
|
90
|
-
|
|
56
|
+
input, select, textarea {
|
|
57
|
+
background: var(--input);
|
|
58
|
+
border: 1px solid #4a4a4a;
|
|
59
|
+
border-radius: 6px;
|
|
60
|
+
color: var(--text);
|
|
61
|
+
font: inherit;
|
|
62
|
+
min-height: 40px;
|
|
63
|
+
padding: 8px 10px;
|
|
64
|
+
width: 100%;
|
|
91
65
|
}
|
|
92
66
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
67
|
+
input[type="checkbox"] {
|
|
68
|
+
accent-color: var(--accent);
|
|
69
|
+
min-height: unset;
|
|
70
|
+
width: auto;
|
|
71
|
+
margin-right: 6px;
|
|
96
72
|
}
|
|
97
73
|
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
background: var(--panel-soft);
|
|
101
|
-
border: 1px solid var(--border);
|
|
102
|
-
border-radius: 8px;
|
|
103
|
-
display: grid;
|
|
104
|
-
gap: 12px;
|
|
105
|
-
grid-template-columns: minmax(0, 1fr) auto;
|
|
106
|
-
padding: 14px;
|
|
107
|
-
}
|
|
74
|
+
.checkbox-row { display: flex; align-items: center; }
|
|
75
|
+
.checkbox-row label { color: var(--text); font-size: 15px; }
|
|
108
76
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
gap: 8px;
|
|
113
|
-
justify-content: flex-end;
|
|
77
|
+
input:focus, select:focus, textarea:focus {
|
|
78
|
+
border-color: var(--accent);
|
|
79
|
+
outline: none;
|
|
114
80
|
}
|
|
115
81
|
|
|
116
|
-
|
|
117
|
-
|
|
82
|
+
textarea {
|
|
83
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
118
84
|
font-size: 13px;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
.empty {
|
|
123
|
-
background: var(--panel-soft);
|
|
124
|
-
border: 1px dashed #555555;
|
|
125
|
-
border-radius: 8px;
|
|
126
|
-
color: var(--muted);
|
|
127
|
-
padding: 18px;
|
|
85
|
+
min-height: 80px;
|
|
86
|
+
resize: vertical;
|
|
128
87
|
}
|
|
129
88
|
|
|
130
89
|
button {
|
|
@@ -139,97 +98,130 @@
|
|
|
139
98
|
padding: 9px 16px;
|
|
140
99
|
}
|
|
141
100
|
|
|
142
|
-
button:hover {
|
|
143
|
-
background: var(--accent-dark);
|
|
144
|
-
}
|
|
101
|
+
button:hover { background: var(--accent-dark); }
|
|
145
102
|
|
|
146
103
|
button.secondary {
|
|
147
104
|
background: #3a3a3a;
|
|
148
105
|
color: var(--text);
|
|
149
106
|
}
|
|
150
107
|
|
|
151
|
-
button.secondary:hover {
|
|
152
|
-
background: #4a4a4a;
|
|
153
|
-
}
|
|
108
|
+
button.secondary:hover { background: #4a4a4a; }
|
|
154
109
|
|
|
155
|
-
button
|
|
156
|
-
|
|
157
|
-
|
|
110
|
+
button.danger {
|
|
111
|
+
background: transparent;
|
|
112
|
+
border: 1px solid var(--danger);
|
|
113
|
+
color: var(--danger);
|
|
158
114
|
}
|
|
159
115
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
116
|
+
button.danger:hover { background: rgba(214, 69, 69, 0.12); }
|
|
117
|
+
|
|
118
|
+
button:disabled { cursor: not-allowed; opacity: 0.55; }
|
|
119
|
+
|
|
120
|
+
a { color: var(--accent); text-decoration: none; }
|
|
121
|
+
a:hover { text-decoration: underline; }
|
|
122
|
+
|
|
123
|
+
.status {
|
|
164
124
|
border-radius: 6px;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
min-height: 40px;
|
|
168
|
-
padding: 8px 10px;
|
|
169
|
-
width: 100%;
|
|
125
|
+
display: none;
|
|
126
|
+
padding: 12px 14px;
|
|
170
127
|
}
|
|
171
128
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
129
|
+
.status.error { background: #2b1515; border: 1px solid var(--danger); color: #ffb7b7; display: block; }
|
|
130
|
+
.status.success { background: #162718; border: 1px solid var(--success); color: #bdedc7; display: block; }
|
|
131
|
+
.status.info { background: #1a2433; border: 1px solid #426da9; color: #c6ddff; display: block; }
|
|
132
|
+
|
|
133
|
+
/* Device cards */
|
|
134
|
+
.device-card {
|
|
135
|
+
background: var(--panel-soft);
|
|
136
|
+
border: 1px solid var(--border);
|
|
137
|
+
border-radius: 8px;
|
|
138
|
+
margin-bottom: 10px;
|
|
177
139
|
}
|
|
178
140
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
141
|
+
.device-card-header {
|
|
142
|
+
align-items: center;
|
|
143
|
+
cursor: pointer;
|
|
144
|
+
display: flex;
|
|
145
|
+
gap: 10px;
|
|
146
|
+
padding: 12px 14px;
|
|
183
147
|
}
|
|
184
148
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
149
|
+
.device-card-header .device-name {
|
|
150
|
+
flex: 1;
|
|
151
|
+
font-weight: 650;
|
|
152
|
+
overflow: hidden;
|
|
153
|
+
text-overflow: ellipsis;
|
|
154
|
+
white-space: nowrap;
|
|
188
155
|
}
|
|
189
156
|
|
|
190
|
-
|
|
191
|
-
|
|
157
|
+
.proto-badge {
|
|
158
|
+
background: #333;
|
|
159
|
+
border-radius: 4px;
|
|
160
|
+
color: var(--muted);
|
|
161
|
+
font-size: 12px;
|
|
162
|
+
padding: 2px 8px;
|
|
163
|
+
white-space: nowrap;
|
|
192
164
|
}
|
|
193
165
|
|
|
194
|
-
.
|
|
195
|
-
border-
|
|
196
|
-
|
|
197
|
-
padding: 12px 14px;
|
|
166
|
+
.device-card-body {
|
|
167
|
+
border-top: 1px solid var(--border);
|
|
168
|
+
padding: 14px;
|
|
198
169
|
}
|
|
199
170
|
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
171
|
+
.section-title {
|
|
172
|
+
color: var(--muted);
|
|
173
|
+
font-size: 13px;
|
|
174
|
+
font-weight: 650;
|
|
175
|
+
letter-spacing: 0.04em;
|
|
176
|
+
margin: 16px 0 10px;
|
|
177
|
+
text-transform: uppercase;
|
|
205
178
|
}
|
|
206
179
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
180
|
+
details summary {
|
|
181
|
+
color: var(--muted);
|
|
182
|
+
cursor: pointer;
|
|
183
|
+
font-size: 13px;
|
|
184
|
+
font-weight: 650;
|
|
185
|
+
letter-spacing: 0.04em;
|
|
186
|
+
list-style: none;
|
|
187
|
+
margin: 16px 0 10px;
|
|
188
|
+
text-transform: uppercase;
|
|
212
189
|
}
|
|
213
190
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
191
|
+
details summary::before { content: '▶ '; }
|
|
192
|
+
details[open] summary::before { content: '▼ '; }
|
|
193
|
+
|
|
194
|
+
.empty-state {
|
|
195
|
+
background: var(--panel-soft);
|
|
196
|
+
border: 1px dashed #555;
|
|
197
|
+
border-radius: 8px;
|
|
198
|
+
color: var(--muted);
|
|
199
|
+
padding: 18px;
|
|
200
|
+
text-align: center;
|
|
219
201
|
}
|
|
220
202
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
padding: 16px;
|
|
224
|
-
}
|
|
203
|
+
.airplus-step { display: none; }
|
|
204
|
+
.airplus-step.active { display: block; }
|
|
225
205
|
|
|
226
|
-
|
|
227
|
-
grid-template-columns: 1fr;
|
|
228
|
-
}
|
|
206
|
+
.airplus-device-grid { display: grid; gap: 10px; }
|
|
229
207
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
208
|
+
.airplus-device-card {
|
|
209
|
+
align-items: center;
|
|
210
|
+
background: var(--panel-soft);
|
|
211
|
+
border: 1px solid var(--border);
|
|
212
|
+
border-radius: 8px;
|
|
213
|
+
display: grid;
|
|
214
|
+
gap: 12px;
|
|
215
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
216
|
+
padding: 14px;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.meta { color: var(--muted); font-size: 13px; }
|
|
220
|
+
|
|
221
|
+
@media (max-width: 640px) {
|
|
222
|
+
body { padding: 16px; }
|
|
223
|
+
.field-row { grid-template-columns: 1fr; }
|
|
224
|
+
.airplus-device-card { grid-template-columns: 1fr; }
|
|
233
225
|
}
|
|
234
226
|
</style>
|
|
235
227
|
</head>
|
|
@@ -241,16 +233,40 @@
|
|
|
241
233
|
|
|
242
234
|
<div id="status" class="status"></div>
|
|
243
235
|
|
|
244
|
-
|
|
236
|
+
<!-- Platform name -->
|
|
237
|
+
<div class="panel">
|
|
238
|
+
<div class="field">
|
|
239
|
+
<label for="platform-name">Platform Name</label>
|
|
240
|
+
<input id="platform-name" type="text" value="Philips Air Purifiers">
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<!-- Device list -->
|
|
245
|
+
<div class="panel">
|
|
246
|
+
<h2>Devices</h2>
|
|
247
|
+
<div id="device-list"></div>
|
|
248
|
+
<div class="toolbar" style="margin-top: 10px; margin-bottom: 0;">
|
|
249
|
+
<button id="add-device-btn" type="button" class="secondary">+ Add Device</button>
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
|
|
253
|
+
<!-- Air+ Cloud -->
|
|
254
|
+
<div class="panel">
|
|
245
255
|
<h2>Air+ Cloud</h2>
|
|
256
|
+
<p style="color: var(--muted); font-size: 13px; margin-bottom: 12px;">
|
|
257
|
+
Use this to add devices from a Philips Air+ cloud account. Your purifier must be registered in the Philips Air+ app.
|
|
258
|
+
</p>
|
|
246
259
|
<div class="toolbar">
|
|
247
|
-
<button id="airplus-start" type="button">Login with Air
|
|
260
|
+
<button id="airplus-start" type="button">Login with Air+</button>
|
|
248
261
|
</div>
|
|
249
262
|
|
|
250
263
|
<div id="airplus-flow" hidden>
|
|
251
264
|
<div id="airplus-step-1" class="airplus-step">
|
|
252
|
-
<p><a id="auth-link" href="#" target="_blank" rel="noopener">Open Philips login</a
|
|
253
|
-
<
|
|
265
|
+
<p><a id="auth-link" href="#" target="_blank" rel="noopener">Open Philips login page</a> — then paste the redirect URL below.</p>
|
|
266
|
+
<div class="field">
|
|
267
|
+
<label for="redirect-url">Redirect URL</label>
|
|
268
|
+
<textarea id="redirect-url" placeholder="com.philips.air://loginredirect?code=..."></textarea>
|
|
269
|
+
</div>
|
|
254
270
|
<div class="toolbar">
|
|
255
271
|
<button id="airplus-continue" type="button">Continue</button>
|
|
256
272
|
<button class="secondary" type="button" data-airplus-cancel>Cancel</button>
|
|
@@ -258,69 +274,340 @@
|
|
|
258
274
|
</div>
|
|
259
275
|
|
|
260
276
|
<div id="airplus-step-2" class="airplus-step">
|
|
261
|
-
<div id="airplus-device-list" class="device-grid">
|
|
262
|
-
<div class="empty">Connecting
|
|
277
|
+
<div id="airplus-device-list" class="airplus-device-grid">
|
|
278
|
+
<div class="empty-state">Connecting…</div>
|
|
263
279
|
</div>
|
|
264
|
-
<div class="toolbar">
|
|
280
|
+
<div class="toolbar" style="margin-top: 10px;">
|
|
265
281
|
<button class="secondary" type="button" data-airplus-cancel>Cancel</button>
|
|
266
282
|
</div>
|
|
267
283
|
</div>
|
|
268
284
|
</div>
|
|
269
|
-
</
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
<!-- Save -->
|
|
288
|
+
<div class="toolbar">
|
|
289
|
+
<button id="save-btn" type="button">Save Changes</button>
|
|
290
|
+
</div>
|
|
270
291
|
</div>
|
|
271
292
|
|
|
272
293
|
<script>
|
|
273
294
|
const PLATFORM_ALIAS = 'PhilipsAirPurifier';
|
|
274
295
|
const DEFAULT_PLATFORM_NAME = 'Philips Air Purifiers';
|
|
275
296
|
|
|
276
|
-
|
|
297
|
+
// ---------- state ----------
|
|
298
|
+
let cardCount = 0; // monotonically incrementing card key (survives removals)
|
|
299
|
+
let platformConfig = {};
|
|
300
|
+
let migratedLegacyDevices = false;
|
|
277
301
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
302
|
+
// ---------- status ----------
|
|
303
|
+
function showStatus(msg, type) {
|
|
304
|
+
const el = document.getElementById('status');
|
|
305
|
+
el.className = 'status ' + (type || 'info');
|
|
306
|
+
el.textContent = msg;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function hideStatus() {
|
|
310
|
+
const el = document.getElementById('status');
|
|
311
|
+
el.className = 'status';
|
|
312
|
+
el.textContent = '';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ---------- escaping ----------
|
|
316
|
+
function escHtml(v) {
|
|
317
|
+
return String(v == null ? '' : v)
|
|
318
|
+
.replace(/&/g, '&').replace(/</g, '<')
|
|
319
|
+
.replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ---------- protocol helpers ----------
|
|
323
|
+
const PROTOCOLS = [
|
|
324
|
+
{ value: 'coap', label: 'CoAP local' },
|
|
325
|
+
{ value: 'http', label: 'HTTP DH/AES local' },
|
|
326
|
+
{ value: 'homeid-http', label: 'HomeID local HTTP' },
|
|
327
|
+
{ value: 'airplus-cloud',label: 'Air+ Cloud' },
|
|
328
|
+
];
|
|
329
|
+
|
|
330
|
+
function protocolLabel(v) {
|
|
331
|
+
return (PROTOCOLS.find(p => p.value === v) || PROTOCOLS[0]).label;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function protocolOptions(selected) {
|
|
335
|
+
return PROTOCOLS.map(p =>
|
|
336
|
+
`<option value="${p.value}"${p.value === selected ? ' selected' : ''}>${escHtml(p.label)}</option>`
|
|
337
|
+
).join('');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ---------- device card rendering ----------
|
|
341
|
+
function createCard(device, key) {
|
|
342
|
+
const proto = device.protocol || 'coap';
|
|
343
|
+
const isAir = proto === 'airplus-cloud';
|
|
344
|
+
const isHid = proto === 'homeid-http';
|
|
345
|
+
const nameVal = escHtml(device.name || '');
|
|
346
|
+
const hostVal = escHtml(device.host || '');
|
|
347
|
+
const cidVal = escHtml(device.clientId || '');
|
|
348
|
+
const csecVal = escHtml(device.clientSecret|| '');
|
|
349
|
+
const encVal = escHtml(device.encryptionKey|| '');
|
|
350
|
+
const uuidVal = escHtml(device.airplusDeviceUuid || '');
|
|
351
|
+
const tokVal = escHtml(device.airplusTokenFile || '');
|
|
352
|
+
const pyVal = escHtml(device.pythonPath || '');
|
|
353
|
+
const apiVal = escHtml(device.apiScriptPath|| '');
|
|
354
|
+
|
|
355
|
+
const card = document.createElement('div');
|
|
356
|
+
card.className = 'device-card';
|
|
357
|
+
card.dataset.key = key;
|
|
358
|
+
|
|
359
|
+
card.innerHTML = `
|
|
360
|
+
<div class="device-card-header" data-toggle="true">
|
|
361
|
+
<span class="device-name">${nameVal || 'New Device'}</span>
|
|
362
|
+
<span class="proto-badge">${escHtml(protocolLabel(proto))}</span>
|
|
363
|
+
<button type="button" class="danger" data-remove style="min-height:30px;padding:4px 10px;font-size:13px;">Remove</button>
|
|
364
|
+
</div>
|
|
365
|
+
<div class="device-card-body">
|
|
366
|
+
<div class="field-row">
|
|
367
|
+
<div class="field">
|
|
368
|
+
<label>Name <span style="color:var(--danger)">*</span></label>
|
|
369
|
+
<input type="text" data-field="name" value="${nameVal}" required>
|
|
370
|
+
</div>
|
|
371
|
+
<div class="field">
|
|
372
|
+
<label>Protocol</label>
|
|
373
|
+
<select data-field="protocol">${protocolOptions(proto)}</select>
|
|
374
|
+
</div>
|
|
375
|
+
</div>
|
|
376
|
+
|
|
377
|
+
<div class="field" data-section="local">
|
|
378
|
+
<label>IP Address</label>
|
|
379
|
+
<input type="text" data-field="host" value="${hostVal}" placeholder="192.168.1.100">
|
|
380
|
+
</div>
|
|
381
|
+
|
|
382
|
+
<div data-section="homeid"${isHid ? '' : ' hidden'}>
|
|
383
|
+
<div class="section-title">HomeID Local HTTP</div>
|
|
384
|
+
<div class="checkbox-row field">
|
|
385
|
+
<input type="checkbox" data-field="useHttps" id="useHttps-${key}"${device.useHttps ? ' checked' : ''}>
|
|
386
|
+
<label for="useHttps-${key}">Use HTTPS (for self-signed certificates)</label>
|
|
387
|
+
</div>
|
|
388
|
+
<div class="field-row">
|
|
389
|
+
<div class="field">
|
|
390
|
+
<label>Client ID</label>
|
|
391
|
+
<input type="password" data-field="clientId" value="${cidVal}" autocomplete="new-password">
|
|
392
|
+
</div>
|
|
393
|
+
<div class="field">
|
|
394
|
+
<label>Client Secret</label>
|
|
395
|
+
<input type="password" data-field="clientSecret" value="${csecVal}" autocomplete="new-password">
|
|
396
|
+
</div>
|
|
397
|
+
</div>
|
|
398
|
+
<div class="field">
|
|
399
|
+
<label>Encryption Key (hex, optional)</label>
|
|
400
|
+
<input type="text" data-field="encryptionKey" value="${encVal}">
|
|
401
|
+
</div>
|
|
402
|
+
</div>
|
|
403
|
+
|
|
404
|
+
<div data-section="airplus"${isAir ? '' : ' hidden'}>
|
|
405
|
+
<div class="section-title">Air+ Cloud</div>
|
|
406
|
+
<div class="field">
|
|
407
|
+
<label>Device UUID</label>
|
|
408
|
+
<input type="text" data-field="airplusDeviceUuid" value="${uuidVal}" placeholder="Filled automatically by Login with Air+">
|
|
409
|
+
</div>
|
|
410
|
+
<div class="field">
|
|
411
|
+
<label>Token File Path</label>
|
|
412
|
+
<input type="text" data-field="airplusTokenFile" value="${tokVal}" placeholder="~/.homebridge/philips-airplus-{uuid}.json">
|
|
413
|
+
</div>
|
|
414
|
+
</div>
|
|
415
|
+
|
|
416
|
+
<details>
|
|
417
|
+
<summary>Advanced</summary>
|
|
418
|
+
<div class="field">
|
|
419
|
+
<label>Python Path</label>
|
|
420
|
+
<input type="text" data-field="pythonPath" value="${pyVal}" placeholder="Auto-detected">
|
|
421
|
+
</div>
|
|
422
|
+
<div class="field">
|
|
423
|
+
<label>API Script Path</label>
|
|
424
|
+
<input type="text" data-field="apiScriptPath" value="${apiVal}" placeholder="Bundled philips_air_api.py">
|
|
425
|
+
</div>
|
|
426
|
+
</details>
|
|
427
|
+
</div>
|
|
428
|
+
`;
|
|
429
|
+
|
|
430
|
+
// Local section visibility (hidden for Air+)
|
|
431
|
+
if (isAir) card.querySelector('[data-section="local"]').hidden = true;
|
|
432
|
+
|
|
433
|
+
// Toggle header click
|
|
434
|
+
card.querySelector('.device-card-header').addEventListener('click', (e) => {
|
|
435
|
+
if (e.target.closest('[data-remove]')) return;
|
|
436
|
+
const body = card.querySelector('.device-card-body');
|
|
437
|
+
body.hidden = !body.hidden;
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
// Protocol change
|
|
441
|
+
card.querySelector('[data-field="protocol"]').addEventListener('change', (e) => {
|
|
442
|
+
const p = e.target.value;
|
|
443
|
+
card.querySelector('[data-section="local"]').hidden = (p === 'airplus-cloud');
|
|
444
|
+
card.querySelector('[data-section="homeid"]').hidden = (p !== 'homeid-http');
|
|
445
|
+
card.querySelector('[data-section="airplus"]').hidden = (p !== 'airplus-cloud');
|
|
446
|
+
// Update badge
|
|
447
|
+
card.querySelector('.proto-badge').textContent = protocolLabel(p);
|
|
282
448
|
});
|
|
449
|
+
|
|
450
|
+
// Name change → update header
|
|
451
|
+
card.querySelector('[data-field="name"]').addEventListener('input', (e) => {
|
|
452
|
+
card.querySelector('.device-name').textContent = e.target.value || 'New Device';
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// Remove button
|
|
456
|
+
card.querySelector('[data-remove]').addEventListener('click', () => {
|
|
457
|
+
card.remove();
|
|
458
|
+
updateEmptyState();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
return card;
|
|
283
462
|
}
|
|
284
463
|
|
|
285
|
-
function
|
|
286
|
-
|
|
464
|
+
function addDeviceCard(device) {
|
|
465
|
+
const key = cardCount++;
|
|
466
|
+
const card = createCard(device, key);
|
|
467
|
+
document.getElementById('device-list').appendChild(card);
|
|
468
|
+
|
|
469
|
+
// Show empty state toggle
|
|
470
|
+
document.getElementById('empty-state').hidden = true;
|
|
287
471
|
}
|
|
288
472
|
|
|
289
|
-
function
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
473
|
+
function updateEmptyState() {
|
|
474
|
+
const emptyState = document.getElementById('empty-state');
|
|
475
|
+
emptyState.hidden = document.querySelectorAll('#device-list .device-card').length > 0;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function collectDevices() {
|
|
479
|
+
const cards = document.querySelectorAll('#device-list .device-card');
|
|
480
|
+
const devices = [];
|
|
481
|
+
for (const card of cards) {
|
|
482
|
+
const get = (field) => card.querySelector(`[data-field="${field}"]`);
|
|
483
|
+
const val = (field) => { const el = get(field); return el ? el.value.trim() : ''; };
|
|
484
|
+
const bool = (field) => { const el = get(field); return el ? el.checked : false; };
|
|
485
|
+
|
|
486
|
+
const proto = val('protocol') || 'coap';
|
|
487
|
+
const device = { name: val('name'), protocol: proto };
|
|
488
|
+
|
|
489
|
+
if (proto !== 'airplus-cloud') {
|
|
490
|
+
if (val('host')) device.host = val('host');
|
|
491
|
+
}
|
|
492
|
+
if (proto === 'homeid-http') {
|
|
493
|
+
device.useHttps = bool('useHttps');
|
|
494
|
+
if (val('clientId')) device.clientId = val('clientId');
|
|
495
|
+
if (val('clientSecret')) device.clientSecret = val('clientSecret');
|
|
496
|
+
if (val('encryptionKey')) device.encryptionKey = val('encryptionKey');
|
|
497
|
+
}
|
|
498
|
+
if (proto === 'airplus-cloud') {
|
|
499
|
+
if (val('airplusDeviceUuid')) device.airplusDeviceUuid = val('airplusDeviceUuid');
|
|
500
|
+
if (val('airplusTokenFile')) device.airplusTokenFile = val('airplusTokenFile');
|
|
501
|
+
}
|
|
502
|
+
if (val('pythonPath')) device.pythonPath = val('pythonPath');
|
|
503
|
+
if (val('apiScriptPath')) device.apiScriptPath = val('apiScriptPath');
|
|
504
|
+
|
|
505
|
+
devices.push(device);
|
|
295
506
|
}
|
|
296
|
-
|
|
297
|
-
|
|
507
|
+
return devices;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// ---------- config load / save ----------
|
|
511
|
+
async function loadConfig() {
|
|
512
|
+
const configs = await homebridge.getPluginConfig();
|
|
513
|
+
const config = configs[0] || {};
|
|
514
|
+
platformConfig = { ...config };
|
|
515
|
+
migratedLegacyDevices = false;
|
|
516
|
+
|
|
517
|
+
document.getElementById('platform-name').value =
|
|
518
|
+
config.name || DEFAULT_PLATFORM_NAME;
|
|
519
|
+
|
|
520
|
+
const rawDevices = Array.isArray(config.devices) ? config.devices : [];
|
|
521
|
+
|
|
522
|
+
// Also merge legacy additionalDevicesJson (back-compat, read-only migration)
|
|
523
|
+
let extra = [];
|
|
524
|
+
if (config.additionalDevicesJson) {
|
|
525
|
+
try { extra = JSON.parse(config.additionalDevicesJson); } catch (_) { /**/ }
|
|
298
526
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const formConfig = latestSchemaConfig || persisted;
|
|
306
|
-
const devices = Array.isArray(formConfig.devices)
|
|
307
|
-
? formConfig.devices
|
|
308
|
-
: Array.isArray(persisted.devices)
|
|
309
|
-
? persisted.devices
|
|
310
|
-
: [];
|
|
311
|
-
const config = {
|
|
312
|
-
...persisted,
|
|
313
|
-
...formConfig,
|
|
314
|
-
platform: PLATFORM_ALIAS,
|
|
315
|
-
name: formConfig.name || persisted.name || DEFAULT_PLATFORM_NAME,
|
|
316
|
-
devices: devices.map((device) => ({ ...device })),
|
|
527
|
+
if (!Array.isArray(extra)) extra = [];
|
|
528
|
+
|
|
529
|
+
// Match index.js merge semantics, then migrate legacy JSON into devices[] on save.
|
|
530
|
+
const deviceKey = (d) => {
|
|
531
|
+
if (!d || typeof d !== 'object' || Array.isArray(d)) return '';
|
|
532
|
+
return d.airplusDeviceUuid ? `airplus:${d.airplusDeviceUuid}` : d.host ? `host:${d.host}` : '';
|
|
317
533
|
};
|
|
534
|
+
const allDevs = [];
|
|
535
|
+
const byKey = new Map();
|
|
536
|
+
for (const device of [...rawDevices, ...extra]) {
|
|
537
|
+
if (!device || typeof device !== 'object' || Array.isArray(device)) continue;
|
|
538
|
+
const key = deviceKey(device);
|
|
539
|
+
if (key && byKey.has(key)) {
|
|
540
|
+
allDevs[byKey.get(key)] = device;
|
|
541
|
+
} else {
|
|
542
|
+
if (key) byKey.set(key, allDevs.length);
|
|
543
|
+
allDevs.push(device);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
migratedLegacyDevices = extra.length > 0;
|
|
547
|
+
|
|
548
|
+
const emptyState = document.getElementById('empty-state');
|
|
549
|
+
emptyState.hidden = allDevs.length > 0;
|
|
550
|
+
|
|
551
|
+
for (const d of allDevs) addDeviceCard(d);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
async function saveConfig() {
|
|
555
|
+
const btn = document.getElementById('save-btn');
|
|
556
|
+
btn.disabled = true;
|
|
557
|
+
hideStatus();
|
|
318
558
|
|
|
319
|
-
|
|
320
|
-
|
|
559
|
+
try {
|
|
560
|
+
const name = document.getElementById('platform-name').value.trim() || DEFAULT_PLATFORM_NAME;
|
|
561
|
+
const devices = collectDevices();
|
|
562
|
+
|
|
563
|
+
// Validate: all devices need a name
|
|
564
|
+
const unnamed = devices.findIndex(d => !d.name);
|
|
565
|
+
if (unnamed >= 0) {
|
|
566
|
+
showStatus(`Device ${unnamed + 1} is missing a name.`, 'error');
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const config = { ...platformConfig, platform: PLATFORM_ALIAS, name, devices };
|
|
571
|
+
if (migratedLegacyDevices) delete config.additionalDevicesJson;
|
|
572
|
+
await homebridge.updatePluginConfig([config]);
|
|
573
|
+
platformConfig = { ...config };
|
|
574
|
+
migratedLegacyDevices = false;
|
|
575
|
+
showStatus('Applied. Click SAVE at the bottom to persist.', 'success');
|
|
576
|
+
homebridge.savePluginConfig().catch(() => { /* native SAVE button will persist */ });
|
|
577
|
+
} catch (err) {
|
|
578
|
+
showStatus('Save failed: ' + (err.message || String(err)), 'error');
|
|
579
|
+
} finally {
|
|
580
|
+
btn.disabled = false;
|
|
321
581
|
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// ---------- Air+ OAuth ----------
|
|
585
|
+
function req(path, body) {
|
|
586
|
+
return homebridge.request(path, body || {}).catch((err) => {
|
|
587
|
+
showStatus(err.message || String(err), 'error');
|
|
588
|
+
throw err;
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
let airplusBusy = false;
|
|
593
|
+
|
|
594
|
+
function setAirplusBusy(v) {
|
|
595
|
+
airplusBusy = v;
|
|
596
|
+
document.getElementById('airplus-start').disabled = v;
|
|
597
|
+
document.getElementById('airplus-continue').disabled = v;
|
|
598
|
+
document.querySelectorAll('[data-airplus-add]').forEach(b => { b.disabled = v; });
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function setAirplusStep(n) {
|
|
602
|
+
document.querySelectorAll('.airplus-step').forEach(el => el.classList.remove('active'));
|
|
603
|
+
document.getElementById('airplus-step-' + n).classList.add('active');
|
|
604
|
+
}
|
|
322
605
|
|
|
323
|
-
|
|
606
|
+
function closeAirplusFlow(showMsg) {
|
|
607
|
+
document.getElementById('airplus-flow').hidden = true;
|
|
608
|
+
document.getElementById('redirect-url').value = '';
|
|
609
|
+
document.getElementById('airplus-device-list').innerHTML = '<div class="empty-state">Connecting…</div>';
|
|
610
|
+
if (showMsg) showStatus('Air+ setup cancelled.', 'info');
|
|
324
611
|
}
|
|
325
612
|
|
|
326
613
|
async function startAirplusSetup() {
|
|
@@ -329,15 +616,13 @@
|
|
|
329
616
|
document.getElementById('airplus-flow').hidden = false;
|
|
330
617
|
setAirplusStep(1);
|
|
331
618
|
|
|
332
|
-
const
|
|
619
|
+
const authWin = window.open('about:blank', '_blank');
|
|
333
620
|
try {
|
|
334
621
|
const result = await req('/auth/init');
|
|
335
622
|
document.getElementById('auth-link').href = result.url;
|
|
336
|
-
if (
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
} catch (_error) {
|
|
340
|
-
if (authWindow) authWindow.close();
|
|
623
|
+
if (authWin) authWin.location = result.url;
|
|
624
|
+
} catch (_) {
|
|
625
|
+
if (authWin) authWin.close();
|
|
341
626
|
closeAirplusFlow(false);
|
|
342
627
|
} finally {
|
|
343
628
|
setAirplusBusy(false);
|
|
@@ -353,12 +638,12 @@
|
|
|
353
638
|
|
|
354
639
|
setAirplusBusy(true);
|
|
355
640
|
setAirplusStep(2);
|
|
356
|
-
document.getElementById('airplus-device-list').innerHTML = '<div class="empty">Connecting
|
|
641
|
+
document.getElementById('airplus-device-list').innerHTML = '<div class="empty-state">Connecting…</div>';
|
|
357
642
|
|
|
358
643
|
try {
|
|
359
644
|
const result = await req('/auth/exchange', { redirectUrl });
|
|
360
645
|
renderAirplusDevices(result.devices || []);
|
|
361
|
-
} catch (
|
|
646
|
+
} catch (_) {
|
|
362
647
|
setAirplusStep(1);
|
|
363
648
|
} finally {
|
|
364
649
|
setAirplusBusy(false);
|
|
@@ -368,141 +653,76 @@
|
|
|
368
653
|
function renderAirplusDevices(devices) {
|
|
369
654
|
const container = document.getElementById('airplus-device-list');
|
|
370
655
|
if (!devices.length) {
|
|
371
|
-
container.innerHTML = '<div class="empty">No Air+ devices found on this account.</div>';
|
|
656
|
+
container.innerHTML = '<div class="empty-state">No Air+ devices found on this account.</div>';
|
|
372
657
|
return;
|
|
373
658
|
}
|
|
374
659
|
|
|
375
|
-
container.innerHTML = devices
|
|
376
|
-
.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
.join('');
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
async function saveAirplusDevice(uuid, index) {
|
|
395
|
-
if (!uuid) {
|
|
396
|
-
showStatus('Air+ device UUID is missing.', 'error');
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
660
|
+
container.innerHTML = devices.map((d, i) => {
|
|
661
|
+
const uuid = escHtml(d.uuid || '');
|
|
662
|
+
const name = escHtml(d.name || 'Philips Air Purifier');
|
|
663
|
+
const model = escHtml(d.modelName || d.uuid || 'Air+ device');
|
|
664
|
+
return `<div class="airplus-device-card">
|
|
665
|
+
<div>
|
|
666
|
+
<h3>${escHtml(d.name || 'Philips Air Purifier')}</h3>
|
|
667
|
+
<div class="meta">${model}</div>
|
|
668
|
+
<input type="text" id="airplus-name-${i}" value="${name}" style="margin-top:8px">
|
|
669
|
+
</div>
|
|
670
|
+
<div>
|
|
671
|
+
<button type="button" data-airplus-add data-uuid="${uuid}" data-idx="${i}">Add Device</button>
|
|
672
|
+
</div>
|
|
673
|
+
</div>`;
|
|
674
|
+
}).join('');
|
|
675
|
+
}
|
|
399
676
|
|
|
400
|
-
|
|
401
|
-
|
|
677
|
+
async function saveAirplusDevice(uuid, idx) {
|
|
678
|
+
if (!uuid) { showStatus('Air+ device UUID is missing.', 'error'); return; }
|
|
679
|
+
const nameEl = document.getElementById('airplus-name-' + idx);
|
|
680
|
+
const name = nameEl && nameEl.value.trim() ? nameEl.value.trim() : 'Philips Air Purifier';
|
|
402
681
|
|
|
403
682
|
setAirplusBusy(true);
|
|
404
683
|
try {
|
|
405
684
|
const result = await req('/auth/save', { uuid, name });
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
685
|
+
addDeviceCard({
|
|
686
|
+
name: result.name || name,
|
|
687
|
+
protocol: 'airplus-cloud',
|
|
688
|
+
airplusDeviceUuid: result.uuid || uuid,
|
|
689
|
+
airplusTokenFile: result.tokenFile,
|
|
410
690
|
});
|
|
411
691
|
closeAirplusFlow(false);
|
|
412
|
-
showStatus('Air+ device added
|
|
692
|
+
showStatus('Air+ device added — click Save Changes to persist it.', 'success');
|
|
413
693
|
} finally {
|
|
414
694
|
setAirplusBusy(false);
|
|
415
695
|
}
|
|
416
696
|
}
|
|
417
697
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
name: device.name || 'Philips Air Purifier',
|
|
422
|
-
host: 'cloud',
|
|
423
|
-
protocol: 'airplus-cloud',
|
|
424
|
-
airplusDeviceUuid: device.uuid,
|
|
425
|
-
airplusTokenFile: device.tokenFile,
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
const existingIndex = config.devices.findIndex((candidate) => candidate.airplusDeviceUuid === device.uuid);
|
|
429
|
-
if (existingIndex >= 0) {
|
|
430
|
-
config.devices[existingIndex] = {
|
|
431
|
-
...config.devices[existingIndex],
|
|
432
|
-
...airplusDevice,
|
|
433
|
-
};
|
|
434
|
-
} else {
|
|
435
|
-
config.devices.push(airplusDevice);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
latestSchemaConfig = config;
|
|
439
|
-
await homebridge.updatePluginConfig([config]);
|
|
440
|
-
renderSchemaForm();
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function closeAirplusFlow(showMessage) {
|
|
444
|
-
document.getElementById('airplus-flow').hidden = true;
|
|
445
|
-
document.getElementById('redirect-url').value = '';
|
|
446
|
-
document.getElementById('airplus-device-list').innerHTML = '<div class="empty">Connecting...</div>';
|
|
447
|
-
if (showMessage) showStatus('Air+ setup cancelled.', 'info');
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function setAirplusStep(step) {
|
|
451
|
-
document.querySelectorAll('.airplus-step').forEach((element) => element.classList.remove('active'));
|
|
452
|
-
document.getElementById('airplus-step-' + step).classList.add('active');
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
function setAirplusBusy(isBusy) {
|
|
456
|
-
document.getElementById('airplus-start').disabled = isBusy;
|
|
457
|
-
document.getElementById('airplus-continue').disabled = isBusy;
|
|
458
|
-
document
|
|
459
|
-
.querySelectorAll('[data-airplus-uuid]')
|
|
460
|
-
.forEach((button) => {
|
|
461
|
-
button.disabled = isBusy;
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function showStatus(message, type) {
|
|
466
|
-
const status = document.getElementById('status');
|
|
467
|
-
status.className = 'status ' + (type || 'info');
|
|
468
|
-
status.textContent = message;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function hideStatus() {
|
|
472
|
-
const status = document.getElementById('status');
|
|
473
|
-
status.className = 'status';
|
|
474
|
-
status.textContent = '';
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function escHtml(value) {
|
|
478
|
-
return String(value)
|
|
479
|
-
.replace(/&/g, '&')
|
|
480
|
-
.replace(/</g, '<')
|
|
481
|
-
.replace(/>/g, '>')
|
|
482
|
-
.replace(/"/g, '"')
|
|
483
|
-
.replace(/'/g, ''');
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function escAttr(value) {
|
|
487
|
-
return escHtml(value);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
window.homebridge.addEventListener('configChanged', (event) => {
|
|
491
|
-
latestSchemaConfig = normaliseConfigPayload(event.data);
|
|
698
|
+
// ---------- init ----------
|
|
699
|
+
document.getElementById('add-device-btn').addEventListener('click', () => {
|
|
700
|
+
addDeviceCard({ name: '', protocol: 'coap' });
|
|
492
701
|
});
|
|
493
702
|
|
|
703
|
+
document.getElementById('save-btn').addEventListener('click', saveConfig);
|
|
704
|
+
|
|
494
705
|
document.getElementById('airplus-start').addEventListener('click', startAirplusSetup);
|
|
495
706
|
document.getElementById('airplus-continue').addEventListener('click', exchangeAirplusCode);
|
|
496
|
-
|
|
497
|
-
|
|
707
|
+
|
|
708
|
+
document.querySelectorAll('[data-airplus-cancel]').forEach(b => {
|
|
709
|
+
b.addEventListener('click', () => closeAirplusFlow(true));
|
|
498
710
|
});
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
711
|
+
|
|
712
|
+
document.getElementById('airplus-device-list').addEventListener('click', (e) => {
|
|
713
|
+
const btn = e.target.closest('[data-airplus-add]');
|
|
714
|
+
if (!btn) return;
|
|
715
|
+
saveAirplusDevice(btn.dataset.uuid, Number(btn.dataset.idx));
|
|
503
716
|
});
|
|
504
717
|
|
|
505
|
-
|
|
718
|
+
// Insert empty-state placeholder inside device-list
|
|
719
|
+
const emptyState = document.createElement('div');
|
|
720
|
+
emptyState.id = 'empty-state';
|
|
721
|
+
emptyState.className = 'empty-state';
|
|
722
|
+
emptyState.textContent = 'No devices configured. Click "+ Add Device" to add your first purifier.';
|
|
723
|
+
document.getElementById('device-list').appendChild(emptyState);
|
|
724
|
+
|
|
725
|
+
loadConfig().catch(err => showStatus('Failed to load config: ' + err.message, 'error'));
|
|
506
726
|
</script>
|
|
507
727
|
</body>
|
|
508
728
|
</html>
|
package/index.js
CHANGED
|
@@ -649,7 +649,7 @@ class PhilipsAirPurifierAccessory {
|
|
|
649
649
|
this.updatePurifierCharacteristics();
|
|
650
650
|
});
|
|
651
651
|
|
|
652
|
-
this.purifierService.
|
|
652
|
+
this.purifierService.getCharacteristic(Characteristic.RotationSpeed)
|
|
653
653
|
.onGet(() => MODE_TO_SPEED[this.state.mode] ?? 100)
|
|
654
654
|
.onSet(async (value) => {
|
|
655
655
|
this.log.info(`[SET] RotationSpeed: ${value}%`);
|
|
@@ -665,7 +665,7 @@ class PhilipsAirPurifierAccessory {
|
|
|
665
665
|
});
|
|
666
666
|
|
|
667
667
|
// Child Lock (LockPhysicalControls)
|
|
668
|
-
this.purifierService.
|
|
668
|
+
this.purifierService.getCharacteristic(Characteristic.LockPhysicalControls)
|
|
669
669
|
.onGet(() => this.state.childLock
|
|
670
670
|
? Characteristic.LockPhysicalControls.CONTROL_LOCK_ENABLED
|
|
671
671
|
: Characteristic.LockPhysicalControls.CONTROL_LOCK_DISABLED)
|
|
@@ -681,7 +681,7 @@ class PhilipsAirPurifierAccessory {
|
|
|
681
681
|
this.platformAcc.addService(Service.AirQualitySensor, 'Air Quality');
|
|
682
682
|
this.airQualitySensor.getCharacteristic(Characteristic.AirQuality)
|
|
683
683
|
.onGet(() => this.pm25ToAirQuality(this.state.pm25));
|
|
684
|
-
this.airQualitySensor.
|
|
684
|
+
this.airQualitySensor.getCharacteristic(Characteristic.PM2_5Density)
|
|
685
685
|
.onGet(() => this.state.pm25 || 0);
|
|
686
686
|
|
|
687
687
|
// HEPA Filter Maintenance
|
|
@@ -724,7 +724,7 @@ class PhilipsAirPurifierAccessory {
|
|
|
724
724
|
await this.executeCommand('light', [level.toString()], { lightLevel: level });
|
|
725
725
|
this.updateLightCharacteristics();
|
|
726
726
|
});
|
|
727
|
-
this.lightService.
|
|
727
|
+
this.lightService.getCharacteristic(Characteristic.Brightness)
|
|
728
728
|
.onGet(() => {
|
|
729
729
|
if (this.state.lightLevel === LIGHT.DIM) return 50;
|
|
730
730
|
if (this.state.lightLevel === LIGHT.OFF) return 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-philips-air-purifier-complete",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"customUi": true,
|
|
5
5
|
"description": "Homebridge plugin for Philips Air Purifier with bundled CoAP control library and Python 3.12+/Node.js 24 support",
|
|
6
6
|
"main": "index.js",
|