Skip to content

v4.0.0#330

Merged
donavanbecker merged 4 commits intolatestfrom
beta-4.0.0
Apr 11, 2026
Merged

v4.0.0#330
donavanbecker merged 4 commits intolatestfrom
beta-4.0.0

Conversation

@donavanbecker
Copy link
Copy Markdown
Collaborator

4.0.0 (2026-04-10)

⚠ 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

Features

  • 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(), and clear() methods
  • Expanded Device Coverage: Added support and parsing updates across newly modeled devices and accessories in the v4 architecture.
  • macOS BLE Support: Enabled BLE functionality on macOS in addition to Linux
    • Platform detection now includes macOS (darwin) using @stoprocent/noble
    • BLE now works on Linux and macOS systems
    • Windows remains unsupported for BLE operations
  • Bot Password Protection: Added BLE password support for Bot (WoHand) devices
    • Password encryption using CRC32 checksums
    • Password validation for 4 alphanumeric characters, case-sensitive
    • Methods: setPassword(), clearPassword(), hasPassword()
    • Automatic encrypted command execution when password is set
    • Example: examples/bot-password.js
    • Based on homebridge-switchbot PR #1337
  • Advanced Resilience Features: Enterprise-grade reliability enhancements
    • Retry logic with exponential backoff and jitter
    • Circuit breaker pattern to prevent cascading failures
    • Connection intelligence tracking per-device success and failure rates
    • Custom fallback handler system for logging, metrics, and alerting
    • Intelligent connection selection based on historical performance
  • Event-Driven: EventEmitter-based architecture for discovery and command events
  • TypeScript Native: Written in TypeScript with full type safety and exports
  • Custom Errors: Specific error classes for better error handling
  • BLE-Only Mode: Works without OpenAPI credentials on Linux/macOS systems
  • API-Only Mode: Works without BLE on Windows systems
  • Exports and API Surface Updates: Updated src/index.ts exports for final v4 public API packaging.
  • Comprehensive Examples: Updated and aligned example files for v4 usage patterns.

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
  • Hardened dependency graph with security overrides for vulnerable transitive packages
  • Full JSDoc documentation coverage
  • Comprehensive TypeScript type definitions for all devices
  • Reworked test suite structure and coverage for APIs, devices, and utilities
  • Auto-formatting and linting with @antfu/eslint-config

Documentation

  • Updated README with v4 quick start and migration guide
  • 6 usage examples in examples/ directory
  • Migration guide from v3.x to v4.0.0
  • Added password protection section to BLE.md
  • Updated README.md with password examples
  • Created comprehensive password protection example
  • Updated examples index with bot-password.js
  • Updated platform support documentation to reflect macOS BLE support
  • Updated Linux-only references to Linux/macOS where applicable
  • Added comprehensive prerequisites guidance for BLE setup on macOS and Linux
    • macOS: Xcode and Bluetooth permissions requirements
    • Linux: system packages, non-root setup, and Raspberry Pi notes
    • Based on @stoprocent/noble prerequisites
  • Full API documentation via TypeDoc

Tests

  • Added 14 comprehensive password protection tests
  • Validation for CRC32 encryption, command building, and response parsing
  • Extended fallback and retry behavior coverage across BLE/API paths
  • 58 test files and 243 passing tests at release validation

Full Changelog: v3.6.8...v4.0.0

donavanbecker and others added 4 commits April 10, 2026 20:01
* 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

