UNPKG

node-switchbot

Version:

The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).

1,235 lines 53.4 kB
import type * as Noble from '@stoprocent/noble'; import type { batteryCirculatorFanServiceData, blindTiltServiceData, botServiceData, ceilingLightProServiceData, ceilingLightServiceData, colorBulbServiceData, contactSensorServiceData, curtain3ServiceData, curtainServiceData, hub2ServiceData, humidifier2ServiceData, humidifierServiceData, keypadDetectorServiceData, lockProServiceData, lockServiceData, meterPlusServiceData, meterProCO2ServiceData, meterProServiceData, meterServiceData, motionSensorServiceData, outdoorMeterServiceData, plugMiniJPServiceData, plugMiniUSServiceData, relaySwitch1PMServiceData, relaySwitch1ServiceData, remoteServiceData, robotVacuumCleanerServiceData, stripLightServiceData, waterLeakDetectorServiceData } from './types/bledevicestatus.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: botServiceData | colorBulbServiceData | contactSensorServiceData | curtainServiceData | curtain3ServiceData | stripLightServiceData | lockServiceData | lockProServiceData | meterServiceData | meterPlusServiceData | meterProServiceData | meterProCO2ServiceData | motionSensorServiceData | outdoorMeterServiceData | plugMiniUSServiceData | plugMiniJPServiceData | blindTiltServiceData | ceilingLightServiceData | ceilingLightProServiceData | hub2ServiceData | 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; OutdoorMeter: DeviceInfo; MotionSensor: DeviceInfo; ContactSensor: DeviceInfo; ColorBulb: DeviceInfo; StripLight: DeviceInfo; PlugMiniUS: DeviceInfo; PlugMiniJP: DeviceInfo; Lock: DeviceInfo; LockPro: DeviceInfo; CeilingLight: DeviceInfo; CeilingLightPro: DeviceInfo; BlindTilt: DeviceInfo; Unknown: DeviceInfo; } export declare enum SwitchBotModel { HubMini = "W0202200", HubPlus = "SwitchBot Hub S1", Hub2 = "W3202100", 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", 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" } export declare enum SwitchBotBLEModel { Bot = "H", Curtain = "c", Curtain3 = "{", Humidifier = "e", Humidifier2 = "#", Meter = "T", MeterPlus = "i", MeterPro = "4", MeterProCO2 = "5", Hub2 = "v", OutdoorMeter = "w", MotionSensor = "s", 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" } export declare enum SwitchBotBLEModelName { Bot = "WoHand", Hub2 = "WoHub2", ColorBulb = "WoBulb", Curtain = "WoCurtain", Curtain3 = "WoCurtain3", Humidifier = "WoHumi", Humidifier2 = "WoHumi2", Meter = "WoSensorTH", MeterPlus = "WoSensorTHPlus", MeterPro = "WoSensorTHP", MeterProCO2 = "WoSensorTHPc", Lock = "WoSmartLock", LockPro = "WoSmartLockPro", 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", Unknown = "Unknown" } export declare enum SwitchBotBLEModelFriendlyName { Bot = "Bot", Hub2 = "Hub 2", 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", 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", Unknown = "Unknown" } export interface Params { duration?: number; model?: string; id?: string; quick?: boolean; noble?: typeof Noble; } export interface ErrorObject { code: string; message: string; } export interface Chars { write: Noble.Characteristic | null; notify: Noble.Characteristic | null; device: Noble.Characteristic | null; } export interface NobleTypes { noble: typeof Noble; state: 'unknown' | 'resetting' | 'unsupported' | 'unauthorized' | 'poweredOff' | 'poweredOn'; peripheral: Noble.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" } /** * 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: NobleTypes['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<Noble.Service[]>; /** * 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 a timeout. * @param char The characteristic to read from. * @returns A Promise that resolves with the data buffer. */ private readCharacteristic; /** * Writes data to a characteristic with a timeout. * @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. * @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 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>; 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(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<meterServiceData | null>; } /** * Class representing a WoSensorTH device. * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md */ export declare class WoSensorTHPlus extends SwitchbotDevice { constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']); static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<meterPlusServiceData | null>; } /** * Class representing a WoSensorTH device. * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md */ export declare class WoSensorTHPro extends SwitchbotDevice { constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']); static parseServiceData(serviceData: Buffer, emitLog: (level: string, message: string) => void): Promise<meterProServiceData | null>; } /** * Class representing a WoSensorTH device. * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md */ export declare class WoSensorTHProCO2 extends SwitchbotDevice { constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']); static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<meterProCO2ServiceData | null>; } /** * Class representing a WoSmartLock device. * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md */ export declare class WoSmartLock extends SwitchbotDevice { iv: Buffer | null; key_id: string; encryption_key: Buffer | null; static Result: { ERROR: number; SUCCESS: number; SUCCESS_LOW_BATTERY: number; }; static validateResponse(res: Buffer): Promise<number>; static getLockStatus(code: number): string; /** * Parses the service data from the SwitchBot Strip Light. * @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<lockServiceData | null>} - Parsed service data or null if invalid. */ static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<lockServiceData | null>; constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']); /** * Initializes the encryption key info for valid lock communication. * @param {string} keyId - The key ID. * @param {string} encryptionKey - The encryption key. */ setKey(keyId: string, encryptionKey: string): Promise<void>; /** * Unlocks the Smart Lock. * @returns {Promise<number>} - The result of the unlock operation. */ unlock(): Promise<number>; /** * Unlocks the Smart Lock without unlatching the door. * @returns {Promise<number>} - The result of the unlock operation. */ unlockNoUnlatch(): Promise<number>; /** * Locks the Smart Lock. * @returns {Promise<number>} - The result of the lock operation. */ lock(): Promise<number>; /** * Gets general state info from the Smart Lock. * @returns {Promise<object | null>} - The state object or null if an error occurred. */ info(): Promise<object | null>; /** * Encrypts a string using AES-128-CTR. * @param {string} str - The string to encrypt. * @returns {Promise<string>} - The encrypted string in hex format. */ encrypt(str: string): Promise<string>; /** * Decrypts a buffer using AES-128-CTR. * @param {Buffer} data - The data to decrypt. * @returns {Promise<Buffer>} - The decrypted data. */ decrypt(data: Buffer): Promise<Buffer>; /** * Retrieves the IV from the device. * @returns {Promise<Buffer>} - The IV buffer. */ getIv(): Promise<Buffer>; /** * Sends an encrypted command to the device. * @param {string} key - The command key. * @returns {Promise<Buffer>} - The response buffer. */ encryptedCommand(key: string): Promise<Buffer>; /** * Operates the lock with the given command. * @param {string} key - The command key. * @param {boolean} [encrypt] - Whether to encrypt the command. * @returns {Promise<Buffer>} - The response buffer. */ operateLock(key: string, encrypt?: boolean): Promise<Buffer>; } /** * Class representing a WoSmartLockPro device. * @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md */ export declare class WoSmartLockPro extends SwitchbotDevice { iv: Buffer | null; key_id: string; encryption_key: Buffer | null; static Result: { ERROR: number; SUCCESS: number; SUCCESS_LOW_BATTERY: number; }; static validateResponse(res: Buffer): Promise<number>; static getLockStatus(code: number): string; /** * Parses the service data from the SwitchBot Strip Light. * @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<lockProServiceData | null>} - Parsed service data or null if invalid. */ static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, emitLog: (level: string, message: string) => void): Promise<lockProServiceData | null>; constructor(peripheral: NobleTypes['peripheral'], noble: NobleTypes['noble']); /** * Initializes the encryption key info for valid lock communication. * @param {string} keyId - The key ID. * @param {string} encryptionKey - The encryption key. */ setKey(keyId: string, encryptionKey: string): Promise<void>; /** * Unlocks the Smart Lock. * @returns {Promise<number>} - The result of the unlock operation. */ unlock(): Promise<number>; /** * Unlocks the Smart Lock without unlatching the door. * @returns {Promise<number>} - The result of the unlock operation. */ unlockNoUnlatch(): Promise<number>; /** * Locks the Smart Lock. * @returns {Promise<number>} - The result of the lock operation. */ lock(): Promise<number>; /** * Gets general state info from the Smart Lock. * @returns {Promise<object | null>} - The state object or null if an error occurred. */ info(): Promise<object | null>; /** * Encrypts a string using AES-128-CTR. * @param {string} str - The string to encrypt. * @returns {Promise<string>} - The encrypted string in hex format. */ encrypt(str: string): Promise<string>; /** * Decrypts a buffer using AES-128-CTR. * @param {Buffer} data - The data to decrypt