Commit 2176af8
committed
v4.0.0
feat: v4.0.0 - Complete rewrite with hybrid BLE/API architecture and advanced features
BREAKING CHANGES:
- Complete rewrite with unified hybrid BLE/API architecture
- No backward compatibility with v3.x - migration required
- Single `SwitchBot` class replaces `SwitchBotBLE` and `SwitchBotOpenAPI`
- Device access via `switchbot.devices` manager pattern
- Full TypeScript rewrite with comprehensive type definitions
Major Features (v4.0.0):
- **Hybrid Architecture**: Unified BLE-first approach with automatic OpenAPI fallback
- **Automatic Discovery**: Combined BLE + OpenAPI device discovery in single call
- **Smart Fallback**: Commands automatically retry via API when BLE fails
- **Device Manager**: Centralized device management with get(), list(), clear()
- **30 Device Types**: Full support for all SwitchBot devices
- **Event-Driven**: EventEmitter-based architecture for discovery and commands
- **TypeScript Native**: Full type safety and comprehensive type exports
- **Custom Errors**: Specific error classes (BLENotAvailableError, DeviceNotFoundError, etc.)
- **Flexible Modes**: BLE-only mode (Linux/macOS) or API-only mode (all platforms)
Additional Features (Post-4.0.0):
- **macOS BLE Support**: Enable BLE on macOS in addition to Linux
* Platform detection now includes darwin (macOS)
* Windows remains unsupported for BLE operations
- **Bot Password Protection**: BLE password support for Bot devices
* CRC32 encryption for 4-char alphanumeric passwords
* Methods: setPassword(), clearPassword(), hasPassword()
* Automatic encrypted command execution
- **Advanced Resilience**: Enterprise-grade reliability features
* Retry logic with exponential backoff and jitter
* Circuit breaker pattern (CLOSED/OPEN/HALF_OPEN states)
* Connection intelligence tracking per-device
* Custom fallback handler system with logging, metrics, alerting
Technical Improvements:
- Complete ES2022 module implementation
- Improved error handling with custom error classes
- Better connection management and timeout handling
- Enhanced logging with configurable log levels
- Full JSDoc documentation coverage
- Comprehensive TypeScript type definitions
- Move regex patterns to module scope for performance
- Fix BLE Noble initialization race conditions
- Proper null checks to prevent "Cannot read properties of undefined"
Dependencies:
- Update @antfu/eslint-config from 5.4.1 to 7.7.0
- Update @types/node from 25.3.3 to 25.3.5
- Update eslint from 9.39.3 to 9.39.4
- Update @stoprocent/noble to ^2.3.17
Documentation:
- Add comprehensive prerequisites for BLE setup (macOS, Linux, Raspberry Pi)
- Update all "Linux-only" references to "Linux/macOS"
- Add password protection section to BLE.md
- Create bot-password.js example
- Add 6 example files covering all major use cases
- Generate TypeDoc API documentation
Tests:
- 108 comprehensive tests (up from 40 in v3.x)
- 14 new password protection tests
- Device manager tests
- Utilities tests
- Error handling tests
- Full validation of CRC32 encryption and command building
Files Changed: 431 files, 13,604 insertions(+), 12,376 deletions(-)1 parent db28768 commit 2176af8
558 files changed
Lines changed: 27226 additions & 15601 deletions
File tree
- .github
- docs
- assets
- classes
- enums
- functions
- interfaces
- media
- types
- variables
- examples
- src
- devices
- types
- utils
- test
- todo
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
29 | 43 | | |
30 | 44 | | |
31 | 45 | | |
| |||
116 | 130 | | |
117 | 131 | | |
118 | 132 | | |
119 | | - | |
| 133 | + | |
120 | 134 | | |
121 | | - | |
| 135 | + | |
122 | 136 | | |
123 | 137 | | |
124 | 138 | | |
| |||
156 | 170 | | |
157 | 171 | | |
158 | 172 | | |
159 | | - | |
| 173 | + | |
160 | 174 | | |
161 | 175 | | |
162 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
5 | 13 | | |
6 | 14 | | |
7 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
69 | 117 | | |
70 | 118 | | |
71 | 119 | | |
| |||
587 | 635 | | |
588 | 636 | | |
589 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
590 | 703 | | |
591 | 704 | | |
592 | 705 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
5 | 94 | | |
6 | 95 | | |
7 | 96 | | |
| |||
0 commit comments