* **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()`, and `clear()` methods
* **Expanded Device Coverage**: Added support and parsing updates across newly modeled devices and accessories in the v4 architecture.
* **macOS BLE Support**: Enabled BLE functionality on macOS in addition to Linux
  * Platform detection now includes macOS (`darwin`) using `@stoprocent/noble`
  * BLE now works on Linux and macOS systems
  * Windows remains unsupported for BLE operations
* **Bot Password Protection**: Added BLE password support for Bot (`WoHand`) devices
  * Password encryption using CRC32 checksums
  * Password validation for 4 alphanumeric characters, case-sensitive
  * Methods: `setPassword()`, `clearPassword()`, `hasPassword()`
  * Automatic encrypted command execution when password is set
  * Example: `examples/bot-password.js`
  * Based on [homebridge-switchbot PR #1337](OpenWonderLabs/homebridge-switchbot#1337)
* **Advanced Resilience Features**: Enterprise-grade reliability enhancements
  * Retry logic with exponential backoff and jitter
  * Circuit breaker pattern to prevent cascading failures
  * Connection intelligence tracking per-device success and failure rates
  * Custom fallback handler system for logging, metrics, and alerting
  * Intelligent connection selection based on historical performance
* **Event-Driven**: EventEmitter-based architecture for discovery and command events
* **TypeScript Native**: Written in TypeScript with full type safety and exports
* **Custom Errors**: Specific error classes for better error handling
* **BLE-Only Mode**: Works without OpenAPI credentials on Linux/macOS systems
* **API-Only Mode**: Works without BLE on Windows systems
* **Exports and API Surface Updates**: Updated `src/index.ts` exports for final v4 public API packaging.
* **Comprehensive Examples**: Updated and aligned example files for v4 usage patterns.

* Complete ES2022 module implementation
* Improved error handling with custom error classes
* Better connection management and timeout handling
* Enhanced logging with configurable log levels
* Hardened dependency graph with security overrides for vulnerable transitive packages
* Full JSDoc documentation coverage
* Comprehensive TypeScript type definitions for all devices
* Reworked test suite structure and coverage for APIs, devices, and utilities
* Auto-formatting and linting with @antfu/eslint-config

* Updated README with v4 quick start and migration guide
* 6 usage examples in `examples/` directory
* Migration guide from v3.x to v4.0.0
* Added password protection section to [BLE.md](BLE.md)
* Updated [README.md](README.md) with password examples
* Created comprehensive password protection example
* Updated examples index with `bot-password.js`
* Updated platform support documentation to reflect macOS BLE support
* Updated Linux-only references to Linux/macOS where applicable
* Added comprehensive prerequisites guidance for BLE setup on macOS and Linux
  * macOS: Xcode and Bluetooth permissions requirements
  * Linux: system packages, non-root setup, and Raspberry Pi notes
  * Based on [@stoprocent/noble prerequisites](https://github.com/stoprocent/noble?tab=readme-ov-file#prerequisites)
* Full API documentation via TypeDoc

* Added 14 comprehensive password protection tests
* Validation for CRC32 encryption, command building, and response parsing
* Extended fallback and retry behavior coverage across BLE/API paths
* 58 test files and 243 passing tests at release validation

**Full Changelog**: v3.6.8...v4.0.0
Copilot AI review requested due to automatic review settings April 11, 2026 01:25
@donavanbecker donavanbecker merged commit d847f63 into latest Apr 11, 2026
13 checks passed
@donavanbecker donavanbecker deleted the beta-4.0.0 branch April 11, 2026 01:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Packages up the v4.0.0 documentation + GitHub automation updates to match the new unified SwitchBot API surface and generated TypeDoc site.

Changes:

  • Added/replaced TypeDoc-generated docs pages for the new v4 public API (and removed legacy v3 pages).
  • Updated README/OpenAPI docs to describe the new v4 hybrid architecture, discovery/device manager pattern, and client usage.
  • Reworked GitHub Actions release automation (beta + stable) and updated shared workflow sources.

Reviewed changes

Copilot reviewed 36 out of 542 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
docs/classes/ValidationError.html New TypeDoc page for v4 ValidationError.
docs/classes/SwitchBotError.html New TypeDoc page for v4 base error type.
docs/classes/SwitchBotBLE.html Removes v3 SwitchBotBLE docs page.
docs/classes/SwitchBot.html New TypeDoc page for unified v4 SwitchBot class.
docs/classes/ErrorUtils.html Removes v3 ErrorUtils docs page.
docs/classes/DiscoveryError.html New TypeDoc page for v4 DiscoveryError.
docs/classes/DeviceNotFoundError.html New TypeDoc page for v4 DeviceNotFoundError.
docs/classes/DeviceManager.html New TypeDoc page for v4 DeviceManager.
docs/classes/ConnectionTimeoutError.html New TypeDoc page for v4 ConnectionTimeoutError.
docs/classes/CommandFailedError.html New TypeDoc page for v4 CommandFailedError.
docs/classes/BLEScanner.html New TypeDoc page for v4 BLEScanner.
docs/classes/BLENotAvailableError.html New TypeDoc page for v4 BLENotAvailableError.
docs/classes/Advertising.html Removes v3 Advertising docs page.
docs/classes/APINotAvailableError.html New TypeDoc page for v4 APINotAvailableError.
docs/classes/APIError.html New TypeDoc page for v4 APIError.
docs/assets/navigation.js Updates TypeDoc navigation index payload.
docs/assets/highlight.css Updates syntax highlighting palette and adds additional highlight classes.
docs/assets/hierarchy.js Updates TypeDoc hierarchy payload.
README.md Adds v4 quick-start and migration guidance.
OpenAPI.md Rewrites OpenAPI docs to match v4 SwitchBot + OpenAPIClient.
.npmignore Adds v4-specific ignore entries for package publishing.
.github/workflows/stale.yml Switches reusable stale workflow source + adjusts cron schedule.
.github/workflows/release.yml Consolidates beta + stable release logic into one workflow.
.github/workflows/beta-release.yml Removes standalone beta release workflow (now handled in release.yml).
.github/copilot-instructions.md Updates platform/BLE prerequisite docs (Linux + macOS) for v4.

### Basic Usage

```javascript
import { SwitchBot } from 'node-switchbot'
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README examples currently call methods on switchbot.devices.get(...) without handling the documented undefined case (per DeviceManager docs, get() returns SwitchBotDevice | undefined), which would throw at runtime. Also, WoHand is used without being imported, and instantiating a device directly may not reflect the v4 recommended switchbot.devices pattern. Consider updating examples to either (a) check for a missing device before calling methods, and (b) show password protection via a device retrieved from switchbot.devices (or explicitly import WoHand and explain when direct instantiation is supported).

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +53
await bot.press()

