Commit 0d2e215
authored
Fix macOS BLE Bot control (#334)
## Summary
- Allows macOS BLE-only SwitchBot Bot devices to be controlled when
noble exposes a peripheral ID but no usable MAC address.
- Passes live BLE/API handles into discovered device instances so
BLE-capable devices are actually commandable after discovery.
- Lets device implementations explicitly mark BLE commands as
write-only, and applies that to standard Bot action commands.
- Avoids fatal unhandled EventEmitter `error` events when device command
failures are already returned to the caller.
## Root Cause
On macOS, noble may discover a SwitchBot Bot by peripheral ID rather
than MAC address and stores discovered peripherals in its private
`_peripherals` map. The existing BLE availability and connect paths
assumed a MAC/public peripheral list. Standard Bot action commands also
do not provide the response expected by the response-validating command
path, so they need to be sent as write-only BLE commands.
Separately, command failures logged and returned failure objects but
also emitted EventEmitter `error` events. In consumers without an
`error` listener, Node treats that as fatal and can crash the process
instead of letting the integration handle the returned command failure.
## Changes
- Treat `bleId` as sufficient for BLE availability when a MAC address is
unavailable.
- Pass the initialized `BLEConnection` and `OpenAPIClient` into created
device instances.
- Read known peripherals from noble `peripherals` or `_peripherals`,
including array, map, and object forms.
- Add an internal `writeOnly` boolean for BLE commands.
- Mark standard Bot action commands as write-only while leaving other
BLE commands on the normal response-validating path.
- Emit device `error` events only when a listener is registered.
## Validation
- `npm run lint`
- `npm run build`
- `npm test`
## Notes
- This is the lower-level BLE fix.1 parent d804942 commit 0d2e215
4 files changed
Lines changed: 51 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
622 | 640 | | |
623 | 641 | | |
624 | 642 | | |
| |||
831 | 849 | | |
832 | 850 | | |
833 | 851 | | |
834 | | - | |
| 852 | + | |
835 | 853 | | |
836 | 854 | | |
837 | 855 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
323 | 329 | | |
324 | 330 | | |
325 | 331 | | |
| |||
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
| 377 | + | |
371 | 378 | | |
372 | 379 | | |
373 | 380 | | |
| |||
394 | 401 | | |
395 | 402 | | |
396 | 403 | | |
397 | | - | |
| 404 | + | |
398 | 405 | | |
399 | 406 | | |
400 | 407 | | |
| |||
406 | 413 | | |
407 | 414 | | |
408 | 415 | | |
409 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
410 | 419 | | |
411 | 420 | | |
412 | 421 | | |
| |||
459 | 468 | | |
460 | 469 | | |
461 | 470 | | |
462 | | - | |
| 471 | + | |
463 | 472 | | |
464 | 473 | | |
465 | 474 | | |
| |||
540 | 549 | | |
541 | 550 | | |
542 | 551 | | |
543 | | - | |
| 552 | + | |
544 | 553 | | |
545 | 554 | | |
546 | 555 | | |
| |||
587 | 596 | | |
588 | 597 | | |
589 | 598 | | |
| 599 | + | |
590 | 600 | | |
591 | 601 | | |
592 | 602 | | |
| |||
628 | 638 | | |
629 | 639 | | |
630 | 640 | | |
631 | | - | |
| 641 | + | |
632 | 642 | | |
633 | 643 | | |
634 | 644 | | |
| |||
652 | 662 | | |
653 | 663 | | |
654 | 664 | | |
655 | | - | |
| 665 | + | |
656 | 666 | | |
657 | 667 | | |
658 | 668 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| 94 | + | |
| 95 | + | |
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
| |||
106 | 110 | | |
107 | 111 | | |
108 | 112 | | |
| 113 | + | |
| 114 | + | |
109 | 115 | | |
110 | 116 | | |
111 | 117 | | |
| |||
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| 132 | + | |
| 133 | + | |
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
| |||
159 | 167 | | |
160 | 168 | | |
161 | 169 | | |
| 170 | + | |
| 171 | + | |
162 | 172 | | |
163 | 173 | | |
164 | 174 | | |
| |||
170 | 180 | | |
171 | 181 | | |
172 | 182 | | |
| 183 | + | |
| 184 | + | |
173 | 185 | | |
174 | 186 | | |
175 | 187 | | |
| |||
209 | 221 | | |
210 | 222 | | |
211 | 223 | | |
212 | | - | |
| 224 | + | |
213 | 225 | | |
214 | 226 | | |
215 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
549 | 549 | | |
550 | 550 | | |
551 | 551 | | |
| 552 | + | |
| 553 | + | |
552 | 554 | | |
553 | 555 | | |
554 | 556 | | |
| |||
0 commit comments