homebridge-philips-airplus-cloud 0.5.3 → 0.6.0-beta.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 +15 -0
- package/README.md +37 -2
- package/bin/philips-airplus-aircloud-probe.js +56 -0
- package/config.schema.json +27 -9
- package/package.json +8 -4
- package/src/accessory.js +105 -4
- package/src/aircloud.js +194 -0
- package/src/cloud.js +12 -2
- package/src/coap-models.js +118 -0
- package/src/coap.js +528 -0
- package/src/platform.js +42 -17
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
The Home Assistant integration in `custom_components/` is unchanged from upstream and keeps its own history.
|
|
4
4
|
|
|
5
|
+
## 0.6.0-beta.0 — 2026-11-29
|
|
6
|
+
|
|
7
|
+
- New: **local purifiers**. Purifiers that are not on the Philips cloud used by the plugin, such as the AC4236 (Series 4000i), can be added by IP address in Devices (`"host": "192.168.1.50", "model": "AC4236"`) and are controlled on the local network over encrypted CoAP, the protocol of aioairctrl. AC4236: power, Auto, Sleep, Speed 1, Speed 2, Turbo, PM2.5, allergen index, filter and pre-filter, display brightness and child lock. Other CoAP models get everything except fan speeds. No Philips login is needed for local purifiers. Not yet tested on a real AC4236.
|
|
8
|
+
- New: **child lock** ("Lock Physical Controls" in the purifier's settings in the Home app) on purifiers that report one: property `D03103` on Air+ cloud models, `cl` on local ones. Shown after the purifier first reports it; option `childLock` hides it.
|
|
9
|
+
- New option **Turn the display off with Sleep** (`sleepDisplayOff`, default off): turning Sleep on from HomeKit also turns the display off, and turning Sleep off restores its brightness. Only on purifiers that show the Display control.
|
|
10
|
+
- Beta: published on npm under the `beta` tag, so it is not installed by normal updates.
|
|
11
|
+
|
|
12
|
+
## 0.5.5 — 2026-11-29
|
|
13
|
+
|
|
14
|
+
- New diagnostic command `philips-airplus-aircloud-probe`: lists the purifiers on Philips' newer "Air+ cloud" — the one used by models the plugin does not find, such as the AC4236 — and what each one reports. It only reads, never sends commands, and hides identifiers, serial numbers, addresses and tokens so the output can be shared in an issue. First step towards supporting those models. No change to the plugin itself.
|
|
15
|
+
|
|
16
|
+
## 0.5.4 — 2026-11-23
|
|
17
|
+
|
|
18
|
+
- Diagnostics for accounts the Philips cloud refuses (HTTP 403 "explicit deny"): the login now logs the result of every step, including the fallback through the Philips HomeID app, and the startup warning explains how to run the login from a terminal to collect them. No change for working installations.
|
|
19
|
+
|
|
5
20
|
## 0.5.3 — 2026-11-21
|
|
6
21
|
|
|
7
22
|
- Fix: logging in from the settings panel failed with "Request a new code first" when the page was reloaded between "Send code" and "Log in" — typically on a phone, after switching to the mail app to read the code, because Homebridge UI then restarts the panel. The pending request is now kept by the page: after a reload the panel reopens on the code field and the code can still be verified.
|
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
Homebridge plugin for **Philips Air+** air purifiers (AC0650, AC0651, AC1715, PureProtect 3200i and others in the same family). It brings them into Apple Home through the Philips/Versuni **cloud**, with the same MQTT protocol used by the official Air+ app and Google Home. No local connection, IP address or port forwarding is needed.
|
|
15
15
|
|
|
16
|
+
Purifiers that are not on that cloud, such as the **AC4236** (Series 4000i), can be added by IP address and are then controlled on the local network (encrypted CoAP, the protocol of [aioairctrl](https://github.com/kongo09/aioairctrl)). See [Local purifiers](#local-purifiers-ac4236).
|
|
17
|
+
|
|
16
18
|
## A Homebridge port of a Home Assistant integration
|
|
17
19
|
|
|
18
20
|
This repository is a fork of [NikGro/philips-air-plus-homeassistant](https://github.com/NikGro/philips-air-plus-homeassistant), a Home Assistant integration that is itself based on [ShorMeneses/philips-airplus-homeassistant](https://github.com/ShorMeneses/philips-airplus-homeassistant). The fork ports that integration to Homebridge:
|
|
@@ -31,6 +33,7 @@ One accessory per purifier with:
|
|
|
31
33
|
- **Air Quality Sensor** — PM2.5 (µg/m³) and a HomeKit air-quality level derived from it.
|
|
32
34
|
- **Allergens** — on models that report the Philips allergen index (1–12): a second air quality sensor whose level follows the index (1 Excellent, 2–3 Good, 4–6 Fair, 7–9 Inferior, 10–12 Poor). HomeKit has no allergen or pollen reading of its own.
|
|
33
35
|
- **Filter Maintenance** — main filter and pre-filter (cleaning), with life level, change alert (below 10% by default) and reset from the Home app. The reset writes the same value the official app does.
|
|
36
|
+
- **Child lock** — "Lock Physical Controls" in the purifier's settings in the Home app, on purifiers that report a child lock (property `D03103` on the cloud, `cl` locally). It appears after the purifier first reports it.
|
|
34
37
|
|
|
35
38
|
State changes arrive in real time over MQTT; a status poll runs every 120 s as a safety net.
|
|
36
39
|
|
|
@@ -87,21 +90,51 @@ The refresh token rotates on every use; the plugin keeps the current one in `<ho
|
|
|
87
90
|
|
|
88
91
|
| Key | Default | Meaning |
|
|
89
92
|
|---|---|---|
|
|
90
|
-
| `devices` | all | `[{ "uuid": "…", "name": "…", "model": "AC0651/10" }]` — pick/rename devices; `model` is only needed if auto-detection fails |
|
|
93
|
+
| `devices` | all | `[{ "uuid": "…", "name": "…", "model": "AC0651/10" }]` — pick/rename cloud devices; `model` is only needed if auto-detection fails. `[{ "host": "192.168.1.50", "name": "…", "model": "AC4236" }]` adds a local purifier |
|
|
91
94
|
| `airQualitySensor` | `true` | Show the PM2.5 sensor |
|
|
92
95
|
| `allergenSensor` | `true` | Show the allergen index as a second air quality sensor (models that report it) |
|
|
93
96
|
| `filterSensors` | `true` | Show filter and pre-filter status |
|
|
94
97
|
| `filterAlerts` | `false` | Add a contact sensor per filter that opens when it needs replacing / cleaning, so the Home app can notify you (turn on notifications for the sensors in Home) |
|
|
95
98
|
| `sleepSwitch` | `true` | Show the Sleep mode switch |
|
|
96
99
|
| `sleepSwitchStyle` | `switch` | `purifier` shows the Sleep control as a second air purifier (purifier icon in Home) that only turns Sleep on/off |
|
|
100
|
+
| `sleepDisplayOff` | `false` | Turning Sleep on from HomeKit also turns the display off; turning Sleep off restores its brightness (purifiers that show the Display control) |
|
|
97
101
|
| `linkComponents` | `false` | Link Sleep, air quality and filters to the purifier. Off: each gets its own labelled tile in the purifier's combined view. On: Home shows them as controls inside the purifier, without labels |
|
|
98
102
|
| `displayLight` | `true` | Show the display light |
|
|
103
|
+
| `childLock` | `true` | Show the child lock in the purifier's settings (purifiers that report one) |
|
|
99
104
|
| `displayLightProperty` | — | Property key of the display light, if it is not detected (see the `Status properties reported by the device` log line) |
|
|
100
105
|
| `logDeviceData` | `false` | Diagnostics: at startup, log every port and the cloud shadow the purifier publishes |
|
|
101
106
|
| `homekitIdentity` | — | Change to any new value to give the purifier a new HomeKit identity (use only if the Home app refuses to move or rename it; reassign the room afterwards) |
|
|
102
107
|
| `filterChangeThreshold` | `10` | Filter life (%) at or below which HomeKit shows "replace filter" |
|
|
103
108
|
| `pollInterval` | `120` | Seconds between safety-net status polls |
|
|
104
109
|
|
|
110
|
+
## Local purifiers (AC4236)
|
|
111
|
+
|
|
112
|
+
Some purifiers that appear in the Air+ app are not on the cloud this plugin uses, so they are not found after login. The AC2xxx/AC3xxx/AC4xxx generation can instead be controlled on the local network.
|
|
113
|
+
|
|
114
|
+
1. In your router, give the purifier a fixed IP address (DHCP reservation). The plugin finds it only by address.
|
|
115
|
+
2. In the plugin settings → **Devices** → **Add**, fill in **IP address (local)** with that address, a **Name**, and **Model** `AC4236`. Leave **Device UUID** empty. Save.
|
|
116
|
+
3. Restart Homebridge. The log shows `Connected locally to <address>` and one line `Local status reported by the device: {…}`.
|
|
117
|
+
|
|
118
|
+
Homebridge must be on the same network as the purifier (UDP port 5683). A Philips login is not needed for local purifiers; cloud and local purifiers can be used together.
|
|
119
|
+
|
|
120
|
+
| Model | Modes | Notes |
|
|
121
|
+
|---|---|---|
|
|
122
|
+
| AC4236 | Auto, Sleep, Speed 1, Speed 2, Turbo | Mapping from [kongo09/philips-airpurifier-coap](https://github.com/kongo09/philips-airpurifier-coap); **not yet tested on a real AC4236 with this plugin** — reports welcome. "Sleep allergy" and the other automatic modes chosen on the purifier show as Sleep and Auto |
|
|
123
|
+
| other CoAP models | — | Power, PM2.5, allergen index, filters, display and child lock; no fan speeds. Open an issue with the `Local status reported by the device` log line to get the speeds added |
|
|
124
|
+
|
|
125
|
+
Filter reset is not available for local purifiers: reset the counter on the purifier itself.
|
|
126
|
+
|
|
127
|
+
## Purifier not found?
|
|
128
|
+
|
|
129
|
+
Philips runs two clouds. This plugin uses the older one (DaConnect: AC0650, AC0651, AC1715…). Some purifiers that appear in the Air+ app live on the newer "Air+ cloud" instead and are not found: try adding them as [local purifiers](#local-purifiers-ac4236). To help add cloud support for yours, run this read-only check from a terminal on the Homebridge machine (Homebridge UI → ⋮ → Terminal) and paste the output into an issue:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
cd /var/lib/homebridge
|
|
133
|
+
npx philips-airplus-aircloud-probe you@example.com
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
It lists the purifiers on the Air+ cloud and what each one reports. It sends no commands and hides identifiers, serial numbers, addresses and tokens.
|
|
137
|
+
|
|
105
138
|
## Filter notifications
|
|
106
139
|
|
|
107
140
|
The Home app shows "Replace filter" inside the purifier but never sends a notification for it. With **Filter alerts** turned on, the plugin adds a contact sensor per filter that Home *can* notify about:
|
|
@@ -133,7 +166,7 @@ Each client uses its own MQTT client id (`…_hb` for Homebridge, `…_ha` for H
|
|
|
133
166
|
- The AC0651/10 does not expose its display brightness through the cloud (the Philips app has no control for it either; the display turns off by itself in Sleep), so no Display control appears for it.
|
|
134
167
|
- Models not in `models.yaml` still get on/off, PM2.5 and filters, and a warning in the log; modes need a `models.yaml` entry.
|
|
135
168
|
- The AC3221 (PureProtect 3200i) mapping is unverified (see below), and so is its speed order in HomeKit.
|
|
136
|
-
- `npm test` runs the plugin tests (protocol, HomeKit mapping, login flow with a mocked cloud).
|
|
169
|
+
- `npm test` runs the plugin tests (protocol, HomeKit mapping, login flow with a mocked cloud, local CoAP against a simulated purifier).
|
|
137
170
|
|
|
138
171
|
## Models
|
|
139
172
|
|
|
@@ -158,6 +191,8 @@ The protocol work comes from the Home Assistant integration this plugin is porte
|
|
|
158
191
|
- @renaudallard — the email OTP authentication flow is adapted from the [Philips HomeID integration](https://github.com/renaudallard/homeassistant_philips_homeid)
|
|
159
192
|
- @rgpublic — AC1715/11 model configuration
|
|
160
193
|
- @NikGro — PureProtect 3200i (AC3221) mapping and the email + code onboarding
|
|
194
|
+
- @kongo09 and the [aioairctrl](https://github.com/kongo09/aioairctrl) / [philips-airpurifier-coap](https://github.com/kongo09/philips-airpurifier-coap) contributors — the local CoAP protocol and the AC4236 mapping
|
|
195
|
+
- [MaddogWarner/homebridge-philips-air-purifier-complete](https://github.com/MaddogWarner/homebridge-philips-air-purifier-complete) — the Air+ cloud child lock key
|
|
161
196
|
|
|
162
197
|
## License
|
|
163
198
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Diagnostic: lists the purifiers that live on the newer Philips "Air+ cloud"
|
|
5
|
+
// (not the DaConnect cloud the plugin uses) and what each one reports.
|
|
6
|
+
// It only reads: it sends no commands to the devices. Identifiers, serial
|
|
7
|
+
// numbers, MAC/IP addresses and tokens are hidden, so the output can be pasted
|
|
8
|
+
// into a GitHub issue.
|
|
9
|
+
|
|
10
|
+
const readline = require('node:readline/promises');
|
|
11
|
+
const { AirCloudLogin, AirCloudClient, loadSigningKey } = require('../src/aircloud');
|
|
12
|
+
|
|
13
|
+
const SECRET_KEY = /(mac|serial|ssid|^ip$|ipaddr|token|uuid|^sn$|^id$|device_id|bssid|email|user|owner|secret|key|sign|cert|url|path)/i;
|
|
14
|
+
|
|
15
|
+
function redact(obj) {
|
|
16
|
+
if (Array.isArray(obj)) return obj.map(redact);
|
|
17
|
+
if (!obj || typeof obj !== 'object') return obj;
|
|
18
|
+
const out = {};
|
|
19
|
+
for (const [k, v] of Object.entries(obj)) out[k] = SECRET_KEY.test(k) ? '<hidden>' : redact(v);
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
(async () => {
|
|
24
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
25
|
+
try {
|
|
26
|
+
const email = (process.argv[2] || (await rl.question('Philips account email: '))).trim();
|
|
27
|
+
const login = new AirCloudLogin();
|
|
28
|
+
await login.sendCode(email);
|
|
29
|
+
const code = await rl.question(`Code sent to ${email}. Enter it: `);
|
|
30
|
+
const uid = await login.verifyCode(code);
|
|
31
|
+
const client = new AirCloudClient({ uid, signingKey: await loadSigningKey() });
|
|
32
|
+
const devices = await client.devices();
|
|
33
|
+
|
|
34
|
+
console.log(`\nAir+ cloud: ${devices.length} device(s)\n`);
|
|
35
|
+
let n = 0;
|
|
36
|
+
for (const d of devices) {
|
|
37
|
+
n += 1;
|
|
38
|
+
console.log(`--- Device ${n}`);
|
|
39
|
+
console.log(JSON.stringify(redact(d.device_info || d), null, 2));
|
|
40
|
+
try {
|
|
41
|
+
const reported = await client.readShadow(d.device_id);
|
|
42
|
+
console.log(`Reported state (${Object.keys(reported).length} values):`);
|
|
43
|
+
console.log(JSON.stringify(redact(reported), null, 2));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.log(`Reported state: not available (${e.message})`);
|
|
46
|
+
}
|
|
47
|
+
console.log('');
|
|
48
|
+
}
|
|
49
|
+
console.log('Nothing was changed on your devices. Paste everything above into the GitHub issue.');
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error(`\nFailed: ${e.message}`);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
} finally {
|
|
54
|
+
rl.close();
|
|
55
|
+
}
|
|
56
|
+
})();
|
package/config.schema.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"pluginType": "platform",
|
|
4
4
|
"singular": true,
|
|
5
5
|
"customUi": true,
|
|
6
|
-
"headerDisplay": "Philips
|
|
6
|
+
"headerDisplay": "Philips purifiers through the Philips Air+ cloud (same protocol as the Air+ app), or on the local network for models that are not in the cloud (AC4236). Log in with the email of your Philips account; a verification code will be sent there.",
|
|
7
7
|
"schema": {
|
|
8
8
|
"type": "object",
|
|
9
9
|
"properties": {
|
|
@@ -33,14 +33,20 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devices": {
|
|
35
35
|
"title": "Devices",
|
|
36
|
-
"description": "Leave empty to add every purifier in the account. Add entries to pick devices or
|
|
36
|
+
"description": "Leave empty to add every purifier in the account. Add entries to pick or rename cloud devices, or to add a purifier that is not in the cloud (e.g. AC4236) by its IP address.",
|
|
37
37
|
"type": "array",
|
|
38
38
|
"items": {
|
|
39
39
|
"type": "object",
|
|
40
40
|
"properties": {
|
|
41
41
|
"uuid": {
|
|
42
|
-
"title": "Device UUID",
|
|
43
|
-
"type": "string"
|
|
42
|
+
"title": "Device UUID (cloud)",
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description": "For Air+ cloud purifiers. Leave empty for a local purifier."
|
|
45
|
+
},
|
|
46
|
+
"host": {
|
|
47
|
+
"title": "IP address (local)",
|
|
48
|
+
"type": "string",
|
|
49
|
+
"description": "For purifiers controlled on the local network over CoAP (e.g. AC4236). Give the purifier a fixed IP address in your router."
|
|
44
50
|
},
|
|
45
51
|
"name": {
|
|
46
52
|
"title": "Name in HomeKit",
|
|
@@ -49,12 +55,9 @@
|
|
|
49
55
|
"model": {
|
|
50
56
|
"title": "Model (optional)",
|
|
51
57
|
"type": "string",
|
|
52
|
-
"description": "e.g. AC0651/10.
|
|
58
|
+
"description": "e.g. AC0651/10 (cloud) or AC4236 (local). Cloud models are detected automatically; local devices default to AC4236."
|
|
53
59
|
}
|
|
54
|
-
}
|
|
55
|
-
"required": [
|
|
56
|
-
"uuid"
|
|
57
|
-
]
|
|
60
|
+
}
|
|
58
61
|
}
|
|
59
62
|
},
|
|
60
63
|
"airQualitySensor": {
|
|
@@ -104,6 +107,12 @@
|
|
|
104
107
|
],
|
|
105
108
|
"description": "'Air purifier' shows Sleep with the purifier icon in the Home app; it only turns Sleep mode on and off."
|
|
106
109
|
},
|
|
110
|
+
"sleepDisplayOff": {
|
|
111
|
+
"title": "Turn the display off with Sleep",
|
|
112
|
+
"type": "boolean",
|
|
113
|
+
"default": false,
|
|
114
|
+
"description": "Turning Sleep on from HomeKit also turns the display off; turning Sleep off restores its brightness. Only on purifiers that show the Display control."
|
|
115
|
+
},
|
|
107
116
|
"linkComponents": {
|
|
108
117
|
"title": "Link components to the purifier",
|
|
109
118
|
"type": "boolean",
|
|
@@ -122,6 +131,12 @@
|
|
|
122
131
|
"placeholder": "D03105",
|
|
123
132
|
"description": "Only if the light does not appear: the property key that holds the light setting, as shown in the log line 'Status properties reported by the device'."
|
|
124
133
|
},
|
|
134
|
+
"childLock": {
|
|
135
|
+
"title": "Show child lock",
|
|
136
|
+
"type": "boolean",
|
|
137
|
+
"default": true,
|
|
138
|
+
"description": "Adds the Lock Physical Controls switch in the purifier's settings in the Home app, when the purifier reports a child lock."
|
|
139
|
+
},
|
|
125
140
|
"filterChangeThreshold": {
|
|
126
141
|
"title": "Filter change alert below (%)",
|
|
127
142
|
"type": "integer",
|
|
@@ -175,6 +190,7 @@
|
|
|
175
190
|
"expanded": false,
|
|
176
191
|
"items": [
|
|
177
192
|
"devices[].uuid",
|
|
193
|
+
"devices[].host",
|
|
178
194
|
"devices[].name",
|
|
179
195
|
"devices[].model"
|
|
180
196
|
]
|
|
@@ -191,9 +207,11 @@
|
|
|
191
207
|
"filterAlerts",
|
|
192
208
|
"sleepSwitch",
|
|
193
209
|
"sleepSwitchStyle",
|
|
210
|
+
"sleepDisplayOff",
|
|
194
211
|
"linkComponents",
|
|
195
212
|
"displayLight",
|
|
196
213
|
"displayLightProperty",
|
|
214
|
+
"childLock",
|
|
197
215
|
"filterChangeThreshold",
|
|
198
216
|
"pollInterval",
|
|
199
217
|
"logDeviceData",
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-philips-airplus-cloud",
|
|
3
3
|
"displayName": "Philips Air+",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Homebridge plugin for Philips Air+ / PureProtect air purifiers via the Philips (Versuni) cloud — the same MQTT protocol used by the Air+ app
|
|
4
|
+
"version": "0.6.0-beta.0",
|
|
5
|
+
"description": "Homebridge plugin for Philips Air+ / PureProtect air purifiers via the Philips (Versuni) cloud — the same MQTT protocol used by the Air+ app — plus local CoAP control for models not on that cloud (AC4236).",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
"air+",
|
|
22
22
|
"airplus",
|
|
23
23
|
"versuni",
|
|
24
|
-
"homekit"
|
|
24
|
+
"homekit",
|
|
25
|
+
"coap",
|
|
26
|
+
"ac4236",
|
|
27
|
+
"child lock"
|
|
25
28
|
],
|
|
26
29
|
"engines": {
|
|
27
30
|
"node": "^22 || ^24 || ^26",
|
|
28
31
|
"homebridge": "^1.6.0 || ^2.0.0-beta.0"
|
|
29
32
|
},
|
|
30
33
|
"bin": {
|
|
31
|
-
"philips-airplus-login": "bin/philips-airplus-login.js"
|
|
34
|
+
"philips-airplus-login": "bin/philips-airplus-login.js",
|
|
35
|
+
"philips-airplus-aircloud-probe": "bin/philips-airplus-aircloud-probe.js"
|
|
32
36
|
},
|
|
33
37
|
"files": [
|
|
34
38
|
"src",
|
package/src/accessory.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// Filter Maintenance (main filter and pre-filter cleaning).
|
|
5
5
|
|
|
6
6
|
const { DeviceConnection } = require('./connection');
|
|
7
|
+
const { CoapConnection } = require('./coap');
|
|
7
8
|
const { findModel, speedModes, modeName } = require('./models');
|
|
8
9
|
const C = require('./constants');
|
|
9
10
|
|
|
@@ -32,6 +33,9 @@ const FALLBACK_MODEL = {
|
|
|
32
33
|
// kongo09/philips-airpurifier-coap.
|
|
33
34
|
const LIGHT_KEYS = ['D03104', 'D03105', 'D0312D'];
|
|
34
35
|
|
|
36
|
+
// Child lock on Air+ cloud devices (homebridge-philips-air-purifier-complete).
|
|
37
|
+
const LOCK_KEYS = ['D03103'];
|
|
38
|
+
|
|
35
39
|
// Bump to re-apply default service labels once on existing accessories.
|
|
36
40
|
const NAMES_VERSION = 2;
|
|
37
41
|
|
|
@@ -58,7 +62,12 @@ function pm25ToAirQuality(pm) {
|
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
class PurifierAccessory {
|
|
61
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @param {object} [opts]
|
|
67
|
+
* @param {{host: string, port?: number, model?: string}} [opts.local] control the
|
|
68
|
+
* purifier over local CoAP instead of the Philips cloud
|
|
69
|
+
*/
|
|
70
|
+
constructor(platform, accessory, { account, mqttConnect, local, createSocket } = {}) {
|
|
62
71
|
this.platform = platform;
|
|
63
72
|
this.api = platform.api;
|
|
64
73
|
this.accessory = accessory;
|
|
@@ -78,7 +87,12 @@ class PurifierAccessory {
|
|
|
78
87
|
this.lastManualMode = accessory.context.lastManualMode || null;
|
|
79
88
|
this.filterThreshold = platform.config.filterChangeThreshold ?? 10;
|
|
80
89
|
|
|
81
|
-
|
|
90
|
+
if (local) {
|
|
91
|
+
this.conn = new CoapConnection({ ...local, log: this.log, createSocket });
|
|
92
|
+
this.fixedProfile = this.conn.profile;
|
|
93
|
+
} else {
|
|
94
|
+
this.conn = new DeviceConnection({ account, uuid: accessory.context.uuid, log: this.log, mqttConnect });
|
|
95
|
+
}
|
|
82
96
|
this.diag = !!platform.config.logDeviceData;
|
|
83
97
|
this.conn.on('connected', () => {
|
|
84
98
|
this.conn.requestAll();
|
|
@@ -95,7 +109,8 @@ class PurifierAccessory {
|
|
|
95
109
|
// models.yaml entry, wait for the device to report its exact code on the
|
|
96
110
|
// Config port instead of starting with the reduced fallback profile.
|
|
97
111
|
const known = accessory.context.model;
|
|
98
|
-
if (
|
|
112
|
+
if (this.fixedProfile) this._applyModel(known || this.fixedProfile.key, false);
|
|
113
|
+
else if (known && findModel(known)) this._applyModel(known, false);
|
|
99
114
|
else this.log.info(`Model ${known ? `${known} ` : ''}not identified yet; waiting for the device to report it`);
|
|
100
115
|
|
|
101
116
|
this._setInfo();
|
|
@@ -141,7 +156,7 @@ class PurifierAccessory {
|
|
|
141
156
|
// ---------------------------------------------------------------- model
|
|
142
157
|
|
|
143
158
|
_applyModel(ctn, persist = true) {
|
|
144
|
-
const model = findModel(ctn);
|
|
159
|
+
const model = this.fixedProfile || findModel(ctn);
|
|
145
160
|
if (!model) {
|
|
146
161
|
this.log.warn(`Model ${ctn} is not in models.yaml: exposing power, PM2.5 and filters only`);
|
|
147
162
|
}
|
|
@@ -357,6 +372,7 @@ class PurifierAccessory {
|
|
|
357
372
|
}
|
|
358
373
|
|
|
359
374
|
this._setupLight();
|
|
375
|
+
this._setupLock();
|
|
360
376
|
|
|
361
377
|
if ((this.accessory.context.namesVersion || 0) < NAMES_VERSION) {
|
|
362
378
|
this.accessory.context.namesVersion = NAMES_VERSION;
|
|
@@ -386,6 +402,59 @@ class PurifierAccessory {
|
|
|
386
402
|
this.light = s;
|
|
387
403
|
}
|
|
388
404
|
|
|
405
|
+
/** Child lock: a control in the purifier's settings, once the device reports it. */
|
|
406
|
+
_setupLock() {
|
|
407
|
+
const { Characteristic } = this.hap;
|
|
408
|
+
const key = this._lockKey();
|
|
409
|
+
const p = this.purifier;
|
|
410
|
+
if (!p) return;
|
|
411
|
+
if (!key || this.platform.config.childLock === false) {
|
|
412
|
+
if (p.testCharacteristic(Characteristic.LockPhysicalControls)) p.removeCharacteristic(p.getCharacteristic(Characteristic.LockPhysicalControls));
|
|
413
|
+
this.lockReady = false;
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (this.lockReady) return;
|
|
417
|
+
p.getCharacteristic(Characteristic.LockPhysicalControls)
|
|
418
|
+
.onGet(() => this._lockState())
|
|
419
|
+
.onSet((v) => this._setLock(v));
|
|
420
|
+
this.lockReady = true;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
_lockKey() {
|
|
424
|
+
const fromModel = this._prop('child_lock');
|
|
425
|
+
if (fromModel) return this.state[fromModel] !== undefined || this.accessory.context.lockKey === fromModel ? fromModel : null;
|
|
426
|
+
if (this.accessory.context.lockKey) return this.accessory.context.lockKey;
|
|
427
|
+
return LOCK_KEYS.find((k) => this.state[k] !== undefined) || null;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
_lockState() {
|
|
431
|
+
const key = this._lockKey();
|
|
432
|
+
const v = key ? Number(this.state[key]) : 0;
|
|
433
|
+
return v ? 1 : 0; // CONTROL_LOCK_ENABLED : CONTROL_LOCK_DISABLED
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async _setLock(v) {
|
|
437
|
+
this._ensureConnected();
|
|
438
|
+
const key = this._lockKey();
|
|
439
|
+
if (!key) return;
|
|
440
|
+
const on = v === 1 ? 1 : 0;
|
|
441
|
+
if (on === this._lockState()) return;
|
|
442
|
+
this.log.info(`Child lock ${on ? 'on' : 'off'}`);
|
|
443
|
+
this.conn.setControl({ [key]: on });
|
|
444
|
+
this.state[key] = on;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
_learnLock(props) {
|
|
448
|
+
const ctx = this.accessory.context;
|
|
449
|
+
const fromModel = this._prop('child_lock');
|
|
450
|
+
const k = fromModel ? (props[fromModel] !== undefined ? fromModel : null) : LOCK_KEYS.find((x) => props[x] !== undefined);
|
|
451
|
+
if (!k || ctx.lockKey === k) return;
|
|
452
|
+
ctx.lockKey = k;
|
|
453
|
+
this.log.info(`Child lock found on property ${k}`);
|
|
454
|
+
this.platform.updateAccessory(this.accessory);
|
|
455
|
+
this._setupLock();
|
|
456
|
+
}
|
|
457
|
+
|
|
389
458
|
_lightKey() {
|
|
390
459
|
const fromConfig = this.platform.config.displayLightProperty;
|
|
391
460
|
if (fromConfig) return String(fromConfig).trim();
|
|
@@ -554,15 +623,45 @@ class PurifierAccessory {
|
|
|
554
623
|
if (on === this._isSleep()) return;
|
|
555
624
|
if (on) {
|
|
556
625
|
this._setMode(this.sleepModeName);
|
|
626
|
+
this._sleepDisplay(true);
|
|
557
627
|
} else {
|
|
558
628
|
// leave Sleep: back to Auto if the model has it, else the last manual speed
|
|
559
629
|
const auto = Object.keys(this.model.modes).find((m) => m.toLowerCase() === 'auto');
|
|
560
630
|
const back = auto || (this.speeds.includes(this.lastManualMode) && this.lastManualMode !== this.sleepModeName ? this.lastManualMode : this.speeds[1] || this.speeds[0]);
|
|
561
631
|
this._setMode(back);
|
|
632
|
+
this._sleepDisplay(false);
|
|
562
633
|
}
|
|
563
634
|
setTimeout(() => this._pushAll(), 0);
|
|
564
635
|
}
|
|
565
636
|
|
|
637
|
+
/**
|
|
638
|
+
* sleepDisplayOff: turning Sleep on from HomeKit also turns the display off,
|
|
639
|
+
* and turning Sleep off restores the level it had. Only for purifiers whose
|
|
640
|
+
* display control is shown (a light property is known).
|
|
641
|
+
*/
|
|
642
|
+
_sleepDisplay(entering) {
|
|
643
|
+
if (this.platform.config.sleepDisplayOff !== true || !this.light) return;
|
|
644
|
+
const key = this._lightKey();
|
|
645
|
+
if (!key) return;
|
|
646
|
+
const ctx = this.accessory.context;
|
|
647
|
+
if (entering) {
|
|
648
|
+
const raw = this._lightRaw();
|
|
649
|
+
if (raw === null || raw <= 0) return;
|
|
650
|
+
ctx.lightBeforeSleep = raw;
|
|
651
|
+
this.log.info('Display off for Sleep');
|
|
652
|
+
this.conn.setControl({ [key]: 0 });
|
|
653
|
+
this.state[key] = 0;
|
|
654
|
+
} else if (ctx.lightBeforeSleep) {
|
|
655
|
+
const raw = ctx.lightBeforeSleep;
|
|
656
|
+
delete ctx.lightBeforeSleep;
|
|
657
|
+
if (this._lightOn()) return; // turned back on by hand in the meantime
|
|
658
|
+
this.log.info(`Display back to ${raw} after Sleep`);
|
|
659
|
+
this.conn.setControl({ [key]: raw });
|
|
660
|
+
this.state[key] = raw;
|
|
661
|
+
}
|
|
662
|
+
this.platform.updateAccessory(this.accessory);
|
|
663
|
+
}
|
|
664
|
+
|
|
566
665
|
/** @param {number|null} brightness 0 = off, null = "on" at the last level */
|
|
567
666
|
async _setLight(brightness) {
|
|
568
667
|
this._ensureConnected();
|
|
@@ -632,6 +731,7 @@ class PurifierAccessory {
|
|
|
632
731
|
}
|
|
633
732
|
Object.assign(this.state, props);
|
|
634
733
|
this._learnLight(props);
|
|
734
|
+
this._learnLock(props);
|
|
635
735
|
} else {
|
|
636
736
|
return;
|
|
637
737
|
}
|
|
@@ -719,6 +819,7 @@ class PurifierAccessory {
|
|
|
719
819
|
this.sleepPurifier.updateCharacteristic(Characteristic.Active, this._isSleep() ? 1 : 0);
|
|
720
820
|
this.sleepPurifier.updateCharacteristic(Characteristic.CurrentAirPurifierState, this._isSleep() ? 2 : 0);
|
|
721
821
|
}
|
|
822
|
+
if (this.lockReady) this.purifier.updateCharacteristic(Characteristic.LockPhysicalControls, this._lockState());
|
|
722
823
|
if (this.light && this._lightRaw() !== null) {
|
|
723
824
|
this.light.updateCharacteristic(Characteristic.On, this._lightOn());
|
|
724
825
|
if (this._lightOn()) this.light.updateCharacteristic(Characteristic.Brightness, this._lightBrightness());
|