// Get status
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README examples currently call methods on switchbot.devices.get(...) without handling the documented undefined case (per DeviceManager docs, get() returns SwitchBotDevice | undefined), which would throw at runtime. Also, WoHand is used without being imported, and instantiating a device directly may not reflect the v4 recommended switchbot.devices pattern. Consider updating examples to either (a) check for a missing device before calling methods, and (b) show password protection via a device retrieved from switchbot.devices (or explicitly import WoHand and explain when direct instantiation is supported).

Suggested change
await bot.press()
// Get status
if (!bot) {
throw new Error('Device not found. Check that YOUR_DEVICE_ID matches a discovered device.')
}
await bot.press()
// Get status

Copilot uses AI. Check for mistakes.
await bot.press()

// Bot with Password Protection (BLE only)
const protectedBot = new WoHand({ id: 'YOUR_BOT_ID', password: 'A1b2' })
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README examples currently call methods on switchbot.devices.get(...) without handling the documented undefined case (per DeviceManager docs, get() returns SwitchBotDevice | undefined), which would throw at runtime. Also, WoHand is used without being imported, and instantiating a device directly may not reflect the v4 recommended switchbot.devices pattern. Consider updating examples to either (a) check for a missing device before calling methods, and (b) show password protection via a device retrieved from switchbot.devices (or explicitly import WoHand and explain when direct instantiation is supported).

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +104
| Property | Type | Description |
| :-- | :-- | :-- |
| `scanBLE` | `boolean` | Enable BLE discovery for this call |
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The markdown tables use || at the start of rows, which renders incorrectly on GitHub (it introduces an extra empty column / breaks table parsing). Replace the leading || with a single | for each row so the tables render as intended.

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +145
| Method | Description |
| :-- | :-- |
| `getDevices()` | Fetch cloud devices |
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The markdown tables use || at the start of rows, which renders incorrectly on GitHub (it introduces an extra empty column / breaks table parsing). Replace the leading || with a single | for each row so the tables render as intended.

