node-switchbot
Version:
The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).
1,218 lines • 64.7 kB
TypeScript
import type { Characteristic, Noble, Peripheral } from '@stoprocent/noble';
import type { airPurifierServiceData, airPurifierTableServiceData, batteryCirculatorFanServiceData, blindTiltServiceData, botServiceData, ceilingLightProServiceData, ceilingLightServiceData, colorBulbServiceData, contactSensorServiceData, curtain3ServiceData, curtainServiceData, hub2ServiceData, hub3ServiceData, humidifier2ServiceData, humidifierServiceData, keypadDetectorServiceData, lockProServiceData, lockServiceData, meterPlusServiceData, meterProCO2ServiceData, meterProServiceData, meterServiceData, motionSensorServiceData, outdoorMeterServiceData, plugMiniJPServiceData, plugMiniUSServiceData, presenceSensorServiceData, relaySwitch1PMServiceData, relaySwitch1ServiceData, remoteServiceData, robotVacuumCleanerServiceData, stripLightServiceData, waterLeakDetectorServiceData } from './types/ble.js';
import { Buffer } from 'node:buffer';
import { EventEmitter } from 'node:events';
export type MacAddress = string;
export interface ad {
id: string;
address: string;
rssi: number;
serviceData: airPurifierServiceData | airPurifierTableServiceData | botServiceData | colorBulbServiceData | contactSensorServiceData | curtainServiceData | curtain3ServiceData | stripLightServiceData | lockServiceData | lockProServiceData | meterServiceData | meterPlusServiceData | meterProServiceData | meterProCO2ServiceData | motionSensorServiceData | presenceSensorServiceData | outdoorMeterServiceData | plugMiniUSServiceData | plugMiniJPServiceData | blindTiltServiceData | ceilingLightServiceData | ceilingLightProServiceData | hub2ServiceData | hub3ServiceData | batteryCirculatorFanServiceData | waterLeakDetectorServiceData | humidifierServiceData | humidifier2ServiceData | robotVacuumCleanerServiceData | keypadDetectorServiceData | relaySwitch1PMServiceData | relaySwitch1ServiceData | remoteServiceData;
[key: string]: unknown;
}
export type ondiscover = (device: SwitchbotDevice) => Promise<void> | void;
export type onadvertisement = (ad: ad) => Promise<void> | void;
interface DeviceInfo {
Model: SwitchBotModel;
BLEModel: SwitchBotBLEModel;
BLEModelName: SwitchBotBLEModelName;
ModelFriendlyName: SwitchBotBLEModelFriendlyName;
}
export declare interface SwitchBotBLEDevice {
Bot: DeviceInfo;
Curtain: DeviceInfo;
Curtain3: DeviceInfo;
Humidifier: DeviceInfo;
Meter: DeviceInfo;
MeterPlus: DeviceInfo;
MeterPro: DeviceInfo;
MeterProCO2: DeviceInfo;
Hub2: DeviceInfo;
Hub3: DeviceInfo;
OutdoorMeter: DeviceInfo;
MotionSensor: DeviceInfo;
PresenceSensor: DeviceInfo;
ContactSensor: DeviceInfo;
ColorBulb: DeviceInfo;
StripLight: DeviceInfo;
PlugMiniUS: DeviceInfo;
PlugMiniJP: DeviceInfo;
Lock: DeviceInfo;
LockPro: DeviceInfo;
CeilingLight: DeviceInfo;
CeilingLightPro: DeviceInfo;
BlindTilt: DeviceInfo;
Unknown: DeviceInfo;
AirPurifier: DeviceInfo;
AirPurifierTable: DeviceInfo;
}
export declare enum SwitchBotModel {
HubMini = "W0202200",
HubPlus = "SwitchBot Hub S1",
Hub2 = "W3202100",
Hub3 = "W3302100",
Bot = "SwitchBot S1",
Curtain = "W0701600",
Curtain3 = "W2400000",
Humidifier = "W0801800",
Humidifier2 = "WXXXXXXX",
Plug = "SP11",// Currently only available in Japan
Meter = "SwitchBot MeterTH S1",
MeterPlusJP = "W2201500",
MeterPlusUS = "W2301500",
MeterPro = "W4900000",
MeterProCO2 = "W4900010",
OutdoorMeter = "W3400010",
MotionSensor = "W1101500",
PresenceSensor = "W8200000",
ContactSensor = "W1201500",
ColorBulb = "W1401400",
StripLight = "W1701100",
PlugMiniUS = "W1901400/W1901401",
PlugMiniJP = "W2001400/W2001401",
Lock = "W1601700",
LockPro = "W3500000",
Keypad = "W2500010",
KeypadTouch = "W2500020",
K10 = "K10+",
K10Pro = "K10+ Pro",
WoSweeper = "WoSweeper",
WoSweeperMini = "WoSweeperMini",
RobotVacuumCleanerS1 = "W3011000",// Currently only available in Japan.
RobotVacuumCleanerS1Plus = "W3011010",// Currently only available in Japan.
RobotVacuumCleanerS10 = "W3211800",
Remote = "Remote",
UniversalRemote = "UniversalRemote",
CeilingLight = "W2612230/W2612240",// Currently only available in Japan.
CeilingLightPro = "W2612210/W2612220",// Currently only available in Japan.
IndoorCam = "W1301200",
PanTiltCam = "W1801200",
PanTiltCam2K = "W3101100",
BlindTilt = "W2701600",
BatteryCirculatorFan = "W3800510",
CirculatorFan = "W3800511",
WaterDetector = "W4402000",
RelaySwitch1 = "W5502300",
RelaySwitch1PM = "W5502310",
Unknown = "Unknown",
AirPurifier = "W5302300",
AirPurifierTable = "W5302310"
}
export declare enum SwitchBotBLEModel {
Bot = "H",
Curtain = "c",
Curtain3 = "{",
Humidifier = "e",
Humidifier2 = "#",
Meter = "T",
MeterPlus = "i",
MeterPro = "4",
MeterProCO2 = "5",
Hub2 = "v",
Hub3 = "V",
OutdoorMeter = "w",
MotionSensor = "s",
PresenceSensor = "p",
ContactSensor = "d",
ColorBulb = "u",
StripLight = "r",
PlugMiniUS = "g",
PlugMiniJP = "j",// Only available in Japan.
Lock = "o",
LockPro = "$",
CeilingLight = "q",// Currently only available in Japan.
CeilingLightPro = "n",// Currently only available in Japan.
BlindTilt = "x",
Leak = "&",
Keypad = "y",
RelaySwitch1 = ";",
RelaySwitch1PM = "<",
Remote = "b",
Unknown = "Unknown",
AirPurifier = "+",
AirPurifierTable = "7"
}
export declare enum SwitchBotBLEModelName {
Bot = "WoHand",
Hub2 = "WoHub2",
Hub3 = "WoHub3",
ColorBulb = "WoBulb",
Curtain = "WoCurtain",
Curtain3 = "WoCurtain3",
Humidifier = "WoHumi",
Humidifier2 = "WoHumi2",
Meter = "WoSensorTH",
MeterPlus = "WoSensorTHPlus",
MeterPro = "WoSensorTHP",
MeterProCO2 = "WoSensorTHPc",
Lock = "WoSmartLock",
LockPro = "WoSmartLockPro",
PresenceSensor = "WoPresence",
PlugMini = "WoPlugMini",
StripLight = "WoStrip",
OutdoorMeter = "WoIOSensorTH",
ContactSensor = "WoContact",
MotionSensor = "WoMotion",
BlindTilt = "WoBlindTilt",
CeilingLight = "WoCeilingLight",
CeilingLightPro = "WoCeilingLightPro",
Leak = "WoLeakDetector",
Keypad = "WoKeypad",
RelaySwitch1 = "WoRelaySwitch1Plus",
RelaySwitch1PM = "WoRelaySwitch1PM",
Remote = "WoRemote",
AirPurifier = "WoAirPurifier",
AirPurifierTable = "WoAirPurifierTable",
Unknown = "Unknown"
}
export declare enum SwitchBotBLEModelFriendlyName {
Bot = "Bot",
Hub2 = "Hub 2",
Hub3 = "Hub 3",
ColorBulb = "Color Bulb",
Curtain = "Curtain",
Curtain3 = "Curtain 3",
Humidifier = "Humidifier",
Humidifier2 = "Humidifier2",
Meter = "Meter",
Lock = "Lock",
LockPro = "Lock Pro",
PlugMini = "Plug Mini",
StripLight = "Strip Light",
MeterPlus = "Meter Plus",
MeterPro = "Meter Pro",
MeterProCO2 = "Meter Pro CO2",
BatteryCirculatorFan = "Battery Circulator Fan",
CirculatorFan = "Circulator Fan",
OutdoorMeter = "Outdoor Meter",
ContactSensor = "Contact Sensor",
MotionSensor = "Motion Sensor",
PresenceSensor = "Presence Sensor",
BlindTilt = "Blind Tilt",
CeilingLight = "Ceiling Light",
CeilingLightPro = "Ceiling Light Pro",
Leak = "Water Detector",
Keypad = "Keypad",
RelaySwitch1 = "Relay Switch 1",
RelaySwitch1PM = "Relay Switch 1PM",
Remote = "Remote",
AirPurifier = "Air Purifier",
AirPurifierTable = "Air Purifier Table",
Unknown = "Unknown",
AirPurifierVOC = "Air Purifier VOC",
AirPurifierTableVOC = "Air Purifier Table VOC",
AirPurifierPM2_5 = "Air Purifier PM2.5",
AirPurifierTablePM2_5 = "Air Purifier Table PM2.5"
}
export interface Params {
duration?: number;
model?: string;
id?: string;
quick?: boolean;
noble?: Noble;
}
export interface ErrorObject {
code: string;
message: string;
}
export interface Chars {
write: Characteristic | null;
notify: Characteristic | null;
device: Characteristic | null;
}
export interface NobleTypes {
noble: Noble;
peripheral: Peripheral;
}
export interface ServiceData {
model: string;
[key: string]: unknown;
}
export interface AdvertisementData {
serviceData: Buffer | null;
manufacturerData: Buffer | null;
}
export interface Rule {
required?: boolean;
min?: number;
max?: number;
minBytes?: number;
maxBytes?: number;
pattern?: RegExp;
enum?: unknown[];
type?: 'float' | 'integer' | 'boolean' | 'array' | 'object' | 'string';
}
/**
* Enum for log levels.
*/
export declare enum LogLevel {
SUCCESS = "success",
DEBUGSUCCESS = "debugsuccess",
WARN = "warn",
DEBUGWARN = "debugwarn",
ERROR = "error",
DEBUGERROR = "debugerror",
DEBUG = "debug",
INFO = "info"
}
/**
* Utility class for comprehensive input validation with improved error messages.
*/
export declare class ValidationUtils {
/**
* Validates percentage value (0-100).
* @param value - The value to validate
* @param paramName - The parameter name for error reporting
* @throws {RangeError} When value is not within valid range
* @throws {TypeError} When value is not a number
*/
static validatePercentage(value: number, paramName?: string): void;
/**
* Validates RGB color value (0-255).
* @param value - The color value to validate
* @param colorName - The color name for error reporting
* @throws {RangeError} When value is not within valid range
* @throws {TypeError} When value is not a number
*/
static validateRGB(value: number, colorName?: string): void;
/**
* Validates buffer and throws descriptive error.
* @param buffer - The buffer to validate
* @param expectedLength - Optional expected length
* @param paramName - The parameter name for error reporting
* @throws {TypeError} When buffer is not a Buffer
* @throws {RangeError} When buffer length doesn't match expected
*/
static validateBuffer(buffer: any, expectedLength?: number, paramName?: string): asserts buffer is Buffer;
/**
* Validates string input with comprehensive checks.
* @param value - The value to validate
* @param paramName - The parameter name for error reporting
* @param minLength - Minimum required length
* @param maxLength - Optional maximum length
* @throws {TypeError} When value is not a string
* @throws {RangeError} When string length is invalid
*/
static validateString(value: any, paramName?: string, minLength?: number, maxLength?: number): asserts value is string;
/**
* Validates numeric range with enhanced checks.
* @param value - The value to validate
* @param min - Minimum allowed value
* @param max - Maximum allowed value
* @param paramName - The parameter name for error reporting
* @param mustBeInteger - Whether the value must be an integer
* @throws {TypeError} When value is not a number
* @throws {RangeError} When value is outside valid range
*/
static validateRange(value: number, min: number, max: number, paramName?: string, mustBeInteger?: boolean): void;
/**
* Validates MAC address format.
* @param address - The MAC address to validate
* @param paramName - The parameter name for error reporting
* @throws {TypeError} When address is not a string
* @throws {Error} When address format is invalid
*/
static validateMacAddress(address: any, paramName?: string): asserts address is string;
/**
* Validates that a value is one of the allowed enum values.
* @param value - The value to validate
* @param allowedValues - Array of allowed values
* @param paramName - The parameter name for error reporting
* @throws {Error} When value is not in allowed values
*/
static validateEnum<T>(value: any, allowedValues: readonly T[], paramName?: string): asserts value is T;
}
/**
* Enhanced error handling utilities.
*/
export declare class ErrorUtils {
/**
* Creates a timeout error with context.
* @param operation - The operation that timed out
* @param timeoutMs - The timeout duration in milliseconds
* @returns A descriptive timeout error
*/
static createTimeoutError(operation: string, timeoutMs: number): Error;
/**
* Creates a connection error with context.
* @param deviceId - The device ID that failed to connect
* @param cause - The underlying cause of the connection failure
* @returns A descriptive connection error
*/
static createConnectionError(deviceId: string, cause?: Error): Error;
/**
* Creates a command error with context.
* @param command - The command that failed
* @param deviceId - The device ID
* @param cause - The underlying cause
* @returns A descriptive command error
*/
static createCommandError(command: string, deviceId: string, cause?: Error): Error;
/**
* Wraps an async operation with timeout and enhanced error handling.
* @param operation - The async operation to wrap
* @param timeoutMs - Timeout in milliseconds
* @param operationName - Name of the operation for error messages
* @returns Promise that resolves with the operation result or rejects with timeout
*/
static withTimeout<T>(operation: Promise<T>, timeoutMs: number, operationName: string): Promise<T>;
}
/**
* Represents a Switchbot Device.
*/
export declare class SwitchbotDevice extends EventEmitter {
private noble;
private peripheral;
private characteristics;
private deviceId;
private deviceAddress;
private deviceModel;
private deviceModelName;
private deviceFriendlyName;
private explicitlyConnected;
private isConnected;
private onNotify;
private onDisconnect;
private onConnect;
/**
* Initializes a new instance of the SwitchbotDevice class.
* @param peripheral The peripheral object from noble.
* @param noble The Noble object.
*/
constructor(peripheral: NobleTypes['peripheral'], noble: Noble);
/**
* Logs a message with the specified log level.
* @param level The severity level of the log (e.g., 'info', 'warn', 'error').
* @param message The log message to be emitted.
*/
log(level: string, message: string): Promise<void>;
get id(): string;
get address(): string;
get model(): SwitchBotBLEModel;
get modelName(): SwitchBotBLEModelName;
get friendlyName(): SwitchBotBLEModelFriendlyName;
get connectionState(): string;
get onConnectHandler(): () => Promise<void>;
set onConnectHandler(func: () => Promise<void>);
get onDisconnectHandler(): () => Promise<void>;
set onDisconnectHandler(func: () => Promise<void>);
/**
* Connects to the device.
* @returns A Promise that resolves when the connection is complete.
*/
connect(): Promise<void>;
/**
* Internal method to handle the connection process.
* @returns A Promise that resolves when the connection is complete.
*/
internalConnect(): Promise<void>;
/**
* Retrieves the device characteristics.
* @returns A Promise that resolves with the device characteristics.
*/
getCharacteristics(): Promise<Chars>;
/**
* Discovers the device services.
* @returns A Promise that resolves with the list of services.
*/
discoverServices(): Promise<NobleTypes['peripheral']['services']>;
/**
* Discovers the characteristics of a service.
* @param service The service to discover characteristics for.
* @returns A Promise that resolves with the list of characteristics.
*/
private discoverCharacteristics;
/**
* Subscribes to the notify characteristic.
* @returns A Promise that resolves when the subscription is complete.
*/
private subscribeToNotify;
/**
* Unsubscribes from the notify characteristic.
* @returns A Promise that resolves when the unsubscription is complete.
*/
unsubscribeFromNotify(): Promise<void>;
/**
* Disconnects from the device.
* @returns A Promise that resolves when the disconnection is complete.
*/
disconnect(): Promise<void>;
/**
* Internal method to handle disconnection if not explicitly initiated.
* @returns A Promise that resolves when the disconnection is complete.
*/
private internalDisconnect;
/**
* Retrieves the device name.
* @returns A Promise that resolves with the device name.
*/
getDeviceName(): Promise<string>;
/**
* Sets the device name.
* @param name The new device name.
* @returns A Promise that resolves when the name is set.
*/
setDeviceName(name: string): Promise<void>;
/**
* Sends a command to the device and awaits a response.
* @param reqBuf The command buffer.
* @returns A Promise that resolves with the response buffer.
*/
command(reqBuf: Buffer): Promise<Buffer>;
/**
* Waits for a response from the device after sending a command.
* @returns A Promise that resolves with the response buffer.
*/
private waitForCommandResponse;
/**
* Reads data from a characteristic with enhanced timeout and error handling.
* @param char The characteristic to read from.
* @returns A Promise that resolves with the data buffer.
*/
private readCharacteristic;
/**
* Writes data to a characteristic with enhanced timeout and error handling.
* @param char The characteristic to write to.
* @param buf The data buffer.
* @returns A Promise that resolves when the write is complete.
*/
private writeCharacteristic;
}
/**
* Represents the advertising data parser for SwitchBot devices.
*/
export declare class Advertising {
constructor();
/**
* Parses the advertisement data coming from SwitchBot device.
*
* This function processes advertising packets received from SwitchBot devices
* and extracts relevant information based on the device type.
*
* @param {NobleTypes['peripheral']} peripheral - The peripheral device object from noble.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<Ad | null>} - An object containing parsed data specific to the SwitchBot device type, or `null` if the device is not recognized.
*/
static parse(peripheral: NobleTypes['peripheral'], emitLog: (level: string, message: string) => void): Promise<ad | null>;
/**
* Validates if the buffer is a valid Buffer object with a minimum length.
*
* @param {any} buffer - The buffer to validate.
* @param {number} minLength - The minimum required length.
* @returns {boolean} - True if the buffer is valid, false otherwise.
*/
private static validateBuffer;
/**
* Parses the service data based on the device model.
*
* @param {string} model - The device model.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<any>} - The parsed service data.
*/
static parseServiceData(model: string, serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<any>;
/**
* Formats the address of the peripheral.
*
* @param {NobleTypes['peripheral']} peripheral - The peripheral device object from noble.
* @returns {string} - The formatted address.
*/
private static formatAddress;
}
/**
* Class representing a WoBlindTilt device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
*/
export declare class WoBlindTilt extends SwitchbotDevice {
private reverse;
/**
* Parses the service data and manufacturer data for the WoBlindTilt device.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @param {boolean} [reverse] - Whether to reverse the tilt percentage.
* @returns {Promise<blindTiltServiceData | null>} - The parsed data object or null if the data is invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void, reverse?: boolean): Promise<blindTiltServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Opens the blind tilt to the fully open position.
* @returns {Promise<void>}
*/
open(): Promise<void>;
/**
* Closes the blind tilt up to the nearest endpoint.
* @returns {Promise<void>}
*/
closeUp(): Promise<void>;
/**
* Closes the blind tilt down to the nearest endpoint.
* @returns {Promise<void>}
*/
closeDown(): Promise<void>;
/**
* Closes the blind tilt to the nearest endpoint.
* @returns {Promise<void>}
*/
close(): Promise<void>;
/**
* Retrieves the current position of the blind tilt.
* @returns {Promise<number>} - The current position of the blind tilt (0-100).
*/
getPosition(): Promise<number>;
/**
* Retrieves the advertised value for a given key.
* @param {string} key - The key for the advertised value.
* @returns {Promise<number>} - The advertised value.
* @private
*/
private _getAdvValue;
/**
* Retrieves the basic information of the blind tilt.
* @returns {Promise<object | null>} - A promise that resolves to an object containing the basic information of the blind tilt.
*/
getBasicInfo(): Promise<object | null>;
/**
* Pauses the blind tilt operation.
* @returns {Promise<void>}
*/
pause(): Promise<void>;
/**
* Runs the blind tilt to the specified position.
* @param {number} percent - The target position percentage (0-100).
* @param {number} mode - The running mode (0 or 1).
* @returns {Promise<void>}
*/
runToPos(percent: number, mode: number): Promise<void>;
/**
* Sends a command to operate the blind tilt and handles the response.
* @param {number[]} bytes - The byte array representing the command to be sent to the device.
* @returns {Promise<void>}
* @private
*/
operateBlindTilt(bytes: number[]): Promise<void>;
}
/**
* Class representing a WoBulb device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
*/
export declare class WoBulb extends SwitchbotDevice {
/**
* Parses the service data for WoBulb.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<colorBulbServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<colorBulbServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Reads the state of the bulb.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true) or OFF (false).
*/
readState(): Promise<boolean>;
/**
* Sets the state of the bulb.
* @param {number[]} reqByteArray - The request byte array.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
* @private
*/
setState(reqByteArray: number[]): Promise<boolean>;
/**
* Turns on the bulb.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is ON (true).
*/
turnOn(): Promise<boolean>;
/**
* Turns off the bulb.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the bulb is OFF (false).
*/
turnOff(): Promise<boolean>;
/**
* Sets the brightness of the bulb.
* @param {number} brightness - The brightness percentage (0-100).
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setBrightness(brightness: number): Promise<boolean>;
/**
* Sets the color temperature of the bulb.
* @param {number} color_temperature - The color temperature percentage (0-100).
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setColorTemperature(color_temperature: number): Promise<boolean>;
/**
* Sets the RGB color of the bulb.
* @param {number} brightness - The brightness percentage (0-100).
* @param {number} red - The red color value (0-255).
* @param {number} green - The green color value (0-255).
* @param {number} blue - The blue color value (0-255).
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setRGB(brightness: number, red: number, green: number, blue: number): Promise<boolean>;
/**
* Sends a command to the bulb.
* @param {number[]} bytes - The command bytes.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
* @private
*/
private operateBulb;
}
/**
* Class representing a WoCeilingLight device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
*/
export declare class WoCeilingLight extends SwitchbotDevice {
/**
* Parses the service data for WoCeilingLight.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<ceilingLightServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<ceilingLightServiceData | null>;
/**
* Parses the service data for WoCeilingLight Pro.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<ceilingLightProServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData_Pro(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<ceilingLightProServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Reads the state of the ceiling light.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the light is ON (true) or OFF (false).
*/
readState(): Promise<boolean>;
/**
* Sets the state of the ceiling light.
* @param {number[]} reqByteArray - The request byte array.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setState(reqByteArray: number[]): Promise<boolean>;
/**
* Turns on the ceiling light.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the light is ON (true).
*/
turnOn(): Promise<boolean>;
/**
* Turns off the ceiling light.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the light is OFF (false).
*/
turnOff(): Promise<boolean>;
/**
* Sets the brightness of the ceiling light.
* @param {number} brightness - The brightness percentage (0-100).
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setBrightness(brightness: number): Promise<boolean>;
/**
* Sets the color temperature of the ceiling light.
* @param {number} color_temperature - The color temperature percentage (0-100).
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setColorTemperature(color_temperature: number): Promise<boolean>;
/**
* Sets the RGB color of the ceiling light.
* @param {number} brightness - The brightness percentage (0-100).
* @param {number} red - The red color value (0-255).
* @param {number} green - The green color value (0-255).
* @param {number} blue - The blue color value (0-255).
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
setRGB(brightness: number, red: number, green: number, blue: number): Promise<boolean>;
/**
* Sends a command to the ceiling light.
* @param {number[]} bytes - The command bytes.
* @returns {Promise<boolean>} - Resolves with a boolean indicating whether the operation was successful.
*/
operateCeilingLight(bytes: number[]): Promise<boolean>;
}
/**
* Class representing a WoContact device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/contactsensor.md
*/
export declare class WoContact extends SwitchbotDevice {
/**
* Parses the service data for WoContact.
* @param {Buffer} serviceData - The service data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<contactSensorServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<contactSensorServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoCurtain device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain3.md
*/
export declare class WoCurtain extends SwitchbotDevice {
/**
* Parses the service data for WoCurtain.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @param {boolean} [reverse] - Whether to reverse the position.
* @returns {Promise<curtainServiceData | curtain3ServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void, reverse?: boolean): Promise<curtainServiceData | curtain3ServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Opens the curtain.
* @param {number} [mode] - Running mode (0x01 = QuietDrift, 0xFF = Default).
* @returns {Promise<void>}
*/
open(mode?: number): Promise<void>;
/**
* Closes the curtain.
* @param {number} [mode] - Running mode (0x01 = QuietDrift, 0xFF = Default).
* @returns {Promise<void>}
*/
close(mode?: number): Promise<void>;
/**
* Pauses the curtain.
* @returns {Promise<void>}
*/
pause(): Promise<void>;
/**
* Runs the curtain to the target position.
* @param {number} percent - The percentage of the target position.
* @param {number} [mode] - Running mode (0x01 = QuietDrift, 0xFF = Default).
* @returns {Promise<void>}
*/
runToPos(percent: number, mode?: number): Promise<void>;
/**
* Sends a command to the curtain.
* @param {number[]} bytes - The command bytes.
* @returns {Promise<void>}
*/
operateCurtain(bytes: number[]): Promise<void>;
}
/**
* Class representing a WoHand device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/bot.md
*/
export declare class WoHand extends SwitchbotDevice {
/**
* Parses the service data for WoHand.
* @param {Buffer} serviceData - The service data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<botServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<botServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Sends a command to the bot.
* @param {Buffer} reqBuf - The command buffer.
* @returns {Promise<void>}
*/
protected sendCommand(reqBuf: Buffer): Promise<void>;
/**
* Presses the bot.
* @returns {Promise<void>}
*/
press(): Promise<void>;
/**
* Turns on the bot.
* @returns {Promise<void>}
*/
turnOn(): Promise<void>;
/**
* Turns off the bot.
* @returns {Promise<void>}
*/
turnOff(): Promise<void>;
/**
* Moves the bot down.
* @returns {Promise<void>}
*/
down(): Promise<void>;
/**
* Moves the bot up.
* @returns {Promise<void>}
*/
up(): Promise<void>;
}
/**
* Class representing a WoHub2 device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
*/
export declare class WoHub2 extends SwitchbotDevice {
/**
* Parses the service data for WoHub2.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<hub2ServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<hub2ServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoHub3 device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
*/
export declare class WoHub3 extends SwitchbotDevice {
/**
* Parses the service data for WoHub3.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<hub3ServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<hub3ServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoHumi device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
*/
export declare class WoHumi extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Parses the service data for WoHumi.
* @param {Buffer} serviceData - The service data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<humidifierServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<humidifierServiceData | null>;
/**
* Sends a command to the humidifier.
* @param {Buffer} reqBuf - The command buffer.
* @returns {Promise<void>}
*/
protected operateHumi(reqBuf: Buffer): Promise<void>;
/**
* Turns on the humidifier.
* @returns {Promise<void>}
*/
turnOn(): Promise<void>;
/**
* Turns off the humidifier.
* @returns {Promise<void>}
*/
turnOff(): Promise<void>;
/**
* Increases the humidifier setting.
* @returns {Promise<void>}
*/
increase(): Promise<void>;
/**
* Decreases the humidifier setting.
* @returns {Promise<void>}
*/
decrease(): Promise<void>;
/**
* Sets the humidifier to auto mode.
* @returns {Promise<void>}
*/
setAutoMode(): Promise<void>;
/**
* Sets the humidifier to manual mode.
* @returns {Promise<void>}
*/
setManualMode(): Promise<void>;
/**
* Sets the humidifier level.
* @param {number} level - The level to set (0-100).
* @returns {Promise<void>}
*/
percentage(level: number): Promise<void>;
}
/**
* Class representing a WoHumi device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/tree/latest/devicetypes
*/
export declare class WoHumi2 extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Parses the service data for WoHumi.
* @param {Buffer} serviceData - The service data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<humidifier2ServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<humidifier2ServiceData | null>;
/**
* Sends a command to the humidifier.
* @param {Buffer} reqBuf - The command buffer.
* @returns {Promise<void>}
*/
protected operateHumi(reqBuf: Buffer): Promise<void>;
/**
* Turns on the humidifier.
* @returns {Promise<void>}
*/
turnOn(): Promise<void>;
/**
* Turns off the humidifier.
* @returns {Promise<void>}
*/
turnOff(): Promise<void>;
/**
* Increases the humidifier setting.
* @returns {Promise<void>}
*/
increase(): Promise<void>;
/**
* Decreases the humidifier setting.
* @returns {Promise<void>}
*/
decrease(): Promise<void>;
/**
* Sets the humidifier to auto mode.
* @returns {Promise<void>}
*/
setAutoMode(): Promise<void>;
/**
* Sets the humidifier to manual mode.
* @returns {Promise<void>}
*/
setManualMode(): Promise<void>;
/**
* Sets the humidifier level.
* @param {number} level - The level to set (0-100).
* @returns {Promise<void>}
*/
percentage(level: number): Promise<void>;
}
/**
* Class representing a WoIOSensorTH device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#outdoor-temperaturehumidity-sensor
*/
export declare class WoIOSensorTH extends SwitchbotDevice {
/**
* Parses the service data for WoIOSensorTH.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<outdoorMeterServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<outdoorMeterServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoKeypad device.
*/
export declare class WoKeypad extends SwitchbotDevice {
/**
* Parses the service data for WoKeypad.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<keypadDetectorServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<keypadDetectorServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoLeak device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md#outdoor-temperaturehumidity-sensor
*/
export declare class WoLeak extends SwitchbotDevice {
/**
* Parses the service data for WoLeak.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<waterLeakDetectorServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<waterLeakDetectorServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoPlugMini device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/plugmini.md
*/
export declare class WoPlugMiniJP extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Parses the service data for WoPlugMini JP.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<plugMiniJPServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<plugMiniJPServiceData | null>;
/**
* Reads the state of the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
readState(): Promise<boolean>;
/**
* Sets the state of the plug.
* @private
* @param {number[]} reqByteArray - The request byte array.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
setState(reqByteArray: number[]): Promise<boolean>;
/**
* Turns on the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
turnOn(): Promise<boolean>;
/**
* Turns off the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
turnOff(): Promise<boolean>;
/**
* Toggles the state of the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
toggle(): Promise<boolean>;
/**
* Operates the plug with the given bytes.
* @param {number[]} bytes - The byte array to send to the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
operatePlug(bytes: number[]): Promise<boolean>;
}
/**
* Class representing a WoPlugMini device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/plugmini.md
*/
export declare class WoPlugMiniUS extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Parses the service data for WoPlugMini US.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<plugMiniUSServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<plugMiniUSServiceData | null>;
/**
* Reads the state of the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
readState(): Promise<boolean>;
/**
* Sets the state of the plug.
* @private
* @param {number[]} reqByteArray - The request byte array.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
private setState;
/**
* Turns on the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
turnOn(): Promise<boolean>;
/**
* Turns off the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
turnOff(): Promise<boolean>;
/**
* Toggles the state of the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
toggle(): Promise<boolean>;
/**
* Operates the plug with the given bytes.
* @param {number[]} bytes - The byte array to send to the plug.
* @returns {Promise<boolean>} - Resolves with a boolean that tells whether the plug is ON (true) or OFF (false).
*/
operatePlug(bytes: number[]): Promise<boolean>;
}
/**
* Class representing a WoPresence device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
*/
export declare class WoPresence extends SwitchbotDevice {
/**
* Parses the service data for WoPresence.
* @param {Buffer} serviceData - The service data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<motionSensorServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<motionSensorServiceData | null>;
/**
* Parses the manufacturer data for presence sensors.
* @param {Buffer | null} serviceData - The optional service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<presenceSensorServiceData | null>} - Parsed service data or null if invalid.
*/
static parsePresenceSensorServiceData(serviceData: Buffer | null, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<presenceSensorServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoRelaySwitch1 device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/
*/
export declare class WoRelaySwitch1 extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Parses the service data for WoRelaySwitch1.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<relaySwitch1ServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<relaySwitch1ServiceData | null>;
/**
* Sends a command to the bot.
* @param {Buffer} reqBuf - The command buffer.
* @returns {Promise<void>}
*/
protected sendCommand(reqBuf: Buffer): Promise<void>;
/**
* Turns on the bot.
* @returns {Promise<void>}
*/
turnOn(): Promise<void>;
/**
* Turns off the bot.
* @returns {Promise<void>}
*/
turnOff(): Promise<void>;
}
/**
* Class representing a WoRelaySwitch1PM device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/
*/
export declare class WoRelaySwitch1PM extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
/**
* Parses the service data for WoRelaySwitch1PM.
* @param {Buffer} serviceData - The service data buffer.
* @param {Buffer} manufacturerData - The manufacturer data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<relaySwitch1PMServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<relaySwitch1PMServiceData | null>;
/**
* Sends a command to the bot.
* @param {Buffer} reqBuf - The command buffer.
* @returns {Promise<void>}
*/
protected sendCommand(reqBuf: Buffer): Promise<void>;
/**
* Turns on the bot.
* @returns {Promise<void>}
*/
turnOn(): Promise<void>;
/**
* Turns off the bot.
* @returns {Promise<void>}
*/
turnOff(): Promise<void>;
}
/**
* Class representing a WoRemote device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/
*/
export declare class WoRemote extends SwitchbotDevice {
/**
* Parses the service data for WoRemote.
* @param {Buffer} serviceData - The service data buffer.
* @param {Function} emitLog - The function to emit log messages.
* @returns {Promise<remoteServiceData | null>} - Parsed service data or null if invalid.
*/
static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<remoteServiceData | null>;
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
}
/**
* Class representing a WoSensorTH device.
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md
*/
export declare class WoSensorTH extends SwitchbotDevice {
constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']);
static parseServiceData(service