homebridge-philips-air-purifier-complete 2.0.2 → 2.2.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 +52 -0
- package/CLAUDE.md +63 -0
- package/CONTRIBUTORS.md +1 -1
- package/IMG_0301.jpeg +0 -0
- package/README.md +60 -7
- package/aioairctrl/coap/client.py +0 -1
- package/codex-plan.md +326 -0
- package/config.schema.json +8 -1
- package/index.js +49 -19
- package/package.json +1 -1
- package/philips_air_api.py +393 -27
- package/postinstall.sh +43 -5
- package/preinstall.sh +64 -17
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,58 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## [2.2.0] — 2026-05-23
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- HTTP protocol support for Philips AC1xxx-series devices (e.g. AC1715) that do not implement
|
|
14
|
+
CoAP. Set `"protocol": "http"` in your Homebridge accessory configuration to use this mode.
|
|
15
|
+
HTTP devices use 10-second polling instead of CoAP Observe push updates.
|
|
16
|
+
- New `protocol` config option (`"coap"` | `"http"`, default `"coap"`). Each accessory
|
|
17
|
+
configures its protocol independently, so mixed households (AC1715 + AC3858) work without
|
|
18
|
+
any shared state.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## [2.1.0] — 2026-05-18
|
|
23
|
+
|
|
24
|
+
### Changes
|
|
25
|
+
|
|
26
|
+
- Removed dead `mode !== null` predicate from `SPEED_TO_MODE.find()` in the RotationSpeed setter — redundant since the unreachable `{ max: 0, mode: null }` entry was removed in 2.0.3.
|
|
27
|
+
- Extended the `PYTHON_MIN_VERSION` single-source-of-truth fix to `preinstall.sh` and `postinstall.sh`: both scripts now derive the Python version tuple from `PYTHON_MIN_VERSION` using bash string operators (`%%.*` / `#*.`), eliminating the separate hardcoded `(3, 12)` tuples in `python_version_ok()` and the postinstall verify step.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## [2.0.5] — 2026-05-18
|
|
32
|
+
|
|
33
|
+
### Changes
|
|
34
|
+
|
|
35
|
+
- Made `PYTHON_MIN_VERSION` the single source of truth for Node-side Python runtime validation by deriving the embedded Python version tuple from the display string.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## [2.0.4] — 2026-05-18
|
|
40
|
+
|
|
41
|
+
### Changes
|
|
42
|
+
|
|
43
|
+
- Removed the CoAP Observe option from one-shot status reads in `aioairctrl/coap/client.py` so CLI diagnostics no longer create unused Observe subscriptions.
|
|
44
|
+
- Left the dedicated `observe_status()` path unchanged for the Homebridge daemon's real-time CoAP Observe updates.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## [2.0.3] — 2026-05-18
|
|
49
|
+
|
|
50
|
+
### Changes
|
|
51
|
+
|
|
52
|
+
- Changed `preinstall.sh` to warn about unsupported Node.js or Python versions without blocking npm/Homebridge UI installation.
|
|
53
|
+
- Extended Python discovery in `preinstall.sh` for Docker/NAS deployments: checks `PHILIPS_AIR_PYTHON`, npm's `--python` setting (`npm_config_python`), common absolute paths (`/opt/homebrew`, `/usr/local`, `/usr/bin`), and Synology-style paths.
|
|
54
|
+
- Added `PHILIPS_AIR_SKIP_PYTHON_PREINSTALL=1` environment variable to bypass the Python preinstall check in managed environments where `pythonPath` is configured after installation.
|
|
55
|
+
- Fixed listener leak in `DaemonHandler.start()`: `readyHandler` is now removed from the readline interface when the 20-second startup timeout fires.
|
|
56
|
+
- Removed unreachable `{ max: 0, mode: null }` entry from `SPEED_TO_MODE` in `index.js`.
|
|
57
|
+
- Updated README troubleshooting to explain expected preinstall warnings and how to provide an explicit Python path when npm has a restricted `PATH`.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
9
61
|
## [2.0.2] — 2026-05-18
|
|
10
62
|
|
|
11
63
|
### Changes
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# CLAUDE.md — homebridge-philips-air-purifier-complete
|
|
2
|
+
|
|
3
|
+
Homebridge plugin for Philips Air Purifiers → Apple HomeKit via CoAP or HTTP. Merges a prior Homebridge plugin with the bundled [aioairctrl](https://github.com/betaboon/aioairctrl) Python CoAP library.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
Node.js >=24, Homebridge >=2.0, Python >=3.12, aiocoap >=0.4.17,<0.5, pycryptodomex >=3.23,<4
|
|
7
|
+
|
|
8
|
+
## Architecture
|
|
9
|
+
```
|
|
10
|
+
index.js (DaemonHandler) → spawn philips_air_api.py --daemon [--protocol http] → device
|
|
11
|
+
```
|
|
12
|
+
- **CoAP path:** `aioairctrl/coap/client.py` → CoAP UDP:5683 → device
|
|
13
|
+
- **HTTP path:** `PhilipsAirHTTPClient` → HTTP TCP:80 → device
|
|
14
|
+
- **Updates:** CoAP Observe push or HTTP polling every 10 seconds (device → Python stdout JSON → JS readline)
|
|
15
|
+
- **Commands:** JS writes JSON to Python stdin; Python sends CoAP or HTTP control and replies
|
|
16
|
+
- **State:** Cached from observe updates or HTTP polls; reads avoid an extra device request
|
|
17
|
+
|
|
18
|
+
## Key Files
|
|
19
|
+
| File | Role |
|
|
20
|
+
|------|------|
|
|
21
|
+
| `index.js` | Plugin entry; DaemonHandler + PhilipsAirPurifierAccessory |
|
|
22
|
+
| `philips_air_api.py` | Python daemon (`ObserveDaemon` / `HTTPPollingDaemon`) + CLI client |
|
|
23
|
+
| `aioairctrl/coap/client.py` | CoAP get/observe/set; handles encryption |
|
|
24
|
+
| `aioairctrl/coap/encryption.py` | AES-CBC + SHA256 integrity (key: "JiangPan" — protocol constant) |
|
|
25
|
+
| `aioairctrl/coap/aiocoap_monkeypatch.py` | Patches aiocoap deduplication and iterator cleanup — do not remove |
|
|
26
|
+
| `preinstall.sh` | Warns (not fails) if Node 24+ or Python 3.12+ absent; supports `PHILIPS_AIR_PYTHON` and `PHILIPS_AIR_SKIP_PYTHON_PREINSTALL=1` |
|
|
27
|
+
| `postinstall.sh` | Creates `.venv/`, installs Python deps, verifies setup |
|
|
28
|
+
|
|
29
|
+
## Device Protocol
|
|
30
|
+
CoAP paths: `/sys/dev/sync` (POST key exchange), `/sys/dev/status` (GET+Observe), `/sys/dev/control` (POST set).
|
|
31
|
+
|
|
32
|
+
HTTP paths: `/di/v1/products/0/security` (PUT DH key exchange), `/di/v1/products/1/air` (GET/PUT encrypted status/control). HTTP uses AES-128-CBC with zero IV, PKCS7 padding, and base64 payloads after the session key exchange.
|
|
33
|
+
|
|
34
|
+
Mode values: `0`=auto, `17`=sleep, `18`=turbo, `19`=medium. Light values: `0`=off, `115`=dim, `123`=bright.
|
|
35
|
+
|
|
36
|
+
HTTP field names differ from the current CoAP payloads: power `pwr`, mode `mode`, fan speed `om`, display brightness `aqil`, child lock `cl`, PM2.5 `pm25`, allergen index `iaql`. `parse_status()` normalises both protocol families into the same Homebridge IPC shape.
|
|
37
|
+
|
|
38
|
+
HomeKit RotationSpeed → mode: 0%=off, 1–33%=sleep, 34–66%=medium, 67–100%=turbo. Sleep Mode is a dedicated Switch service (HomeKit AirPurifier only has Auto/Manual).
|
|
39
|
+
|
|
40
|
+
## Design Decisions
|
|
41
|
+
- **Optimistic state:** Commands update `this.state` immediately; observe updates correct on next push.
|
|
42
|
+
- **Command lock (`_commandCount`):** Blocks observe updates for 500ms after a command to avoid overwriting optimistic state.
|
|
43
|
+
- **Daemon backoff:** `[5s, 10s, 30s, 60s]` restart delays on crash.
|
|
44
|
+
- **Python finder:** Checks `.venv/bin/python3` first, then system Python 3.12 paths; all candidates validated with `PYTHON_RUNTIME_CHECK` (version + import check).
|
|
45
|
+
- **aiocoap monkeypatches:** Required for Observe to work correctly. Pinned to `<0.5` — do not bump aiocoap without re-validating patches.
|
|
46
|
+
- **`PYTHON_MIN_VERSION` is the single source of truth** for the minimum Python version across `index.js`, `preinstall.sh`, and `postinstall.sh`. All three derive the version tuple from this string — only one value to update when the minimum changes.
|
|
47
|
+
- **preinstall warns, not fails:** If Python 3.12+ is not in the PATH npm sees, install continues with a warning. Set `PHILIPS_AIR_PYTHON=/path/to/python3.12` or `PHILIPS_AIR_SKIP_PYTHON_PREINSTALL=1` for Docker/NAS setups.
|
|
48
|
+
- **Protocol selection:** `protocol` is explicit per accessory (`coap` default, `http` for AC1xxx such as AC1715). No auto-detection; mixed households work because each accessory owns its config.
|
|
49
|
+
- **HTTP polling:** `HTTPPollingDaemon.POLL_INTERVAL` is 10 seconds. Physical button changes on HTTP devices may be stale in HomeKit for up to one poll interval.
|
|
50
|
+
|
|
51
|
+
## Release Process
|
|
52
|
+
1. Update `CHANGELOG.md` and bump `version` in `package.json`
|
|
53
|
+
2. `git commit`, `git tag vX.Y.Z`, `git push origin main vX.Y.Z`
|
|
54
|
+
3. `gh release create vX.Y.Z --title "vX.Y.Z" --notes "..."`
|
|
55
|
+
4. `npm publish --access public`
|
|
56
|
+
|
|
57
|
+
## Dev Commands
|
|
58
|
+
```bash
|
|
59
|
+
npm run lint # ESLint v9 flat config
|
|
60
|
+
npm run format # Prettier
|
|
61
|
+
bash postinstall.sh # Rebuild .venv manually
|
|
62
|
+
source .venv/bin/activate && python philips_air_api.py <ip> sensors
|
|
63
|
+
```
|
package/CONTRIBUTORS.md
CHANGED
|
@@ -8,7 +8,7 @@ Combined fork author. Bundled aioairctrl into the plugin, automated Python envir
|
|
|
8
8
|
## AI Assistance
|
|
9
9
|
|
|
10
10
|
**[Claude Sonnet 4.6](https://claude.ai)** (Anthropic)
|
|
11
|
-
Code review of aioairctrl (bug fixes, type annotation corrections, input validation), refactoring of homebridge plugin for the bundled architecture, postinstall automation, documentation authoring.
|
|
11
|
+
Code review of aioairctrl (bug fixes, type annotation corrections, input validation), refactoring of homebridge plugin for the bundled architecture, postinstall automation, documentation authoring. Additional contributions: daemon readline listener leak fix, removal of orphaned CoAP Observe subscription from one-shot `get_status()`, `PYTHON_MIN_VERSION` single-source-of-truth refactor across JS and shell runtimes, removal of dead `SPEED_TO_MODE` entry and residual null guard.
|
|
12
12
|
|
|
13
13
|
**OpenAI Codex**
|
|
14
14
|
Python 3.12 and Node.js 24 compatibility review, runtime detection hardening, dependency range updates, ESLint flat config migration, and documentation updates.
|
package/IMG_0301.jpeg
ADDED
|
Binary file
|
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ This plugin bundles the [aioairctrl](https://github.com/betaboon/aioairctrl) CoA
|
|
|
26
26
|
- **Child Lock** — Lock or unlock physical controls on the device
|
|
27
27
|
- **HEPA Filter Status** — Filter life percentage and change alert
|
|
28
28
|
- **Pre-Filter Status** — Cleanup cycle percentage and change alert
|
|
29
|
-
- **
|
|
29
|
+
- **HTTP Protocol Support** — Supports AC1xxx-series models (e.g. AC1715) that use HTTP instead of CoAP
|
|
30
|
+
- **Real-time Updates** — CoAP Observe push updates (AC2xxx+) or 10-second HTTP polling (AC1xxx)
|
|
30
31
|
- **Auto-reconnect** — Daemon restarts automatically with exponential backoff if the device drops off
|
|
31
32
|
|
|
32
33
|
---
|
|
@@ -70,7 +71,25 @@ The install hook creates a plugin-local virtual environment and installs:
|
|
|
70
71
|
|
|
71
72
|
The plugin automatically sets up a Python virtual environment and installs its CoAP dependencies during install. No extra steps needed.
|
|
72
73
|
|
|
73
|
-
The npm `preinstall` check
|
|
74
|
+
The npm `preinstall` check reports warnings if Node.js 24+ or Python 3.12+ is not available on the host, but it does not block installation. This keeps Homebridge UI plugin installation simple while still making unsupported runtime versions visible in the install log.
|
|
75
|
+
|
|
76
|
+
For Docker, NAS, or managed Homebridge installs where npm runs with a restricted `PATH`, provide the Python path explicitly:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
PHILIPS_AIR_PYTHON=/absolute/path/to/python3.12 npm install -g homebridge-philips-air-purifier-complete
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The installer also honours npm's Python setting:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm install -g homebridge-philips-air-purifier-complete --python=/absolute/path/to/python3.12
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
If the install environment cannot expose Python until after the plugin is installed, configure `pythonPath` in Homebridge before starting the plugin. You can also suppress the Python preinstall warning:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
PHILIPS_AIR_SKIP_PYTHON_PREINSTALL=1 npm install -g homebridge-philips-air-purifier-complete
|
|
92
|
+
```
|
|
74
93
|
|
|
75
94
|
### Via npm
|
|
76
95
|
|
|
@@ -102,7 +121,22 @@ Add to your Homebridge `config.json` under `"accessories"`:
|
|
|
102
121
|
}
|
|
103
122
|
```
|
|
104
123
|
|
|
105
|
-
|
|
124
|
+
For AC1xxx models that use HTTP:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"accessories": [
|
|
129
|
+
{
|
|
130
|
+
"accessory": "PhilipsAirPurifier",
|
|
131
|
+
"name": "Bedroom Air Purifier",
|
|
132
|
+
"host": "192.168.1.101",
|
|
133
|
+
"protocol": "http"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Or configure via the Homebridge UI — fill in **Name** and **IP Address**, and set **Protocol** to `http` if your device is an AC1xxx model.
|
|
106
140
|
|
|
107
141
|
### Configuration Options
|
|
108
142
|
|
|
@@ -110,8 +144,18 @@ Or configure via the Homebridge UI — just fill in the **Name** and **IP Addres
|
|
|
110
144
|
|--------|----------|---------|-------------|
|
|
111
145
|
| `name` | Yes | — | Name shown in HomeKit |
|
|
112
146
|
| `host` | Yes | — | IPv4 address of your air purifier |
|
|
147
|
+
| `protocol` | No | `coap` | Communication protocol. Set to `http` for AC1xxx models (AC1715, etc.) that do not support CoAP. |
|
|
113
148
|
| `pythonPath` | No | Auto-detected | Path to Python 3.12 or newer with `aiocoap` and `pycryptodomex` installed. Leave blank to use the plugin's bundled virtual environment. |
|
|
114
149
|
|
|
150
|
+
### Model Compatibility
|
|
151
|
+
|
|
152
|
+
| Protocol | Models | Notes |
|
|
153
|
+
|----------|--------|-------|
|
|
154
|
+
| `coap` (default) | AC2xxx, AC3xxx, AC4xxx | CoAP Observe push updates |
|
|
155
|
+
| `http` | AC1xxx (e.g. AC1715) | HTTP polling every 10 seconds |
|
|
156
|
+
|
|
157
|
+
If your device shows `Network error: NetworkError` on every command, try setting `"protocol": "http"` in your accessory config.
|
|
158
|
+
|
|
115
159
|
---
|
|
116
160
|
|
|
117
161
|
## Connectivity Check (optional)
|
|
@@ -155,15 +199,18 @@ Homebridge (Node.js)
|
|
|
155
199
|
│
|
|
156
200
|
▼
|
|
157
201
|
philips_air_api.py ─── aioairctrl/ (bundled) ──► aiocoap ──► Philips device (CoAP)
|
|
202
|
+
│
|
|
203
|
+
└──────────────────── HTTP encrypted polling ───────────► Philips device (HTTP)
|
|
158
204
|
│
|
|
159
205
|
│ CoAP Observe (push)
|
|
160
206
|
│ ≈ every 30s or on change
|
|
207
|
+
│ HTTP polling every 10s
|
|
161
208
|
▼
|
|
162
209
|
State cache ──► HomeKit characteristics
|
|
163
210
|
```
|
|
164
211
|
|
|
165
212
|
- The Python daemon maintains a **CoAP Observe** subscription to the device
|
|
166
|
-
-
|
|
213
|
+
- For HTTP models, the Python daemon polls the local API every 10 seconds
|
|
167
214
|
- Commands (power, mode, light) are sent directly and complete in ~100–300ms
|
|
168
215
|
- The Node.js plugin communicates with the daemon over stdin/stdout JSON
|
|
169
216
|
- If the daemon exits for any reason, Homebridge restarts it with exponential backoff (5s → 10s → 30s → 60s)
|
|
@@ -202,14 +249,20 @@ python3.12 philips_air_api.py 192.168.1.100 childlock off
|
|
|
202
249
|
**Python setup failed during install**
|
|
203
250
|
- Ensure Python 3.12+ and the matching `venv` package are installed, then re-run `bash postinstall.sh`
|
|
204
251
|
|
|
205
|
-
**
|
|
206
|
-
-
|
|
207
|
-
-
|
|
252
|
+
**Preinstall warnings**
|
|
253
|
+
- Warnings about Node.js mean `node --version` did not report v24.0.0 or newer during install
|
|
254
|
+
- Warnings about Python mean `python3.12 --version` or `python3 --version` did not report Python 3.12 or newer during install
|
|
255
|
+
- If Python 3.12+ is installed but not visible to npm, install with `PHILIPS_AIR_PYTHON=/absolute/path/to/python3.12 npm install -g homebridge-philips-air-purifier-complete`
|
|
256
|
+
- If Python can only be configured after install, set `pythonPath` in the Homebridge plugin configuration before starting Homebridge
|
|
208
257
|
|
|
209
258
|
**Persistent CoAP timeouts**
|
|
210
259
|
- CoAP (UDP) can be blocked by some network configurations; ensure UDP is allowed between Homebridge and the device
|
|
211
260
|
- Assign a static IP to the device in your router's DHCP settings
|
|
212
261
|
|
|
262
|
+
**`Network error: NetworkError` on every command**
|
|
263
|
+
- Your device may use HTTP instead of CoAP. Set `"protocol": "http"` in your Homebridge accessory configuration.
|
|
264
|
+
- This affects AC1xxx models (e.g. AC1715) which do not expose a CoAP server on UDP port 5683.
|
|
265
|
+
|
|
213
266
|
---
|
|
214
267
|
|
|
215
268
|
## Versioning
|
|
@@ -65,7 +65,6 @@ class Client:
|
|
|
65
65
|
mtype=NON,
|
|
66
66
|
uri=f"coap://{self.host}:{self.port}{self.STATUS_PATH}",
|
|
67
67
|
)
|
|
68
|
-
request.opt.observe = 0
|
|
69
68
|
response = await self._client_context.request(request).response
|
|
70
69
|
payload_encrypted = response.payload.decode()
|
|
71
70
|
payload = self._encryption_context.decrypt(payload_encrypted)
|
package/codex-plan.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# Codex Implementation Plan: Add HTTP Protocol Support (AC1715 / AC1xxx)
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
|
|
5
|
+
A user's AC1715 air purifier fails with `Network error: NetworkError` on every attempt. The AC1715 uses an **HTTP-based local API** (TCP port 80) — not CoAP (UDP 5683). The plugin currently only implements CoAP, so AC1xxx-series devices cannot connect.
|
|
6
|
+
|
|
7
|
+
Evidence:
|
|
8
|
+
- kongo09/philips-airpurifier-coap issues #173 and #210: AC1715/70 and AC1715/11 both show `ECONNREFUSED` on UDP 5683 — labelled "Philips connectivity problem — will not be fixed"
|
|
9
|
+
- py-air-control (rgerganov/py-air-control) has a working HTTP client for exactly this protocol
|
|
10
|
+
- HTTP protocol: DH key exchange → AES-128-CBC with zero IV + PKCS7 + base64
|
|
11
|
+
|
|
12
|
+
No new Python dependencies: `urllib.request` (stdlib), `Cryptodome` (already installed for CoAP), and Python's built-in `pow()` for DH.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Approach
|
|
17
|
+
|
|
18
|
+
Add `"protocol": "http"` as an optional Homebridge accessory config field. When set, the Python daemon runs an HTTP polling loop instead of CoAP Observe. The JS↔Python IPC format, optimistic state, and HomeKit characteristic mapping are **unchanged**.
|
|
19
|
+
|
|
20
|
+
Protocol is explicit config — not auto-detected. Each accessory has its own independent config block, so a mixed household (AC1715 + AC3858) works without shared state.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Files to Modify
|
|
25
|
+
|
|
26
|
+
| File | Change |
|
|
27
|
+
|------|--------|
|
|
28
|
+
| `config.schema.json` | Add `protocol` enum field ("coap"/"http", default "coap") |
|
|
29
|
+
| `index.js` | Read `protocol` from config; pass `--protocol http` to daemon args |
|
|
30
|
+
| `philips_air_api.py` | Add `PhilipsAirHTTPClient` + `HTTPPollingDaemon`; wire `--protocol` arg |
|
|
31
|
+
| `CLAUDE.md` | Document HTTP protocol option, field names, polling interval |
|
|
32
|
+
| `README.md` | See README changes section below |
|
|
33
|
+
| `CHANGELOG.md` | See CHANGELOG changes section below |
|
|
34
|
+
| `package.json` | Bump version to `2.2.0` |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Implementation Detail
|
|
39
|
+
|
|
40
|
+
### 1. config.schema.json
|
|
41
|
+
|
|
42
|
+
Add to the `"properties"` object:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
"protocol": {
|
|
46
|
+
"title": "Protocol",
|
|
47
|
+
"type": "string",
|
|
48
|
+
"enum": ["coap", "http"],
|
|
49
|
+
"default": "coap",
|
|
50
|
+
"description": "Communication protocol. Use 'http' for AC1xxx models (AC1715, etc.) that do not support CoAP."
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Add `"protocol"` to the existing `"Device Settings"` fieldset items array in `"layout"`.
|
|
55
|
+
|
|
56
|
+
### 2. index.js
|
|
57
|
+
|
|
58
|
+
In `PhilipsAirPurifierAccessory` constructor, read:
|
|
59
|
+
```js
|
|
60
|
+
this.protocol = accessory.context.device.protocol || 'coap';
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Pass `this.protocol` into `DaemonHandler` (add it as a constructor param or expose via the start call).
|
|
64
|
+
|
|
65
|
+
In `DaemonHandler.start()` (around line 100), change spawn args:
|
|
66
|
+
```js
|
|
67
|
+
// Before:
|
|
68
|
+
[scriptPath, host, '--daemon']
|
|
69
|
+
|
|
70
|
+
// After:
|
|
71
|
+
[scriptPath, host, '--daemon', ...(protocol === 'http' ? ['--protocol', 'http'] : [])]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 3. philips_air_api.py
|
|
75
|
+
|
|
76
|
+
#### DH constants (protocol constants, not secrets — from py-air-control)
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import base64, random, urllib.request, urllib.error
|
|
80
|
+
from Cryptodome.Cipher import AES
|
|
81
|
+
from Cryptodome.Util.Padding import pad, unpad
|
|
82
|
+
|
|
83
|
+
_G = 0xA4
|
|
84
|
+
_P = int(
|
|
85
|
+
"FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
|
|
86
|
+
"29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
|
|
87
|
+
"EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
|
|
88
|
+
"E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
|
|
89
|
+
"EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381"
|
|
90
|
+
"FFFFFFFFFFFFFFFF",
|
|
91
|
+
16,
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### `PhilipsAirHTTPClient` class
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
class PhilipsAirHTTPClient:
|
|
99
|
+
def __init__(self, host: str, port: int = 80):
|
|
100
|
+
self.host = host
|
|
101
|
+
self.port = port
|
|
102
|
+
self._session_key: bytes | None = None
|
|
103
|
+
|
|
104
|
+
def _url(self, path: str) -> str:
|
|
105
|
+
return f"http://{self.host}:{self.port}{path}"
|
|
106
|
+
|
|
107
|
+
def _encrypt(self, values: dict) -> bytes:
|
|
108
|
+
data = "AA" + json.dumps(values)
|
|
109
|
+
padded = pad(data.encode(), 16, style="pkcs7")
|
|
110
|
+
cipher = AES.new(self._session_key, AES.MODE_CBC, iv=bytes(16))
|
|
111
|
+
return base64.b64encode(cipher.encrypt(padded))
|
|
112
|
+
|
|
113
|
+
def _decrypt(self, data: bytes) -> dict:
|
|
114
|
+
payload = base64.b64decode(data)
|
|
115
|
+
cipher = AES.new(self._session_key, AES.MODE_CBC, iv=bytes(16))
|
|
116
|
+
decrypted = unpad(cipher.decrypt(payload), 16, style="pkcs7")[2:]
|
|
117
|
+
return json.loads(decrypted)
|
|
118
|
+
|
|
119
|
+
def _http(self, method: str, path: str, body: bytes | None = None) -> bytes:
|
|
120
|
+
req = urllib.request.Request(
|
|
121
|
+
self._url(path),
|
|
122
|
+
data=body,
|
|
123
|
+
method=method,
|
|
124
|
+
headers={"Content-Type": "application/json"},
|
|
125
|
+
)
|
|
126
|
+
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
127
|
+
return resp.read()
|
|
128
|
+
|
|
129
|
+
def connect(self):
|
|
130
|
+
"""DH key exchange — derives and stores session key."""
|
|
131
|
+
a = random.getrandbits(256)
|
|
132
|
+
A = pow(_G, a, _P)
|
|
133
|
+
body = json.dumps({"diffie": format(A, "x")}).encode()
|
|
134
|
+
raw = self._http("PUT", "/di/v1/products/0/security", body)
|
|
135
|
+
resp = json.loads(raw)
|
|
136
|
+
B = int(resp["hellman"], 16)
|
|
137
|
+
s = pow(B, a, _P)
|
|
138
|
+
s_bytes = s.to_bytes(128, byteorder="big")[:16]
|
|
139
|
+
# Decrypt the server's wrapped key using the shared secret
|
|
140
|
+
enc_key = base64.b64decode(resp["key"])
|
|
141
|
+
cipher = AES.new(s_bytes, AES.MODE_CBC, iv=bytes(16))
|
|
142
|
+
self._session_key = unpad(cipher.decrypt(enc_key), 16, style="pkcs7")[:16]
|
|
143
|
+
|
|
144
|
+
def get_status(self) -> dict:
|
|
145
|
+
raw = self._http("GET", "/di/v1/products/1/air")
|
|
146
|
+
return self._decrypt(raw)
|
|
147
|
+
|
|
148
|
+
def set_values(self, values: dict):
|
|
149
|
+
body = self._encrypt(values)
|
|
150
|
+
self._http("PUT", "/di/v1/products/1/air", body)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
All `_http` calls are wrapped in `asyncio.to_thread()` inside the daemon to keep the event loop non-blocking. No new dependencies required.
|
|
154
|
+
|
|
155
|
+
#### `HTTPPollingDaemon` class
|
|
156
|
+
|
|
157
|
+
Mirrors the existing `ObserveDaemon` structure. Emits the same stdout JSON format so JS side is unchanged:
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
class HTTPPollingDaemon:
|
|
161
|
+
POLL_INTERVAL = 10 # seconds
|
|
162
|
+
|
|
163
|
+
def __init__(self, host: str, port: int = 80):
|
|
164
|
+
self._client = PhilipsAirHTTPClient(host, port)
|
|
165
|
+
self._pending: dict[str, asyncio.Future] = {}
|
|
166
|
+
|
|
167
|
+
async def run(self):
|
|
168
|
+
# Connect (DH exchange)
|
|
169
|
+
await asyncio.to_thread(self._client.connect)
|
|
170
|
+
_emit({"status": "ready"})
|
|
171
|
+
|
|
172
|
+
# Start poll loop and stdin reader concurrently
|
|
173
|
+
await asyncio.gather(self._poll_loop(), self._command_loop())
|
|
174
|
+
|
|
175
|
+
async def _poll_loop(self):
|
|
176
|
+
while True:
|
|
177
|
+
try:
|
|
178
|
+
state = await asyncio.to_thread(self._client.get_status)
|
|
179
|
+
_emit({"state": state})
|
|
180
|
+
except Exception as e:
|
|
181
|
+
_emit({"error": str(e)})
|
|
182
|
+
await asyncio.to_thread(self._client.connect) # reconnect
|
|
183
|
+
await asyncio.sleep(self.POLL_INTERVAL)
|
|
184
|
+
|
|
185
|
+
async def _command_loop(self):
|
|
186
|
+
loop = asyncio.get_event_loop()
|
|
187
|
+
reader = asyncio.StreamReader()
|
|
188
|
+
protocol = asyncio.StreamReaderProtocol(reader)
|
|
189
|
+
await loop.connect_read_pipe(lambda: protocol, sys.stdin)
|
|
190
|
+
async for line in reader:
|
|
191
|
+
try:
|
|
192
|
+
msg = json.loads(line)
|
|
193
|
+
cmd_id = msg["id"]
|
|
194
|
+
values = msg.get("args", {})
|
|
195
|
+
await asyncio.to_thread(self._client.set_values, values)
|
|
196
|
+
_emit({"id": cmd_id, "result": "ok"})
|
|
197
|
+
except Exception as e:
|
|
198
|
+
_emit({"id": msg.get("id"), "result": "error", "error": str(e)})
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
#### `--protocol` arg in `main()`
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
parser.add_argument("--protocol", choices=["coap", "http"], default="coap")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
In the `--daemon` branch:
|
|
208
|
+
```python
|
|
209
|
+
if args.protocol == "http":
|
|
210
|
+
daemon = HTTPPollingDaemon(args.host)
|
|
211
|
+
else:
|
|
212
|
+
daemon = ObserveDaemon(args.host)
|
|
213
|
+
asyncio.run(daemon.run())
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Field name mapping
|
|
217
|
+
|
|
218
|
+
HTTP and CoAP use the same JSON field names (`pwr`, `om`, `mode`, `aqil`, `cl`, etc.) — **no changes needed to index.js HomeKit mapping**.
|
|
219
|
+
|
|
220
|
+
### Polling interval
|
|
221
|
+
|
|
222
|
+
10 seconds. Less responsive than CoAP Observe (instant push) but acceptable for HomeKit. Device state can appear stale for up to 10s after a physical button press.
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## README.md Changes
|
|
227
|
+
|
|
228
|
+
### Features section
|
|
229
|
+
|
|
230
|
+
Add one new bullet and update the real-time updates bullet:
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
- **HTTP Protocol Support** — Supports AC1xxx-series models (e.g. AC1715) that use HTTP instead of CoAP
|
|
234
|
+
- **Real-time Updates** — CoAP Observe push updates (AC2xxx+) or 10-second HTTP polling (AC1xxx)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Configuration Options table
|
|
238
|
+
|
|
239
|
+
Add `protocol` row after `host`:
|
|
240
|
+
|
|
241
|
+
| Option | Required | Default | Description |
|
|
242
|
+
|--------|----------|---------|-------------|
|
|
243
|
+
| `protocol` | No | `coap` | Communication protocol. Set to `http` for AC1xxx models (AC1715, etc.) that do not support CoAP. |
|
|
244
|
+
|
|
245
|
+
### Config JSON example
|
|
246
|
+
|
|
247
|
+
Add a second example block after the existing one:
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"accessories": [
|
|
252
|
+
{
|
|
253
|
+
"accessory": "PhilipsAirPurifier",
|
|
254
|
+
"name": "Bedroom Air Purifier",
|
|
255
|
+
"host": "192.168.1.101",
|
|
256
|
+
"protocol": "http"
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### New "Model Compatibility" section
|
|
263
|
+
|
|
264
|
+
Insert after "Configuration Options", before "Connectivity Check":
|
|
265
|
+
|
|
266
|
+
```markdown
|
|
267
|
+
### Model Compatibility
|
|
268
|
+
|
|
269
|
+
| Protocol | Models | Notes |
|
|
270
|
+
|----------|--------|-------|
|
|
271
|
+
| `coap` (default) | AC2xxx, AC3xxx, AC4xxx | CoAP Observe push updates |
|
|
272
|
+
| `http` | AC1xxx (e.g. AC1715) | HTTP polling every 10 seconds |
|
|
273
|
+
|
|
274
|
+
If your device shows `Network error: NetworkError` on every command, try setting `"protocol": "http"` in your accessory config.
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Troubleshooting section
|
|
278
|
+
|
|
279
|
+
Add entry:
|
|
280
|
+
|
|
281
|
+
```markdown
|
|
282
|
+
- **`Network error: NetworkError` on every command**: Your device may use HTTP instead of CoAP.
|
|
283
|
+
Set `"protocol": "http"` in your Homebridge accessory configuration. This affects AC1xxx models
|
|
284
|
+
(e.g. AC1715) which do not expose a CoAP server on UDP port 5683.
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## CHANGELOG.md Changes
|
|
290
|
+
|
|
291
|
+
Insert a new block at the top (after the `---` header divider), before the existing `## [2.1.0]` entry:
|
|
292
|
+
|
|
293
|
+
```markdown
|
|
294
|
+
## [2.2.0] — YYYY-MM-DD
|
|
295
|
+
|
|
296
|
+
### Added
|
|
297
|
+
|
|
298
|
+
- HTTP protocol support for Philips AC1xxx-series devices (e.g. AC1715) that do not implement
|
|
299
|
+
CoAP. Set `"protocol": "http"` in your Homebridge accessory configuration to use this mode.
|
|
300
|
+
HTTP devices use 10-second polling instead of CoAP Observe push updates.
|
|
301
|
+
- New `protocol` config option (`"coap"` | `"http"`, default `"coap"`). Each accessory
|
|
302
|
+
configures its protocol independently, so mixed households (AC1715 + AC3858) work without
|
|
303
|
+
any shared state.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Also bump `"version"` in `package.json` from `"2.1.0"` to `"2.2.0"`.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Verification
|
|
313
|
+
|
|
314
|
+
1. Set `"protocol": "http"` in Homebridge config for a device
|
|
315
|
+
2. Restart Homebridge — logs should show `Daemon ready` with no `NetworkError`
|
|
316
|
+
3. Confirm on/off, fan speed, and mode commands work from HomeKit
|
|
317
|
+
4. Confirm state updates appear within ~10s if device state changes externally
|
|
318
|
+
5. Verify CoAP path (no `protocol` set) still works — no regression
|
|
319
|
+
6. `npm run lint` passes
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## Out of Scope
|
|
324
|
+
|
|
325
|
+
- Auto-protocol detection (adds complexity; users know their model)
|
|
326
|
+
- Filter/firmware status via HTTP (can be added later via `/di/v1/products/1/fltsts`)
|
package/config.schema.json
CHANGED
|
@@ -21,6 +21,13 @@
|
|
|
21
21
|
"placeholder": "192.168.1.100",
|
|
22
22
|
"description": "IP address of your Philips Air Purifier"
|
|
23
23
|
},
|
|
24
|
+
"protocol": {
|
|
25
|
+
"title": "Protocol",
|
|
26
|
+
"type": "string",
|
|
27
|
+
"enum": ["coap", "http"],
|
|
28
|
+
"default": "coap",
|
|
29
|
+
"description": "Communication protocol. Use 'http' for AC1xxx models (AC1715, etc.) that do not support CoAP."
|
|
30
|
+
},
|
|
24
31
|
"pythonPath": {
|
|
25
32
|
"title": "Python Path (Optional)",
|
|
26
33
|
"type": "string",
|
|
@@ -35,7 +42,7 @@
|
|
|
35
42
|
"type": "fieldset",
|
|
36
43
|
"title": "Device Settings",
|
|
37
44
|
"expandable": false,
|
|
38
|
-
"items": ["name", "host"]
|
|
45
|
+
"items": ["name", "host", "protocol"]
|
|
39
46
|
},
|
|
40
47
|
{
|
|
41
48
|
"type": "fieldset",
|