Copilot uses AI. Check for mistakes.
needs: lint
permissions:
id-token: write
uses: homebridge/.github/.github/workflows/npm-publish-esm-oidc.yml@latest
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
beta-pre-release:
if: startsWith(github.ref_name, 'beta')
needs: beta-publish
uses: homebridge/.github/.github/workflows/pre-release.yml@latest
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
# 6️⃣ Post to Discord (Beta + Stable)
discord:
name: Release Notifications
if: ${{ always() && ((startsWith(github.ref_name, 'beta') && needs.beta-publish.result == 'success') || (github.ref_name == 'latest' && needs.publish-release.result == 'success')) }}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +117
title: ${{ startsWith(github.ref_name, 'beta') && 'SwitchBot-Node Beta Release' || 'SwitchBot-Node Release' }}
description: |
Version `v${{ needs.update-version.outputs.version }}`
url: "https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v${{ needs.update-version.outputs.version }}"
Version `v${{ startsWith(github.ref_name, 'beta') && needs.beta-publish.outputs.NPM_VERSION || needs.update-version.outputs.version }}`
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two workflow reliability issues: (1) All reusable workflows are referenced via @latest, which is mutable and can break releases unexpectedly if upstream changes—prefer pinning to a specific tag or commit SHA. (2) The title/Version fields use &&/|| to emulate a ternary; switching to the explicit ternary operator makes it clearer and avoids accidental evaluation/empty values when a dependent job is skipped (e.g., update-version on beta).

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,22 @@
<!DOCTYPE html><html class="default" lang="en" data-base="../"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>SwitchBot | node-switchbot</title><meta name="description" content="Documentation for node-switchbot"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script><script async src="../assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="../index.html" class="title">node-switchbot</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"><li><a href="" aria-current="page">SwitchBot</a></li></ul><h1>Class SwitchBot</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Main SwitchBot class - Hybrid BLE/API with automatic fallback</p>
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR checks in large, generated TypeDoc HTML assets under docs/, which tends to create very noisy diffs and complicates reviews/merges. If these are intended to be published as a site, consider generating/publishing them via CI (e.g., GitHub Pages artifact) rather than committing the generated output, or at least keep generated docs isolated from source changes (separate commits/PR) so functional changes remain reviewable.

Copilot uses AI. Check for mistakes.
donavanbecker added a commit that referenced this pull request Apr 11, 2026
* 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

