homebridge-dyson-solarcycle-morph 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/LICENSE +22 -0
- package/README.md +259 -0
- package/config.schema.json +118 -0
- package/dist/accessory.d.ts +41 -0
- package/dist/accessory.js +129 -0
- package/dist/accessory.js.map +1 -0
- package/dist/cli/pair.d.ts +2 -0
- package/dist/cli/pair.js +144 -0
- package/dist/cli/pair.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +32 -0
- package/dist/config.js.map +1 -0
- package/dist/dyson/cloud.d.ts +67 -0
- package/dist/dyson/cloud.js +147 -0
- package/dist/dyson/cloud.js.map +1 -0
- package/dist/dyson/credentials.d.ts +32 -0
- package/dist/dyson/credentials.js +73 -0
- package/dist/dyson/credentials.js.map +1 -0
- package/dist/dyson/crypto.d.ts +38 -0
- package/dist/dyson/crypto.js +98 -0
- package/dist/dyson/crypto.js.map +1 -0
- package/dist/dyson/debounce.d.ts +33 -0
- package/dist/dyson/debounce.js +59 -0
- package/dist/dyson/debounce.js.map +1 -0
- package/dist/dyson/lamp.d.ts +193 -0
- package/dist/dyson/lamp.js +692 -0
- package/dist/dyson/lamp.js.map +1 -0
- package/dist/dyson/protocol.d.ts +91 -0
- package/dist/dyson/protocol.js +156 -0
- package/dist/dyson/protocol.js.map +1 -0
- package/dist/dyson/queue.d.ts +24 -0
- package/dist/dyson/queue.js +51 -0
- package/dist/dyson/queue.js.map +1 -0
- package/dist/dyson/reconcile.d.ts +38 -0
- package/dist/dyson/reconcile.js +30 -0
- package/dist/dyson/reconcile.js.map +1 -0
- package/dist/dyson/settle.d.ts +30 -0
- package/dist/dyson/settle.js +56 -0
- package/dist/dyson/settle.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/platform.d.ts +27 -0
- package/dist/platform.js +106 -0
- package/dist/platform.js.map +1 -0
- package/dist/settings.d.ts +4 -0
- package/dist/settings.js +5 -0
- package/dist/settings.js.map +1 -0
- package/docs/PROTOCOL.md +153 -0
- package/homebridge-ui/public/index.html +396 -0
- package/homebridge-ui/server.js +297 -0
- package/package.json +68 -0
- package/tools/ble-probe.js +132 -0
package/dist/platform.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describeError } from './errors.js';
|
|
2
|
+
import { MorphAccessory } from './accessory.js';
|
|
3
|
+
import { validateLightConfig } from './config.js';
|
|
4
|
+
import { CredentialStore } from './dyson/credentials.js';
|
|
5
|
+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
6
|
+
/**
|
|
7
|
+
* Registers one HomeKit accessory per configured lamp and owns their lifecycle.
|
|
8
|
+
*/
|
|
9
|
+
export class MorphPlatform {
|
|
10
|
+
log;
|
|
11
|
+
config;
|
|
12
|
+
api;
|
|
13
|
+
/** Accessories restored from Homebridge's cache, keyed by UUID. */
|
|
14
|
+
cached = new Map();
|
|
15
|
+
lamps = [];
|
|
16
|
+
credentials;
|
|
17
|
+
constructor(log, config, api) {
|
|
18
|
+
this.log = log;
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.api = api;
|
|
21
|
+
this.credentials = new CredentialStore(api.user.storagePath(), PLUGIN_NAME);
|
|
22
|
+
this.api.on('didFinishLaunching', () => void this.discoverDevices());
|
|
23
|
+
this.api.on('shutdown', () => {
|
|
24
|
+
void Promise.all(this.lamps.map((lamp) => lamp.stop()));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Homebridge replays cached accessories here before `didFinishLaunching`. */
|
|
28
|
+
configureAccessory(accessory) {
|
|
29
|
+
this.cached.set(accessory.UUID, accessory);
|
|
30
|
+
}
|
|
31
|
+
async discoverDevices() {
|
|
32
|
+
const lights = this.config.lights ?? [];
|
|
33
|
+
if (lights.length === 0) {
|
|
34
|
+
this.log.warn('No lights configured — nothing to do. Add a "lights" entry to config.json.');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const configured = new Set();
|
|
38
|
+
for (const [index, light] of lights.entries()) {
|
|
39
|
+
const problems = validateLightConfig(light, index);
|
|
40
|
+
if (problems.length > 0) {
|
|
41
|
+
for (const problem of problems) {
|
|
42
|
+
this.log.error(`Ignoring invalid light config: ${problem}`);
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const resolved = await this.resolveCredentials(light);
|
|
47
|
+
if (!resolved) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// Keyed on the serial so renaming a lamp does not orphan its accessory.
|
|
51
|
+
const uuid = this.api.hap.uuid.generate(`${PLUGIN_NAME}:${light.serial}`);
|
|
52
|
+
configured.add(uuid);
|
|
53
|
+
let accessory = this.cached.get(uuid);
|
|
54
|
+
if (accessory) {
|
|
55
|
+
accessory.displayName = light.name;
|
|
56
|
+
accessory.context.light = light;
|
|
57
|
+
this.api.updatePlatformAccessories([accessory]);
|
|
58
|
+
this.log.info(`Restoring ${light.name} (${light.mac})`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
accessory = new this.api.platformAccessory(light.name, uuid);
|
|
62
|
+
accessory.context.light = light;
|
|
63
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
64
|
+
this.log.info(`Adding ${light.name} (${light.mac})`);
|
|
65
|
+
}
|
|
66
|
+
const lamp = new MorphAccessory(this, accessory, resolved);
|
|
67
|
+
this.lamps.push(lamp);
|
|
68
|
+
void lamp.start();
|
|
69
|
+
}
|
|
70
|
+
this.pruneStaleAccessories(configured);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Fill in a lamp's credentials from the store when the config omits them.
|
|
74
|
+
*
|
|
75
|
+
* Config wins when it supplies both, so an existing setup keeps working and
|
|
76
|
+
* an override is always possible; otherwise the pairing done in the custom UI
|
|
77
|
+
* is what counts.
|
|
78
|
+
*/
|
|
79
|
+
async resolveCredentials(light) {
|
|
80
|
+
if (light.ltk && light.accountId) {
|
|
81
|
+
return { ...light, ltk: light.ltk, accountId: light.accountId };
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const stored = await this.credentials.get(light.serial);
|
|
85
|
+
if (stored) {
|
|
86
|
+
return { ...light, ltk: stored.ltk, accountId: stored.accountId };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.log.error(`Could not read stored credentials for ${light.name}: ${describeError(error)}`);
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
this.log.error(`${light.name} (${light.serial}) is not paired yet. Open this plugin's settings in the ` +
|
|
94
|
+
'Homebridge UI and authorise your MyDyson account there.');
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
pruneStaleAccessories(configured) {
|
|
98
|
+
// Drop accessories whose lamp was removed from config.json.
|
|
99
|
+
const stale = [...this.cached.entries()].filter(([uuid]) => !configured.has(uuid));
|
|
100
|
+
if (stale.length > 0) {
|
|
101
|
+
this.log.info(`Removing ${stale.length} accessory/accessories no longer in config`);
|
|
102
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, stale.map(([, accessory]) => accessory));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQ5C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAwE,MAAM,aAAa,CAAC;AACxH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,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AAK,CAAC,EAAE,CAAC,CAAC;YAC/F,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CACZ,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,MAAM,0DAA0D;YACtF,yDAAyD,CAC5D,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,qBAAqB,CAAC,UAAuB;QACnD,4DAA4D;QAC5D,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACnF,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,MAAM,4CAA4C,CAAC,CAAC;YACpF,IAAI,CAAC,GAAG,CAAC,6BAA6B,CACpC,WAAW,EACX,aAAa,EACb,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CACxC,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Must match the `platform` name used in Homebridge's config.json. */
|
|
2
|
+
export const PLATFORM_NAME = 'DysonSolarcycleMorph';
|
|
3
|
+
/** Must match the `name` field in package.json. */
|
|
4
|
+
export const PLUGIN_NAME = 'homebridge-dyson-solarcycle-morph';
|
|
5
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,CAAC,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAEpD,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,mCAAmC,CAAC"}
|
package/docs/PROTOCOL.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Dyson Morph BLE protocol
|
|
2
|
+
|
|
3
|
+
Notes on the protocol this plugin speaks. Reverse-engineered by others; this
|
|
4
|
+
file records what the implementation relies on, so a future reader can tell
|
|
5
|
+
what is verified from what is assumed.
|
|
6
|
+
|
|
7
|
+
**Source:** the protocol was reverse-engineered from the MyDyson Android app
|
|
8
|
+
(`g20/a.java`, `g20/b.java`, `g20/c.java`) by S-Termi and documented in
|
|
9
|
+
[cmgrayb/hass-dyson](https://github.com/cmgrayb/hass-dyson) under
|
|
10
|
+
`.github/design/ble_lights.md`. Verified there against the Lightcycle Morph
|
|
11
|
+
(CD06) and Solarcycle Morph (CF06).
|
|
12
|
+
|
|
13
|
+
## GATT layout
|
|
14
|
+
|
|
15
|
+
**Observed on a Solarcycle Morph desk light, model CD06** (serial `ABC-EU-…`;
|
|
16
|
+
the lamp advertises its serial as its BLE name). It differs from the published
|
|
17
|
+
notes in two ways worth knowing:
|
|
18
|
+
|
|
19
|
+
Characteristics are spread over **three** services, not one:
|
|
20
|
+
|
|
21
|
+
| Service | Characteristics |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `2dd10010-…` | `2dd10011` auth, `2dd10013` RSSI |
|
|
24
|
+
| `2dd10020-…` | `2dd10021` attribute write |
|
|
25
|
+
| `2dd1fff0-…` | `2dd11000`, `01`, `04`, `05`, `06`, `07`, `08`, `09` |
|
|
26
|
+
|
|
27
|
+
The client therefore discovers by sweeping every service and matching on the
|
|
28
|
+
characteristic UUID, which is unique on its own.
|
|
29
|
+
|
|
30
|
+
| UUID | Flags (observed) | Format | Meaning |
|
|
31
|
+
|---|---|---|---|
|
|
32
|
+
| `2dd10011-…` | write-without-response, notify | framed messages | Authentication channel |
|
|
33
|
+
| `2dd10013-…` | read, notify | int8 | RSSI, readable **without** auth |
|
|
34
|
+
| `2dd10021-…` | write-without-response, notify | attribute TLV | Attribute writes (daylight mode) |
|
|
35
|
+
| `2dd11000-…` | read, write-without-response, notify | uint8 | Brightness 0–100 % (lamps without daylight) |
|
|
36
|
+
| `2dd11001-…` | read, write-without-response, notify | uint16 LE | Colour temperature, 2700–6500 K |
|
|
37
|
+
| `2dd11004-…` | read | — | Undocumented, not decoded |
|
|
38
|
+
| `2dd11005-…` | read, write-without-response, notify | uint8 | Power: 0 = off, 1 = on |
|
|
39
|
+
| `2dd11006-…` | read, write-without-response, notify | — | Runtime / schedule flags, not decoded |
|
|
40
|
+
| `2dd11007-…` | read, write-without-response, notify | — | Ambient sensor, not decoded |
|
|
41
|
+
| `2dd11008-…` | read, notify | bytes | Motion: any non-zero byte = detected |
|
|
42
|
+
| `2dd11009-…` | read, write-without-response, notify | uint16 LE | Brightness 100–1000 lm (CD06/CF06) |
|
|
43
|
+
|
|
44
|
+
The published notes say brightness, colour temperature and daylight-mode writes
|
|
45
|
+
must be **acknowledged** (`write-with-response`), because the lamp otherwise
|
|
46
|
+
discards them. That does not hold here: this lamp declares no `write` flag at
|
|
47
|
+
all, only `write-without-response`, and unacknowledged writes to power,
|
|
48
|
+
brightness and colour temperature **do take effect** — verified on hardware.
|
|
49
|
+
The client picks the mode from each characteristic's advertised flags rather
|
|
50
|
+
than assuming either, so models that do offer `write` still get acknowledged
|
|
51
|
+
writes.
|
|
52
|
+
|
|
53
|
+
Every characteristic except `2dd10013` (RSSI) returns `Operation Not Authorized`
|
|
54
|
+
for reads and notifications until the handshake below completes — confirmed on
|
|
55
|
+
hardware, as is the fact that they read and write normally afterwards.
|
|
56
|
+
|
|
57
|
+
Connecting is unreliable in a way that is worth expecting: BlueZ commonly
|
|
58
|
+
returns `le-connection-abort-by-local` for the first two or three attempts
|
|
59
|
+
before one succeeds, so the client retries with backoff rather than treating it
|
|
60
|
+
as fatal.
|
|
61
|
+
|
|
62
|
+
Separately, the lamp can reach a state where it keeps advertising at full signal
|
|
63
|
+
strength but refuses every connection, indefinitely — over a hundred attempts in
|
|
64
|
+
one observed stretch. **Removing its power for ten seconds clears it**, twice
|
|
65
|
+
reproduced. Nothing on the client side was found to help: connecting from the
|
|
66
|
+
cached record, rediscovering it, scanning during the connect and waiting for a
|
|
67
|
+
fresh advertisement were each tried and each failed while it was in that state.
|
|
68
|
+
The client therefore thins its retries out rather than hammering, and says in
|
|
69
|
+
the log what actually works.
|
|
70
|
+
|
|
71
|
+
Before writing brightness or colour temperature, write
|
|
72
|
+
`13 20 01 00 00` to `2dd10021-…` to leave daylight mode, then wait ~200 ms.
|
|
73
|
+
There is no way to read the current mode back, so the plugin re-asserts it on a
|
|
74
|
+
TTL (see `MANUAL_MODE_TTL_MS`).
|
|
75
|
+
|
|
76
|
+
## Message framing on the auth channel
|
|
77
|
+
|
|
78
|
+
Every write and notification on `2dd10011-…` is a fragment:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
first fragment: [0x80 | (total - 1)] [type byte] [payload…]
|
|
82
|
+
later fragments: [fragment index] [payload…]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Capacity is 20 bytes per fragment — the MyDyson app's assumption, which we copy
|
|
86
|
+
rather than trusting the negotiated MTU.
|
|
87
|
+
|
|
88
|
+
## Authentication
|
|
89
|
+
|
|
90
|
+
The lamp ignores every control write until the handshake completes. Two paths
|
|
91
|
+
exist; this plugin implements only the second.
|
|
92
|
+
|
|
93
|
+
**Fresh pairing** (once, needs the physical Flash button and the Dyson cloud)
|
|
94
|
+
produces a long-term key. Message types `0x04`, `0x05`, `0x09`, `0x0D`, `0x01`,
|
|
95
|
+
`0x02`, `0x03`, with cloud calls to `/v1/lec/<serial>/{auth,verify,provision,ltk}`.
|
|
96
|
+
|
|
97
|
+
**LTK re-auth** (every connect, fully offline) is what the plugin runs:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
→ 0x0A request product info
|
|
101
|
+
← 0x0B product info
|
|
102
|
+
→ 0x06 account GUID(16) ‖ 00 00 ‖ seal(nonce) 82 bytes
|
|
103
|
+
← 0x07 00 00 ‖ IV(16) ‖ ct(32) ‖ MAC(32)?
|
|
104
|
+
→ 0x08 00 00 ‖ seal(challenge) 66 bytes
|
|
105
|
+
← 0x26 connection established
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`challenge` is the second 16-byte block of the decrypted `ct`; the first block
|
|
109
|
+
is our own nonce echoed back.
|
|
110
|
+
|
|
111
|
+
### Crypto
|
|
112
|
+
|
|
113
|
+
Dyson's own notes call this AES-GCM. It is not. The key is derived from the LTK
|
|
114
|
+
with HKDF-SHA256 (empty salt, info `USER_AUTH_AES\0\0\0`, first 16 bytes), and
|
|
115
|
+
`seal(x)` is unpadded AES-128-CBC followed by HMAC-SHA256 over the ciphertext —
|
|
116
|
+
encrypt-then-MAC, with one key used for both:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
seal(x) = IV(16) ‖ AES-128-CBC(key, IV, x) ‖ HMAC-SHA256(key, ciphertext)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`test/crypto.test.ts` pins this against vectors generated from the Python
|
|
123
|
+
reference implementation.
|
|
124
|
+
|
|
125
|
+
## Obtaining the LTK
|
|
126
|
+
|
|
127
|
+
If the lamp is already registered in the MyDyson app, no button press is
|
|
128
|
+
needed — `GET /v1/lec/<serial>/ltk` returns it, authenticated with a normal
|
|
129
|
+
account bearer token plus the header `X-Dyson-ApiAuthCode: 80541406` (a
|
|
130
|
+
well-known constant that the endpoint accepts in place of a session code).
|
|
131
|
+
`dyson-morph-pair` does this.
|
|
132
|
+
|
|
133
|
+
## Brightness is not a setpoint
|
|
134
|
+
|
|
135
|
+
The lamp adjusts its own brightness to track daylight, using its configured
|
|
136
|
+
location and the time of day: ask for 100% and it may settle at 88%. That is the
|
|
137
|
+
lamp working as intended, and it is indistinguishable from a command that was
|
|
138
|
+
dropped in transit.
|
|
139
|
+
|
|
140
|
+
Anything that verifies brightness by reading it back will therefore fight the
|
|
141
|
+
lamp. This client checks only power, which has an unambiguous outcome, and
|
|
142
|
+
treats brightness and colour temperature as fire-and-forget.
|
|
143
|
+
|
|
144
|
+
Writing `13 20 01 00 00` to `2dd10021-…` is documented as leaving daylight mode
|
|
145
|
+
so explicit values are accepted. Whether that also stops the tracking described
|
|
146
|
+
above, and whether brightness writes land without it, is **not established** —
|
|
147
|
+
the mode cannot be read back, so there is nothing to observe.
|
|
148
|
+
|
|
149
|
+
## Open questions
|
|
150
|
+
|
|
151
|
+
- `2dd11004-…`, `2dd11006-…` and `2dd11007-…` are not decoded.
|
|
152
|
+
- Daylight mode is write-only; the plugin cannot report whether it is active.
|
|
153
|
+
- Only the `0x2013` attribute is known for `2dd10021-…`.
|