Get active connection type (property accessor for convenience)
Get device type (property accessor for convenience)
Get device ID (property accessor for convenience)
Get MAC address (property accessor for convenience)
Get device name (property accessor for convenience)
Get active connection type
Get basic device info (universal settings retrieval) Returns: battery, firmware, device-specific settings, etc. Command: 0x57 0x02 (BLE), 'getBasicInfo' (API)
Example usage: const info = await device.getBasicInfo(); console.log(info);
Returns a CommandResult object with device info fields.
Get circuit breaker for API
Get circuit breaker for BLE
Get connection tracker for this device
Get device type
Get fallback handler manager
Get device ID
Get device information
Get MAC address (if available)
Get device name
Get device status (BLE-first/API-fallback, centralized)
Check if API is available for this device
Check if BLE is available for this device
Poll device status if needed (passive polling)
Returns true if device should be polled (passive polling interval elapsed)
Register a custom fallback handler
Optionaloptions: FallbackHandlerOptionsSend multiple commands in sequence (all must succeed) Used for Curtain 3, bulbs, strips, and other multi-step devices
Send multiple commands (returns true if any succeed) Used for fallback operations with complex patterns
Set brightness (1-100)
Enable or disable circuit breaker
Set color (RGB)
Set color temperature (Kelvin)
Enable or disable connection intelligence
Enable or disable fallback
Universal mode setting command BLE: 0x57 0x03 [modeByte] API: 'setMode' (if available)
Mode value (number or string, per-device enum recommended)
Example usage: await device.setMode('auto') await device.setMode(1)
Returns a CommandResult object indicating success and mode info.
Enable or disable retry logic
Turn off the neon wire rope light
Turn on the neon wire rope light
Unregister a fallback handler
Base class for all SwitchBot devices
BLE-first, API-fallback Logic
This class provides a centralized, robust hybrid connection strategy for all SwitchBot devices:
preferredConnectionandenableFallback.getStatusWithFallback()andsendCommand()methods implement this logic. Device subclasses should call these methods and provide normalization/mapping as needed.Usage in Subclasses
await this.getStatusWithFallback(normalizeBLE, normalizeAPI)in yourgetStatus()implementation.await this.sendCommand(bleCommand, apiCommand, apiParameter)to automatically select the best connection and handle fallback.Example (in a device subclass)
Configuration
preferredConnection: 'ble' | 'api' (default: 'ble')enableFallback: boolean (default: true)enableConnectionIntelligence: boolean (default: true)enableCircuitBreaker: boolean (default: true)enableRetry: boolean (default: true)See Also
getStatusWithFallback()sendCommand()hasBLE(),hasAPI()setPreferredConnection(),setFallbackEnabled()This pattern ensures all device classes benefit from robust, testable, and consistent connection logic.