* **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()`, and `clear()` methods
* **Expanded Device Coverage**: Added support and parsing updates across newly modeled devices and accessories in the v4 architecture.
* **macOS BLE Support**: Enabled BLE functionality on macOS in addition to Linux
  * Platform detection now includes macOS (`darwin`) using `@stoprocent/noble`
  * BLE now works on Linux and macOS systems
  * Windows remains unsupported for BLE operations
* **Bot Password Protection**: Added BLE password support for Bot (`WoHand`) devices
  * Password encryption using CRC32 checksums
  * Password validation for 4 alphanumeric characters, case-sensitive
  * Methods: `setPassword()`, `clearPassword()`, `hasPassword()`
  * Automatic encrypted command execution when password is set
  * Example: `examples/bot-password.js`
  * Based on [homebridge-switchbot PR #1337](OpenWonderLabs/homebridge-switchbot#1337)
* **Advanced Resilience Features**: Enterprise-grade reliability enhancements
  * Retry logic with exponential backoff and jitter
  * Circuit breaker pattern to prevent cascading failures
  * Connection intelligence tracking per-device success and failure rates
  * Custom fallback handler system for logging, metrics, and alerting
  * Intelligent connection selection based on historical performance
* **Event-Driven**: EventEmitter-based architecture for discovery and command events
* **TypeScript Native**: Written in TypeScript with full type safety and exports
* **Custom Errors**: Specific error classes for better error handling
* **BLE-Only Mode**: Works without OpenAPI credentials on Linux/macOS systems
* **API-Only Mode**: Works without BLE on Windows systems
* **Exports and API Surface Updates**: Updated `src/index.ts` exports for final v4 public API packaging.
* **Comprehensive Examples**: Updated and aligned example files for v4 usage patterns.

* Complete ES2022 module implementation
* Improved error handling with custom error classes
* Better connection management and timeout handling
* Enhanced logging with configurable log levels
* Hardened dependency graph with security overrides for vulnerable transitive packages
* Full JSDoc documentation coverage
* Comprehensive TypeScript type definitions for all devices
* Reworked test suite structure and coverage for APIs, devices, and utilities
* Auto-formatting and linting with @antfu/eslint-config

* Updated README with v4 quick start and migration guide
* 6 usage examples in `examples/` directory
* Migration guide from v3.x to v4.0.0
* Added password protection section to [BLE.md](BLE.md)
* Updated [README.md](README.md) with password examples
* Created comprehensive password protection example
* Updated examples index with `bot-password.js`
* Updated platform support documentation to reflect macOS BLE support
* Updated Linux-only references to Linux/macOS where applicable
* Added comprehensive prerequisites guidance for BLE setup on macOS and Linux
  * macOS: Xcode and Bluetooth permissions requirements
  * Linux: system packages, non-root setup, and Raspberry Pi notes
  * Based on [@stoprocent/noble prerequisites](https://github.com/stoprocent/noble?tab=readme-ov-file#prerequisites)
* Full API documentation via TypeDoc

* Added 14 comprehensive password protection tests
* Validation for CRC32 encryption, command building, and response parsing
* Extended fallback and retry behavior coverage across BLE/API paths
* 58 test files and 243 passing tests at release validation

**Full Changelog**: v3.6.8...v4.0.0

chore(release): v3.6.9 [skip ci]
donavanbecker added a commit that referenced this pull request Apr 11, 2026
* 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

* **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()`, and `clear()` methods
* **Expanded Device Coverage**: Added support and parsing updates across newly modeled devices and accessories in the v4 architecture.
* **macOS BLE Support**: Enabled BLE functionality on macOS in addition to Linux
  * Platform detection now includes macOS (`darwin`) using `@stoprocent/noble`
  * BLE now works on Linux and macOS systems
  * Windows remains unsupported for BLE operations
* **Bot Password Protection**: Added BLE password support for Bot (`WoHand`) devices
  * Password encryption using CRC32 checksums
  * Password validation for 4 alphanumeric characters, case-sensitive
  * Methods: `setPassword()`, `clearPassword()`, `hasPassword()`
  * Automatic encrypted command execution when password is set
  * Example: `examples/bot-password.js`
  * Based on [homebridge-switchbot PR #1337](OpenWonderLabs/homebridge-switchbot#1337)
* **Advanced Resilience Features**: Enterprise-grade reliability enhancements
  * Retry logic with exponential backoff and jitter
  * Circuit breaker pattern to prevent cascading failures
  * Connection intelligence tracking per-device success and failure rates
  * Custom fallback handler system for logging, metrics, and alerting
  * Intelligent connection selection based on historical performance
* **Event-Driven**: EventEmitter-based architecture for discovery and command events
* **TypeScript Native**: Written in TypeScript with full type safety and exports
* **Custom Errors**: Specific error classes for better error handling
* **BLE-Only Mode**: Works without OpenAPI credentials on Linux/macOS systems
* **API-Only Mode**: Works without BLE on Windows systems
* **Exports and API Surface Updates**: Updated `src/index.ts` exports for final v4 public API packaging.
* **Comprehensive Examples**: Updated and aligned example files for v4 usage patterns.

* Complete ES2022 module implementation
* Improved error handling with custom error classes
* Better connection management and timeout handling
* Enhanced logging with configurable log levels
* Hardened dependency graph with security overrides for vulnerable transitive packages
* Full JSDoc documentation coverage
* Comprehensive TypeScript type definitions for all devices
* Reworked test suite structure and coverage for APIs, devices, and utilities
* Auto-formatting and linting with @antfu/eslint-config

* Updated README with v4 quick start and migration guide
* 6 usage examples in `examples/` directory
* Migration guide from v3.x to v4.0.0
* Added password protection section to [BLE.md](BLE.md)
* Updated [README.md](README.md) with password examples
* Created comprehensive password protection example
* Updated examples index with `bot-password.js`
* Updated platform support documentation to reflect macOS BLE support
* Updated Linux-only references to Linux/macOS where applicable
* Added comprehensive prerequisites guidance for BLE setup on macOS and Linux
  * macOS: Xcode and Bluetooth permissions requirements
  * Linux: system packages, non-root setup, and Raspberry Pi notes
  * Based on [@stoprocent/noble prerequisites](https://github.com/stoprocent/noble?tab=readme-ov-file#prerequisites)
* Full API documentation via TypeDoc

* Added 14 comprehensive password protection tests
* Validation for CRC32 encryption, command building, and response parsing
* Extended fallback and retry behavior coverage across BLE/API paths
* 58 test files and 243 passing tests at release validation

**Full Changelog**: v3.6.8...v4.0.0
donavanbecker added a commit that referenced this pull request Apr 11, 2026
## [4.0.0](v3.6.8...v4.0.0) (2026-04-10)

### ⚠ 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

### Features

* **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()`, and `clear()` methods
* **Expanded Device Coverage**: Added support and parsing updates across newly modeled devices and accessories in the v4 architecture.
* **macOS BLE Support**: Enabled BLE functionality on macOS in addition to Linux
  * Platform detection now includes macOS (`darwin`) using `@stoprocent/noble`
  * BLE now works on Linux and macOS systems
  * Windows remains unsupported for BLE operations
* **Bot Password Protection**: Added BLE password support for Bot (`WoHand`) devices
  * Password encryption using CRC32 checksums
  * Password validation for 4 alphanumeric characters, case-sensitive
  * Methods: `setPassword()`, `clearPassword()`, `hasPassword()`
  * Automatic encrypted command execution when password is set
  * Example: `examples/bot-password.js`
  * Based on [homebridge-switchbot PR #1337](OpenWonderLabs/homebridge-switchbot#1337)
* **Advanced Resilience Features**: Enterprise-grade reliability enhancements
  * Retry logic with exponential backoff and jitter
  * Circuit breaker pattern to prevent cascading failures
  * Connection intelligence tracking per-device success and failure rates
  * Custom fallback handler system for logging, metrics, and alerting
  * Intelligent connection selection based on historical performance
* **Event-Driven**: EventEmitter-based architecture for discovery and command events
* **TypeScript Native**: Written in TypeScript with full type safety and exports
* **Custom Errors**: Specific error classes for better error handling
* **BLE-Only Mode**: Works without OpenAPI credentials on Linux/macOS systems
* **API-Only Mode**: Works without BLE on Windows systems
* **Exports and API Surface Updates**: Updated `src/index.ts` exports for final v4 public API packaging.
* **Comprehensive Examples**: Updated and aligned example files for v4 usage patterns.

### 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
* Hardened dependency graph with security overrides for vulnerable transitive packages
* Full JSDoc documentation coverage
* Comprehensive TypeScript type definitions for all devices
* Reworked test suite structure and coverage for APIs, devices, and utilities
* Auto-formatting and linting with @antfu/eslint-config

### Documentation

* Updated README with v4 quick start and migration guide
* 6 usage examples in `examples/` directory
* Migration guide from v3.x to v4.0.0
* Added password protection section to [BLE.md](BLE.md)
* Updated [README.md](README.md) with password examples
* Created comprehensive password protection example
* Updated examples index with `bot-password.js`
* Updated platform support documentation to reflect macOS BLE support
* Updated Linux-only references to Linux/macOS where applicable
* Added comprehensive prerequisites guidance for BLE setup on macOS and Linux
  * macOS: Xcode and Bluetooth permissions requirements
  * Linux: system packages, non-root setup, and Raspberry Pi notes
  * Based on [@stoprocent/noble prerequisites](https://github.com/stoprocent/noble?tab=readme-ov-file#prerequisites)
* Full API documentation via TypeDoc

### Tests

* Added 14 comprehensive password protection tests
* Validation for CRC32 encryption, command building, and response parsing
* Extended fallback and retry behavior coverage across BLE/API paths
* 58 test files and 243 passing tests at release validation

**Full Changelog**: v3.6.8...v4.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants