node-switchbot 3.6.6 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/npm-version-script-esm.js +97 -0
- package/CHANGELOG.md +322 -0
- package/PRODUCTION_READY.md +135 -0
- package/README.md +92 -0
- package/dist/api.d.ts +130 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +286 -0
- package/dist/api.js.map +1 -0
- package/dist/ble.d.ts +116 -0
- package/dist/ble.d.ts.map +1 -0
- package/dist/ble.js +430 -0
- package/dist/ble.js.map +1 -0
- package/dist/devices/base.d.ts +146 -0
- package/dist/devices/base.d.ts.map +1 -0
- package/dist/devices/base.js +324 -0
- package/dist/devices/base.js.map +1 -0
- package/dist/devices/index.d.ts +30 -0
- package/dist/devices/index.d.ts.map +1 -0
- package/dist/devices/index.js +34 -0
- package/dist/devices/index.js.map +1 -0
- package/dist/devices/wo-air-purifier-table.d.ts +8 -0
- package/dist/devices/wo-air-purifier-table.d.ts.map +1 -0
- package/dist/devices/wo-air-purifier-table.js +12 -0
- package/dist/devices/wo-air-purifier-table.js.map +1 -0
- package/dist/devices/wo-air-purifier.d.ts +28 -0
- package/dist/devices/wo-air-purifier.d.ts.map +1 -0
- package/dist/devices/wo-air-purifier.js +105 -0
- package/dist/devices/wo-air-purifier.js.map +1 -0
- package/dist/devices/wo-blind-tilt.d.ts +36 -0
- package/dist/devices/wo-blind-tilt.d.ts.map +1 -0
- package/dist/devices/wo-blind-tilt.js +95 -0
- package/dist/devices/wo-blind-tilt.js.map +1 -0
- package/dist/devices/wo-bulb.d.ts +32 -0
- package/dist/devices/wo-bulb.d.ts.map +1 -0
- package/dist/devices/wo-bulb.js +109 -0
- package/dist/devices/wo-bulb.js.map +1 -0
- package/dist/devices/wo-ceiling-light.d.ts +8 -0
- package/dist/devices/wo-ceiling-light.d.ts.map +1 -0
- package/dist/devices/wo-ceiling-light.js +12 -0
- package/dist/devices/wo-ceiling-light.js.map +1 -0
- package/dist/devices/wo-contact.d.ts +12 -0
- package/dist/devices/wo-contact.d.ts.map +1 -0
- package/dist/devices/wo-contact.js +50 -0
- package/dist/devices/wo-contact.js.map +1 -0
- package/dist/devices/wo-curtain.d.ts +28 -0
- package/dist/devices/wo-curtain.d.ts.map +1 -0
- package/dist/devices/wo-curtain.js +82 -0
- package/dist/devices/wo-curtain.js.map +1 -0
- package/dist/devices/wo-hand.d.ts +24 -0
- package/dist/devices/wo-hand.d.ts.map +1 -0
- package/dist/devices/wo-hand.js +70 -0
- package/dist/devices/wo-hand.js.map +1 -0
- package/dist/devices/wo-hub2.d.ts +12 -0
- package/dist/devices/wo-hub2.d.ts.map +1 -0
- package/dist/devices/wo-hub2.js +48 -0
- package/dist/devices/wo-hub2.js.map +1 -0
- package/dist/devices/wo-hub3.d.ts +8 -0
- package/dist/devices/wo-hub3.d.ts.map +1 -0
- package/dist/devices/wo-hub3.js +12 -0
- package/dist/devices/wo-hub3.js.map +1 -0
- package/dist/devices/wo-humi.d.ts +28 -0
- package/dist/devices/wo-humi.d.ts.map +1 -0
- package/dist/devices/wo-humi.js +91 -0
- package/dist/devices/wo-humi.js.map +1 -0
- package/dist/devices/wo-humi2.d.ts +8 -0
- package/dist/devices/wo-humi2.d.ts.map +1 -0
- package/dist/devices/wo-humi2.js +12 -0
- package/dist/devices/wo-humi2.js.map +1 -0
- package/dist/devices/wo-io-sensor-th.d.ts +8 -0
- package/dist/devices/wo-io-sensor-th.d.ts.map +1 -0
- package/dist/devices/wo-io-sensor-th.js +12 -0
- package/dist/devices/wo-io-sensor-th.js.map +1 -0
- package/dist/devices/wo-keypad.d.ts +13 -0
- package/dist/devices/wo-keypad.d.ts.map +1 -0
- package/dist/devices/wo-keypad.js +46 -0
- package/dist/devices/wo-keypad.js.map +1 -0
- package/dist/devices/wo-leak.d.ts +12 -0
- package/dist/devices/wo-leak.d.ts.map +1 -0
- package/dist/devices/wo-leak.js +46 -0
- package/dist/devices/wo-leak.js.map +1 -0
- package/dist/devices/wo-lock-pro.d.ts +24 -0
- package/dist/devices/wo-lock-pro.d.ts.map +1 -0
- package/dist/devices/wo-lock-pro.js +72 -0
- package/dist/devices/wo-lock-pro.js.map +1 -0
- package/dist/devices/wo-lock.d.ts +20 -0
- package/dist/devices/wo-lock.d.ts.map +1 -0
- package/dist/devices/wo-lock.js +64 -0
- package/dist/devices/wo-lock.js.map +1 -0
- package/dist/devices/wo-plug-mini-jp.d.ts +8 -0
- package/dist/devices/wo-plug-mini-jp.d.ts.map +1 -0
- package/dist/devices/wo-plug-mini-jp.js +12 -0
- package/dist/devices/wo-plug-mini-jp.js.map +1 -0
- package/dist/devices/wo-plug-mini-us.d.ts +24 -0
- package/dist/devices/wo-plug-mini-us.d.ts.map +1 -0
- package/dist/devices/wo-plug-mini-us.js +70 -0
- package/dist/devices/wo-plug-mini-us.js.map +1 -0
- package/dist/devices/wo-presence.d.ts +12 -0
- package/dist/devices/wo-presence.d.ts.map +1 -0
- package/dist/devices/wo-presence.js +48 -0
- package/dist/devices/wo-presence.js.map +1 -0
- package/dist/devices/wo-relay-switch-1.d.ts +24 -0
- package/dist/devices/wo-relay-switch-1.d.ts.map +1 -0
- package/dist/devices/wo-relay-switch-1.js +70 -0
- package/dist/devices/wo-relay-switch-1.js.map +1 -0
- package/dist/devices/wo-relay-switch-1pm.d.ts +8 -0
- package/dist/devices/wo-relay-switch-1pm.d.ts.map +1 -0
- package/dist/devices/wo-relay-switch-1pm.js +12 -0
- package/dist/devices/wo-relay-switch-1pm.js.map +1 -0
- package/dist/devices/wo-remote.d.ts +13 -0
- package/dist/devices/wo-remote.d.ts.map +1 -0
- package/dist/devices/wo-remote.js +45 -0
- package/dist/devices/wo-remote.js.map +1 -0
- package/dist/devices/wo-sensor-th-plus.d.ts +8 -0
- package/dist/devices/wo-sensor-th-plus.d.ts.map +1 -0
- package/dist/devices/wo-sensor-th-plus.js +12 -0
- package/dist/devices/wo-sensor-th-plus.js.map +1 -0
- package/dist/devices/wo-sensor-th-pro-co2.d.ts +8 -0
- package/dist/devices/wo-sensor-th-pro-co2.d.ts.map +1 -0
- package/dist/devices/wo-sensor-th-pro-co2.js +12 -0
- package/dist/devices/wo-sensor-th-pro-co2.js.map +1 -0
- package/dist/devices/wo-sensor-th-pro.d.ts +8 -0
- package/dist/devices/wo-sensor-th-pro.d.ts.map +1 -0
- package/dist/devices/wo-sensor-th-pro.js +12 -0
- package/dist/devices/wo-sensor-th-pro.js.map +1 -0
- package/dist/devices/wo-sensor-th.d.ts +12 -0
- package/dist/devices/wo-sensor-th.d.ts.map +1 -0
- package/dist/devices/wo-sensor-th.js +49 -0
- package/dist/devices/wo-sensor-th.js.map +1 -0
- package/dist/devices/wo-strip.d.ts +8 -0
- package/dist/devices/wo-strip.d.ts.map +1 -0
- package/dist/devices/wo-strip.js +12 -0
- package/dist/devices/wo-strip.js.map +1 -0
- package/dist/errors.d.ts +63 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +103 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/dist/settings.d.ts +126 -47
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +214 -64
- package/dist/settings.js.map +1 -1
- package/dist/switchbot.d.ts +87 -0
- package/dist/switchbot.d.ts.map +1 -0
- package/dist/switchbot.js +422 -0
- package/dist/switchbot.js.map +1 -0
- package/dist/types/api.d.ts +187 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +6 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/ble.d.ts +246 -348
- package/dist/types/ble.d.ts.map +1 -1
- package/dist/types/ble.js +94 -1
- package/dist/types/ble.js.map +1 -1
- package/dist/types/device.d.ts +209 -0
- package/dist/types/device.d.ts.map +1 -0
- package/dist/types/device.js +6 -0
- package/dist/types/device.js.map +1 -0
- package/dist/types/index.d.ts +115 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +97 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +206 -0
- package/dist/utils/index.js.map +1 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/highlight.css +20 -6
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +2 -2
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +3 -3
- package/docs/classes/APIError.html +6 -0
- package/docs/classes/APINotAvailableError.html +4 -0
- package/docs/classes/BLEConnection.html +17 -0
- package/docs/classes/BLENotAvailableError.html +4 -0
- package/docs/classes/BLEScanner.html +15 -0
- package/docs/classes/CommandFailedError.html +6 -0
- package/docs/classes/ConnectionTimeoutError.html +5 -0
- package/docs/classes/DeviceManager.html +25 -0
- package/docs/classes/DeviceNotFoundError.html +4 -0
- package/docs/classes/DiscoveryError.html +5 -0
- package/docs/classes/OpenAPIClient.html +66 -0
- package/docs/classes/SwitchBot.html +22 -0
- package/docs/classes/SwitchBotDevice.html +28 -0
- package/docs/classes/SwitchBotError.html +4 -0
- package/docs/classes/ValidationError.html +5 -0
- package/docs/classes/WoAirPurifier.html +32 -80
- package/docs/classes/WoAirPurifierTable.html +36 -83
- package/docs/classes/WoBlindTilt.html +34 -73
- package/docs/classes/WoBulb.html +33 -85
- package/docs/classes/WoCeilingLight.html +38 -107
- package/docs/classes/WoContact.html +27 -52
- package/docs/classes/WoCurtain.html +32 -69
- package/docs/classes/WoHand.html +30 -59
- package/docs/classes/WoHub2.html +27 -52
- package/docs/classes/WoHub3.html +28 -52
- package/docs/classes/WoHumi.html +33 -65
- package/docs/classes/WoHumi2.html +36 -67
- package/docs/classes/WoIOSensorTH.html +28 -53
- package/docs/classes/WoKeypad.html +28 -52
- package/docs/classes/WoLeak.html +27 -53
- package/docs/classes/WoPlugMiniJP.html +34 -78
- package/docs/classes/WoPlugMiniUS.html +30 -75
- package/docs/classes/WoPresence.html +27 -60
- package/docs/classes/WoRelaySwitch1.html +31 -55
- package/docs/classes/WoRelaySwitch1PM.html +34 -57
- package/docs/classes/WoRemote.html +28 -52
- package/docs/classes/WoSensorTH.html +27 -46
- package/docs/classes/WoSensorTHPlus.html +28 -46
- package/docs/classes/WoSensorTHPro.html +28 -46
- package/docs/classes/WoSensorTHProCO2.html +28 -46
- package/docs/classes/WoSmartLock.html +29 -111
- package/docs/classes/WoSmartLockPro.html +31 -111
- package/docs/classes/WoStrip.html +38 -94
- package/docs/enums/LogLevel.html +4 -7
- package/docs/enums/SwitchBotBLEModel.html +11 -6
- package/docs/enums/SwitchBotBLEModelName.html +13 -6
- package/docs/functions/updateBaseURL.html +3 -3
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +40 -6
- package/docs/interfaces/APICommandRequest.html +5 -0
- package/docs/interfaces/APICommandResponse.html +5 -0
- package/docs/interfaces/APIDevice.html +18 -0
- package/docs/interfaces/APIDeviceStatus.html +36 -0
- package/docs/interfaces/APIErrorResponse.html +5 -0
- package/docs/interfaces/APIResponse.html +5 -0
- package/docs/interfaces/AirPurifierCommands.html +5 -0
- package/docs/interfaces/AirPurifierServiceData.html +14 -0
- package/docs/interfaces/AirPurifierStatus.html +17 -0
- package/docs/interfaces/BLEAdvertisement.html +6 -0
- package/docs/interfaces/BLEScanOptions.html +10 -0
- package/docs/interfaces/BLEServiceData.html +10 -0
- package/docs/interfaces/BlindTiltCommands.html +7 -0
- package/docs/interfaces/BlindTiltServiceData.html +14 -0
- package/docs/interfaces/BlindTiltStatus.html +15 -0
- package/docs/interfaces/BotCommands.html +4 -0
- package/docs/interfaces/BotServiceData.html +12 -0
- package/docs/interfaces/BotStatus.html +14 -0
- package/docs/interfaces/BulbCommands.html +6 -0
- package/docs/interfaces/BulbServiceData.html +19 -0
- package/docs/interfaces/BulbStatus.html +16 -0
- package/docs/interfaces/CeilingLightCommands.html +6 -0
- package/docs/interfaces/CeilingLightServiceData.html +19 -0
- package/docs/interfaces/CeilingLightStatus.html +16 -0
- package/docs/interfaces/CommandResult.html +12 -0
- package/docs/interfaces/ContactServiceData.html +13 -0
- package/docs/interfaces/ContactStatus.html +15 -0
- package/docs/interfaces/CurtainCommands.html +5 -0
- package/docs/interfaces/CurtainServiceData.html +14 -0
- package/docs/interfaces/CurtainStatus.html +17 -0
- package/docs/interfaces/DeviceInfo.html +26 -0
- package/docs/interfaces/DeviceListResponse.html +4 -0
- package/docs/interfaces/DeviceStatus.html +12 -0
- package/docs/interfaces/DiscoveryOptions.html +14 -0
- package/docs/interfaces/HubServiceData.html +14 -0
- package/docs/interfaces/HubStatus.html +15 -0
- package/docs/interfaces/HumidifierCommands.html +5 -0
- package/docs/interfaces/HumidifierServiceData.html +14 -0
- package/docs/interfaces/HumidifierStatus.html +18 -0
- package/docs/interfaces/KeypadStatus.html +13 -0
- package/docs/interfaces/LeakServiceData.html +11 -0
- package/docs/interfaces/LeakStatus.html +13 -0
- package/docs/interfaces/LockCommands.html +3 -0
- package/docs/interfaces/LockServiceData.html +15 -0
- package/docs/interfaces/LockStatus.html +15 -0
- package/docs/interfaces/MeterServiceData.html +13 -0
- package/docs/interfaces/MeterStatus.html +15 -0
- package/docs/interfaces/MotionServiceData.html +13 -0
- package/docs/interfaces/MotionStatus.html +14 -0
- package/docs/interfaces/PlugCommands.html +4 -0
- package/docs/interfaces/PlugServiceData.html +17 -0
- package/docs/interfaces/PlugStatus.html +16 -0
- package/docs/interfaces/PresenceServiceData.html +12 -0
- package/docs/interfaces/PresenceStatus.html +14 -0
- package/docs/interfaces/RelaySwitchCommands.html +4 -0
- package/docs/interfaces/RelaySwitchServiceData.html +14 -0
- package/docs/interfaces/RelaySwitchStatus.html +16 -0
- package/docs/interfaces/RemoteStatus.html +12 -0
- package/docs/interfaces/SceneListResponse.html +3 -0
- package/docs/interfaces/StripCommands.html +6 -0
- package/docs/interfaces/StripServiceData.html +19 -0
- package/docs/interfaces/StripStatus.html +16 -0
- package/docs/interfaces/SwitchBotConfig.html +18 -0
- package/docs/interfaces/WebhookConfig.html +4 -0
- package/docs/interfaces/WebhookDetails.html +7 -0
- package/docs/interfaces/WebhookQueryResponse.html +5 -0
- package/docs/interfaces/WebhookSetupResponse.html +5 -0
- package/docs/modules.html +1 -1
- package/docs/types/ConnectionType.html +2 -0
- package/docs/types/PhysicalDeviceType.html +2 -0
- package/docs/types/VirtualDeviceType.html +2 -0
- package/docs/variables/urls.html +1 -1
- package/package.json +12 -21
- package/.github/scripts/npm-version-script-esm-auto.js +0 -207
- package/dist/device.d.ts +0 -1626
- package/dist/device.d.ts.map +0 -1
- package/dist/device.js +0 -3602
- package/dist/device.js.map +0 -1
- package/dist/device.test.d.ts +0 -2
- package/dist/device.test.d.ts.map +0 -1
- package/dist/device.test.js +0 -336
- package/dist/device.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -14
- package/dist/index.test.js.map +0 -1
- package/dist/parameter-checker.d.ts +0 -91
- package/dist/parameter-checker.d.ts.map +0 -1
- package/dist/parameter-checker.js +0 -262
- package/dist/parameter-checker.js.map +0 -1
- package/dist/parameter-checker.test.d.ts +0 -2
- package/dist/parameter-checker.test.d.ts.map +0 -1
- package/dist/parameter-checker.test.js +0 -56
- package/dist/parameter-checker.test.js.map +0 -1
- package/dist/settings.test.d.ts +0 -2
- package/dist/settings.test.d.ts.map +0 -1
- package/dist/settings.test.js +0 -61
- package/dist/settings.test.js.map +0 -1
- package/dist/switchbot-ble.d.ts +0 -89
- package/dist/switchbot-ble.d.ts.map +0 -1
- package/dist/switchbot-ble.js +0 -320
- package/dist/switchbot-ble.js.map +0 -1
- package/dist/switchbot-ble.test.d.ts +0 -2
- package/dist/switchbot-ble.test.d.ts.map +0 -1
- package/dist/switchbot-ble.test.js +0 -32
- package/dist/switchbot-ble.test.js.map +0 -1
- package/dist/switchbot-openapi.d.ts +0 -139
- package/dist/switchbot-openapi.d.ts.map +0 -1
- package/dist/switchbot-openapi.js +0 -375
- package/dist/switchbot-openapi.js.map +0 -1
- package/dist/switchbot-openapi.test.d.ts +0 -2
- package/dist/switchbot-openapi.test.d.ts.map +0 -1
- package/dist/switchbot-openapi.test.js +0 -36
- package/dist/switchbot-openapi.test.js.map +0 -1
- package/dist/types/ble-guards.d.ts +0 -12
- package/dist/types/ble-guards.d.ts.map +0 -1
- package/dist/types/ble-guards.js +0 -10
- package/dist/types/ble-guards.js.map +0 -1
- package/dist/types/ble-guards.test.d.ts +0 -2
- package/dist/types/ble-guards.test.d.ts.map +0 -1
- package/dist/types/ble-guards.test.js +0 -62
- package/dist/types/ble-guards.test.js.map +0 -1
- package/dist/types/openapi.d.ts +0 -638
- package/dist/types/openapi.d.ts.map +0 -1
- package/dist/types/openapi.js +0 -3
- package/dist/types/openapi.js.map +0 -1
- package/docs/classes/Advertising.html +0 -21
- package/docs/classes/ErrorUtils.html +0 -25
- package/docs/classes/ParameterChecker.html +0 -69
- package/docs/classes/SwitchBotBLE.html +0 -39
- package/docs/classes/SwitchBotOpenAPI.html +0 -57
- package/docs/classes/SwitchbotDevice.html +0 -47
- package/docs/classes/ValidationUtils.html +0 -51
- package/docs/classes/WoPlugMiniEU.html +0 -84
- package/docs/classes/WoSmartLockUltra.html +0 -113
- package/docs/enums/SwitchBotBLEModelFriendlyName.html +0 -39
- package/docs/enums/SwitchBotModel.html +0 -53
- package/docs/interfaces/AdvertisementData.html +0 -3
- package/docs/interfaces/Chars.html +0 -4
- package/docs/interfaces/ColorLightServiceDataBase.html +0 -17
- package/docs/interfaces/ErrorObject.html +0 -3
- package/docs/interfaces/LockBaseServiceData.html +0 -15
- package/docs/interfaces/NobleTypes.html +0 -3
- package/docs/interfaces/Params.html +0 -6
- package/docs/interfaces/PlugMiniServiceDataBase.html +0 -12
- package/docs/interfaces/Rule.html +0 -9
- package/docs/interfaces/ServiceData.html +0 -2
- package/docs/interfaces/SwitchBotBLEDevice.html +0 -28
- package/docs/interfaces/SwitchBotScanner.html +0 -6
- package/docs/interfaces/TemperatureServiceDataBase.html +0 -10
- package/docs/interfaces/WebhookDetail.html +0 -6
- package/docs/interfaces/ad.html +0 -5
- package/docs/interfaces/body.html +0 -3
- package/docs/interfaces/bodyChange.html +0 -4
- package/docs/interfaces/deleteWebhookResponse.html +0 -4
- package/docs/interfaces/device.html +0 -7
- package/docs/interfaces/deviceList.html +0 -2
- package/docs/interfaces/deviceStatus.html +0 -7
- package/docs/interfaces/deviceStatusRequest.html +0 -4
- package/docs/interfaces/deviceWebhook.html +0 -4
- package/docs/interfaces/deviceWebhookContext.html +0 -4
- package/docs/interfaces/devices.html +0 -4
- package/docs/interfaces/infraredRemoteList.html +0 -2
- package/docs/interfaces/irdevice.html +0 -5
- package/docs/interfaces/pushRequest.html +0 -5
- package/docs/interfaces/pushResponse.html +0 -5
- package/docs/interfaces/pushResponseBody.html +0 -3
- package/docs/interfaces/queryWebhookResponse.html +0 -4
- package/docs/interfaces/setupWebhookResponse.html +0 -4
- package/docs/interfaces/updateWebhookResponse.html +0 -4
- package/docs/interfaces/webhookRequest.html +0 -4
- package/docs/types/BLEDeviceServiceData.html +0 -1
- package/docs/types/IndoorCam.html +0 -1
- package/docs/types/MacAddress.html +0 -1
- package/docs/types/airPurifier.html +0 -1
- package/docs/types/airPurifierPM25WebhookContext.html +0 -1
- package/docs/types/airPurifierServiceData.html +0 -1
- package/docs/types/airPurifierStatus.html +0 -1
- package/docs/types/airPurifierTable.html +0 -1
- package/docs/types/airPurifierTablePM25WebhookContext.html +0 -1
- package/docs/types/airPurifierTableServiceData.html +0 -1
- package/docs/types/airPurifierTableStatus.html +0 -1
- package/docs/types/airPurifierTableVOC.html +0 -1
- package/docs/types/airPurifierTableVOCStatus.html +0 -1
- package/docs/types/airPurifierTableVOCWebhookContext.html +0 -1
- package/docs/types/airPurifierTableWebhookContext.html +0 -1
- package/docs/types/airPurifierVOC.html +0 -1
- package/docs/types/airPurifierVOCStatus.html +0 -1
- package/docs/types/airPurifierVOCWebhookContext.html +0 -1
- package/docs/types/airPurifierWebhookContext.html +0 -1
- package/docs/types/batteryCirculatorFan.html +0 -1
- package/docs/types/batteryCirculatorFanServiceData.html +0 -1
- package/docs/types/batteryCirculatorFanStatus.html +0 -1
- package/docs/types/batteryCirculatorFanWebhookContext.html +0 -1
- package/docs/types/blindTilt.html +0 -1
- package/docs/types/blindTiltServiceData.html +0 -1
- package/docs/types/blindTiltStatus.html +0 -1
- package/docs/types/blindTiltWebhookContext.html +0 -1
- package/docs/types/bot.html +0 -1
- package/docs/types/botServiceData.html +0 -1
- package/docs/types/botStatus.html +0 -1
- package/docs/types/botWebhookContext.html +0 -1
- package/docs/types/ceilingLight.html +0 -1
- package/docs/types/ceilingLightPro.html +0 -1
- package/docs/types/ceilingLightProServiceData.html +0 -1
- package/docs/types/ceilingLightProStatus.html +0 -1
- package/docs/types/ceilingLightProWebhookContext.html +0 -1
- package/docs/types/ceilingLightServiceData.html +0 -1
- package/docs/types/ceilingLightStatus.html +0 -1
- package/docs/types/ceilingLightWebhookContext.html +0 -1
- package/docs/types/circulatorFanStatus.html +0 -1
- package/docs/types/circulatorFanWebhookContext.html +0 -1
- package/docs/types/colorBulb.html +0 -1
- package/docs/types/colorBulbServiceData.html +0 -1
- package/docs/types/colorBulbStatus.html +0 -1
- package/docs/types/colorBulbWebhookContext.html +0 -1
- package/docs/types/commandType.html +0 -2
- package/docs/types/contactSensor.html +0 -1
- package/docs/types/contactSensorServiceData.html +0 -1
- package/docs/types/contactSensorStatus.html +0 -1
- package/docs/types/contactSensorWebhookContext.html +0 -1
- package/docs/types/curtain.html +0 -1
- package/docs/types/curtain3.html +0 -1
- package/docs/types/curtain3ServiceData.html +0 -1
- package/docs/types/curtain3WebhookContext.html +0 -1
- package/docs/types/curtainServiceData.html +0 -1
- package/docs/types/curtainStatus.html +0 -1
- package/docs/types/curtainWebhookContext.html +0 -1
- package/docs/types/floorCleaningRobotS10.html +0 -1
- package/docs/types/floorCleaningRobotS10Status.html +0 -1
- package/docs/types/floorCleaningRobotS10WebhookContext.html +0 -1
- package/docs/types/hub2.html +0 -1
- package/docs/types/hub2ServiceData.html +0 -1
- package/docs/types/hub2Status.html +0 -1
- package/docs/types/hub2WebhookContext.html +0 -1
- package/docs/types/hub3ServiceData.html +0 -1
- package/docs/types/humidifier.html +0 -1
- package/docs/types/humidifier2ServiceData.html +0 -1
- package/docs/types/humidifier2Status.html +0 -1
- package/docs/types/humidifier2WebhookContext.html +0 -1
- package/docs/types/humidifierServiceData.html +0 -1
- package/docs/types/humidifierStatus.html +0 -1
- package/docs/types/humidifierWebhookContext.html +0 -1
- package/docs/types/indoorCameraWebhookContext.html +0 -1
- package/docs/types/keypad.html +0 -1
- package/docs/types/keypadDetectorServiceData.html +0 -1
- package/docs/types/keypadTouch.html +0 -1
- package/docs/types/keypadTouchWebhookContext.html +0 -1
- package/docs/types/keypadWebhookContext.html +0 -1
- package/docs/types/lock.html +0 -1
- package/docs/types/lockPro.html +0 -1
- package/docs/types/lockProServiceData.html +0 -1
- package/docs/types/lockProStatus.html +0 -1
- package/docs/types/lockProWebhookContext.html +0 -1
- package/docs/types/lockServiceData.html +0 -1
- package/docs/types/lockStatus.html +0 -1
- package/docs/types/lockWebhookContext.html +0 -1
- package/docs/types/meter.html +0 -1
- package/docs/types/meterPlus.html +0 -1
- package/docs/types/meterPlusServiceData.html +0 -1
- package/docs/types/meterPlusStatus.html +0 -1
- package/docs/types/meterPlusWebhookContext.html +0 -1
- package/docs/types/meterPro.html +0 -1
- package/docs/types/meterProCO2ServiceData.html +0 -1
- package/docs/types/meterProCO2Status.html +0 -1
- package/docs/types/meterProCO2WebhookContext.html +0 -1
- package/docs/types/meterProServiceData.html +0 -1
- package/docs/types/meterProStatus.html +0 -1
- package/docs/types/meterProWebhookContext.html +0 -1
- package/docs/types/meterServiceData.html +0 -1
- package/docs/types/meterStatus.html +0 -1
- package/docs/types/meterWebhookContext.html +0 -1
- package/docs/types/motionSensor.html +0 -1
- package/docs/types/motionSensorServiceData.html +0 -1
- package/docs/types/motionSensorStatus.html +0 -1
- package/docs/types/motionSensorWebhookContext.html +0 -1
- package/docs/types/onadvertisement.html +0 -1
- package/docs/types/ondiscover.html +0 -1
- package/docs/types/outdoorMeter.html +0 -1
- package/docs/types/outdoorMeterServiceData.html +0 -1
- package/docs/types/outdoorMeterStatus.html +0 -1
- package/docs/types/outdoorMeterWebhookContext.html +0 -1
- package/docs/types/panTiltCamWebhookContext.html +0 -1
- package/docs/types/pantiltCam.html +0 -1
- package/docs/types/pantiltCam2k.html +0 -1
- package/docs/types/plug.html +0 -1
- package/docs/types/plugMini.html +0 -1
- package/docs/types/plugMiniEUServiceData.html +0 -1
- package/docs/types/plugMiniEUWebhookContext.html +0 -1
- package/docs/types/plugMiniJPServiceData.html +0 -1
- package/docs/types/plugMiniJPWebhookContext.html +0 -1
- package/docs/types/plugMiniStatus.html +0 -1
- package/docs/types/plugMiniUSServiceData.html +0 -1
- package/docs/types/plugMiniUSWebhookContext.html +0 -1
- package/docs/types/plugStatus.html +0 -1
- package/docs/types/plugWebhookContext.html +0 -1
- package/docs/types/presenceSensor.html +0 -1
- package/docs/types/presenceSensorServiceData.html +0 -1
- package/docs/types/presenceSensorStatus.html +0 -1
- package/docs/types/presenceSensorWebhookContext.html +0 -1
- package/docs/types/relaySwitch1Context.html +0 -1
- package/docs/types/relaySwitch1PMContext.html +0 -1
- package/docs/types/relaySwitch1PMServiceData.html +0 -1
- package/docs/types/relaySwitch1PMStatus.html +0 -1
- package/docs/types/relaySwitch1ServiceData.html +0 -1
- package/docs/types/relaySwitch1Status.html +0 -1
- package/docs/types/remote.html +0 -1
- package/docs/types/remoteServiceData.html +0 -1
- package/docs/types/robotVacuumCleanerS1.html +0 -1
- package/docs/types/robotVacuumCleanerS1Plus.html +0 -1
- package/docs/types/robotVacuumCleanerS1PlusStatus.html +0 -1
- package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +0 -1
- package/docs/types/robotVacuumCleanerS1Status.html +0 -1
- package/docs/types/robotVacuumCleanerS1WebhookContext.html +0 -1
- package/docs/types/robotVacuumCleanerServiceData.html +0 -1
- package/docs/types/stripLight.html +0 -1
- package/docs/types/stripLightServiceData.html +0 -1
- package/docs/types/stripLightStatus.html +0 -1
- package/docs/types/stripLightWebhookContext.html +0 -1
- package/docs/types/waterLeakDetector.html +0 -1
- package/docs/types/waterLeakDetectorServiceData.html +0 -1
- package/docs/types/waterLeakDetectorStatus.html +0 -1
- package/docs/types/waterLeakDetectorWebhookContext.html +0 -1
- package/docs/variables/parameterChecker.html +0 -1
- package/eslint.config.js +0 -48
- package/typedoc.json +0 -17
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { APICommandResponse, APIDevice, APIDeviceStatus, DeviceListResponse, SceneListResponse, WebhookConfig, WebhookQueryResponse, WebhookSetupResponse } from './types/api.js';
|
|
2
|
+
/**
|
|
3
|
+
* OpenAPI Client for SwitchBot API v1.1
|
|
4
|
+
*/
|
|
5
|
+
export declare class OpenAPIClient {
|
|
6
|
+
private token;
|
|
7
|
+
private secret;
|
|
8
|
+
private baseURL;
|
|
9
|
+
private logger;
|
|
10
|
+
constructor(token: string, secret: string, baseURL?: string, logLevel?: number);
|
|
11
|
+
/**
|
|
12
|
+
* Generate authentication headers for API requests
|
|
13
|
+
*/
|
|
14
|
+
private generateHeaders;
|
|
15
|
+
/**
|
|
16
|
+
* Make an API request
|
|
17
|
+
*/
|
|
18
|
+
private makeRequest;
|
|
19
|
+
/**
|
|
20
|
+
* Get all devices
|
|
21
|
+
*/
|
|
22
|
+
getDevices(): Promise<DeviceListResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Get device status
|
|
25
|
+
*/
|
|
26
|
+
getStatus(deviceId: string): Promise<APIDeviceStatus>;
|
|
27
|
+
/**
|
|
28
|
+
* Send command to device
|
|
29
|
+
*/
|
|
30
|
+
sendCommand(deviceId: string, command: string, parameter?: any): Promise<APICommandResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Get all scenes
|
|
33
|
+
*/
|
|
34
|
+
getScenes(): Promise<SceneListResponse>;
|
|
35
|
+
/**
|
|
36
|
+
* Execute a scene
|
|
37
|
+
*/
|
|
38
|
+
executeScene(sceneId: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Setup webhook
|
|
41
|
+
*/
|
|
42
|
+
setupWebhook(config: WebhookConfig): Promise<WebhookSetupResponse>;
|
|
43
|
+
/**
|
|
44
|
+
* Query webhook configuration
|
|
45
|
+
*/
|
|
46
|
+
queryWebhook(urls?: string[]): Promise<WebhookQueryResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Update webhook
|
|
49
|
+
*/
|
|
50
|
+
updateWebhook(config: WebhookConfig): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete webhook
|
|
53
|
+
*/
|
|
54
|
+
deleteWebhook(url: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get specific device information
|
|
57
|
+
*/
|
|
58
|
+
getDevice(deviceId: string): Promise<APIDevice | undefined>;
|
|
59
|
+
/**
|
|
60
|
+
* Get devices by type
|
|
61
|
+
*/
|
|
62
|
+
getDevicesByType(deviceType: string): Promise<APIDevice[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Check if device has cloud service enabled
|
|
65
|
+
*/
|
|
66
|
+
isCloudServiceEnabled(deviceId: string): Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Bot-specific commands
|
|
69
|
+
*/
|
|
70
|
+
botPress(deviceId: string): Promise<APICommandResponse>;
|
|
71
|
+
botTurnOn(deviceId: string): Promise<APICommandResponse>;
|
|
72
|
+
botTurnOff(deviceId: string): Promise<APICommandResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Curtain-specific commands
|
|
75
|
+
*/
|
|
76
|
+
curtainOpen(deviceId: string): Promise<APICommandResponse>;
|
|
77
|
+
curtainClose(deviceId: string): Promise<APICommandResponse>;
|
|
78
|
+
curtainPause(deviceId: string): Promise<APICommandResponse>;
|
|
79
|
+
curtainSetPosition(deviceId: string, position: number): Promise<APICommandResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Lock-specific commands
|
|
82
|
+
*/
|
|
83
|
+
lockLock(deviceId: string): Promise<APICommandResponse>;
|
|
84
|
+
lockUnlock(deviceId: string): Promise<APICommandResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Plug-specific commands
|
|
87
|
+
*/
|
|
88
|
+
plugTurnOn(deviceId: string): Promise<APICommandResponse>;
|
|
89
|
+
plugTurnOff(deviceId: string): Promise<APICommandResponse>;
|
|
90
|
+
plugToggle(deviceId: string): Promise<APICommandResponse>;
|
|
91
|
+
/**
|
|
92
|
+
* Bulb/Light-specific commands
|
|
93
|
+
*/
|
|
94
|
+
lightTurnOn(deviceId: string): Promise<APICommandResponse>;
|
|
95
|
+
lightTurnOff(deviceId: string): Promise<APICommandResponse>;
|
|
96
|
+
lightSetBrightness(deviceId: string, brightness: number): Promise<APICommandResponse>;
|
|
97
|
+
lightSetColor(deviceId: string, red: number, green: number, blue: number): Promise<APICommandResponse>;
|
|
98
|
+
lightSetColorTemperature(deviceId: string, temperature: number): Promise<APICommandResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Humidifier-specific commands
|
|
101
|
+
*/
|
|
102
|
+
humidifierTurnOn(deviceId: string): Promise<APICommandResponse>;
|
|
103
|
+
humidifierTurnOff(deviceId: string): Promise<APICommandResponse>;
|
|
104
|
+
humidifierSetMode(deviceId: string, mode: 'auto' | 'manual'): Promise<APICommandResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Air Purifier-specific commands
|
|
107
|
+
*/
|
|
108
|
+
airPurifierTurnOn(deviceId: string): Promise<APICommandResponse>;
|
|
109
|
+
airPurifierTurnOff(deviceId: string): Promise<APICommandResponse>;
|
|
110
|
+
airPurifierSetMode(deviceId: string, mode: 'auto' | 'manual' | 'sleep'): Promise<APICommandResponse>;
|
|
111
|
+
airPurifierSetFanSpeed(deviceId: string, speed: number): Promise<APICommandResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Blind Tilt-specific commands
|
|
114
|
+
*/
|
|
115
|
+
blindTiltOpen(deviceId: string): Promise<APICommandResponse>;
|
|
116
|
+
blindTiltClose(deviceId: string): Promise<APICommandResponse>;
|
|
117
|
+
blindTiltSetPosition(deviceId: string, position: number): Promise<APICommandResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Get client configuration
|
|
120
|
+
*/
|
|
121
|
+
getConfig(): {
|
|
122
|
+
token: string;
|
|
123
|
+
baseURL: string;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Update base URL
|
|
127
|
+
*/
|
|
128
|
+
setBaseURL(newBaseURL: string): void;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,kBAAkB,EAAE,SAAS,EAAE,eAAe,EAAe,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAOtN;;GAEG;AACH,qBAAa,aAAa;IAItB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IALjB,OAAO,CAAC,MAAM,CAAQ;gBAGZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,MAAkB,EACnC,QAAQ,CAAC,EAAE,MAAM;IASnB;;OAEG;YACW,eAAe;IAc7B;;OAEG;YACW,WAAW;IAgCzB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAK/C;;OAEG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAK3D;;OAEG;IACG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,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI/F;;OAEG;IACG,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIhE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIjE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIpG,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI1F;;OAEG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI5D,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI7D,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI3F;;OAEG;IACH,SAAS,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAO/C;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;CAIrC"}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/* Copyright(C) 2024-2026, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* api.ts: SwitchBot v4.0.0 - OpenAPI Client
|
|
4
|
+
*/
|
|
5
|
+
import { request } from 'undici';
|
|
6
|
+
import { urls } from './settings.js';
|
|
7
|
+
import { createSignature, generateNonce, generateTimestamp, Logger } from './utils/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* OpenAPI Client for SwitchBot API v1.1
|
|
10
|
+
*/
|
|
11
|
+
export class OpenAPIClient {
|
|
12
|
+
token;
|
|
13
|
+
secret;
|
|
14
|
+
baseURL;
|
|
15
|
+
logger;
|
|
16
|
+
constructor(token, secret, baseURL = urls.base, logLevel) {
|
|
17
|
+
this.token = token;
|
|
18
|
+
this.secret = secret;
|
|
19
|
+
this.baseURL = baseURL;
|
|
20
|
+
this.logger = new Logger('OpenAPIClient', logLevel);
|
|
21
|
+
if (!token || !secret) {
|
|
22
|
+
throw new Error('OpenAPI token and secret are required');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generate authentication headers for API requests
|
|
27
|
+
*/
|
|
28
|
+
async generateHeaders() {
|
|
29
|
+
const timestamp = generateTimestamp();
|
|
30
|
+
const nonce = generateNonce();
|
|
31
|
+
const sign = await createSignature(this.token, this.secret, timestamp, nonce);
|
|
32
|
+
return {
|
|
33
|
+
'Authorization': this.token,
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
't': timestamp,
|
|
36
|
+
'sign': sign,
|
|
37
|
+
'nonce': nonce,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Make an API request
|
|
42
|
+
*/
|
|
43
|
+
async makeRequest(method, path, body) {
|
|
44
|
+
const headers = await this.generateHeaders();
|
|
45
|
+
const url = `${this.baseURL}${path}`;
|
|
46
|
+
this.logger.debug(`${method} ${url}`, body ? { body } : {});
|
|
47
|
+
try {
|
|
48
|
+
const response = await request(url, {
|
|
49
|
+
method,
|
|
50
|
+
headers,
|
|
51
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
52
|
+
});
|
|
53
|
+
const data = await response.body.json();
|
|
54
|
+
if (data.statusCode !== 100 && data.statusCode !== 200) {
|
|
55
|
+
this.logger.error('API request failed', data);
|
|
56
|
+
throw new Error(`API Error ${data.statusCode}: ${data.message}`);
|
|
57
|
+
}
|
|
58
|
+
this.logger.debug('API response', data);
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
this.logger.error('API request error', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get all devices
|
|
68
|
+
*/
|
|
69
|
+
async getDevices() {
|
|
70
|
+
const response = await this.makeRequest('GET', '/v1.1/devices');
|
|
71
|
+
return response.body;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get device status
|
|
75
|
+
*/
|
|
76
|
+
async getStatus(deviceId) {
|
|
77
|
+
const response = await this.makeRequest('GET', `/v1.1/devices/${deviceId}/status`);
|
|
78
|
+
return response.body;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Send command to device
|
|
82
|
+
*/
|
|
83
|
+
async sendCommand(deviceId, command, parameter) {
|
|
84
|
+
const body = {
|
|
85
|
+
command,
|
|
86
|
+
parameter: parameter !== undefined ? parameter : 'default',
|
|
87
|
+
};
|
|
88
|
+
const response = await this.makeRequest('POST', `/v1.1/devices/${deviceId}/commands`, body);
|
|
89
|
+
return {
|
|
90
|
+
statusCode: response.statusCode,
|
|
91
|
+
message: response.message,
|
|
92
|
+
body: response.body,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get all scenes
|
|
97
|
+
*/
|
|
98
|
+
async getScenes() {
|
|
99
|
+
const response = await this.makeRequest('GET', '/v1.1/scenes');
|
|
100
|
+
return response.body;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Execute a scene
|
|
104
|
+
*/
|
|
105
|
+
async executeScene(sceneId) {
|
|
106
|
+
await this.makeRequest('POST', `/v1.1/scenes/${sceneId}/execute`);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Setup webhook
|
|
110
|
+
*/
|
|
111
|
+
async setupWebhook(config) {
|
|
112
|
+
const response = await this.makeRequest('POST', '/v1.1/webhook/setupWebhook', config);
|
|
113
|
+
return {
|
|
114
|
+
statusCode: response.statusCode,
|
|
115
|
+
message: response.message,
|
|
116
|
+
body: response.body,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Query webhook configuration
|
|
121
|
+
*/
|
|
122
|
+
async queryWebhook(urls) {
|
|
123
|
+
const body = urls ? { urls } : {};
|
|
124
|
+
const response = await this.makeRequest('POST', '/v1.1/webhook/queryWebhook', body);
|
|
125
|
+
return {
|
|
126
|
+
statusCode: response.statusCode,
|
|
127
|
+
message: response.message,
|
|
128
|
+
body: response.body,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Update webhook
|
|
133
|
+
*/
|
|
134
|
+
async updateWebhook(config) {
|
|
135
|
+
await this.makeRequest('POST', '/v1.1/webhook/updateWebhook', config);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Delete webhook
|
|
139
|
+
*/
|
|
140
|
+
async deleteWebhook(url) {
|
|
141
|
+
await this.makeRequest('POST', '/v1.1/webhook/deleteWebhook', { url });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get specific device information
|
|
145
|
+
*/
|
|
146
|
+
async getDevice(deviceId) {
|
|
147
|
+
const devices = await this.getDevices();
|
|
148
|
+
return devices.deviceList.find(d => d.deviceId === deviceId);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get devices by type
|
|
152
|
+
*/
|
|
153
|
+
async getDevicesByType(deviceType) {
|
|
154
|
+
const devices = await this.getDevices();
|
|
155
|
+
return devices.deviceList.filter(d => d.deviceType === deviceType);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if device has cloud service enabled
|
|
159
|
+
*/
|
|
160
|
+
async isCloudServiceEnabled(deviceId) {
|
|
161
|
+
const device = await this.getDevice(deviceId);
|
|
162
|
+
return device?.enableCloudService ?? false;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Bot-specific commands
|
|
166
|
+
*/
|
|
167
|
+
async botPress(deviceId) {
|
|
168
|
+
return this.sendCommand(deviceId, 'press');
|
|
169
|
+
}
|
|
170
|
+
async botTurnOn(deviceId) {
|
|
171
|
+
return this.sendCommand(deviceId, 'turnOn');
|
|
172
|
+
}
|
|
173
|
+
async botTurnOff(deviceId) {
|
|
174
|
+
return this.sendCommand(deviceId, 'turnOff');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Curtain-specific commands
|
|
178
|
+
*/
|
|
179
|
+
async curtainOpen(deviceId) {
|
|
180
|
+
return this.sendCommand(deviceId, 'setPosition', '0,ff,0');
|
|
181
|
+
}
|
|
182
|
+
async curtainClose(deviceId) {
|
|
183
|
+
return this.sendCommand(deviceId, 'setPosition', '0,ff,100');
|
|
184
|
+
}
|
|
185
|
+
async curtainPause(deviceId) {
|
|
186
|
+
return this.sendCommand(deviceId, 'pause');
|
|
187
|
+
}
|
|
188
|
+
async curtainSetPosition(deviceId, position) {
|
|
189
|
+
return this.sendCommand(deviceId, 'setPosition', `0,ff,${position}`);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Lock-specific commands
|
|
193
|
+
*/
|
|
194
|
+
async lockLock(deviceId) {
|
|
195
|
+
return this.sendCommand(deviceId, 'lock');
|
|
196
|
+
}
|
|
197
|
+
async lockUnlock(deviceId) {
|
|
198
|
+
return this.sendCommand(deviceId, 'unlock');
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Plug-specific commands
|
|
202
|
+
*/
|
|
203
|
+
async plugTurnOn(deviceId) {
|
|
204
|
+
return this.sendCommand(deviceId, 'turnOn');
|
|
205
|
+
}
|
|
206
|
+
async plugTurnOff(deviceId) {
|
|
207
|
+
return this.sendCommand(deviceId, 'turnOff');
|
|
208
|
+
}
|
|
209
|
+
async plugToggle(deviceId) {
|
|
210
|
+
return this.sendCommand(deviceId, 'toggle');
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Bulb/Light-specific commands
|
|
214
|
+
*/
|
|
215
|
+
async lightTurnOn(deviceId) {
|
|
216
|
+
return this.sendCommand(deviceId, 'turnOn');
|
|
217
|
+
}
|
|
218
|
+
async lightTurnOff(deviceId) {
|
|
219
|
+
return this.sendCommand(deviceId, 'turnOff');
|
|
220
|
+
}
|
|
221
|
+
async lightSetBrightness(deviceId, brightness) {
|
|
222
|
+
return this.sendCommand(deviceId, 'setBrightness', brightness);
|
|
223
|
+
}
|
|
224
|
+
async lightSetColor(deviceId, red, green, blue) {
|
|
225
|
+
return this.sendCommand(deviceId, 'setColor', `${red}:${green}:${blue}`);
|
|
226
|
+
}
|
|
227
|
+
async lightSetColorTemperature(deviceId, temperature) {
|
|
228
|
+
return this.sendCommand(deviceId, 'setColorTemperature', temperature);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Humidifier-specific commands
|
|
232
|
+
*/
|
|
233
|
+
async humidifierTurnOn(deviceId) {
|
|
234
|
+
return this.sendCommand(deviceId, 'turnOn');
|
|
235
|
+
}
|
|
236
|
+
async humidifierTurnOff(deviceId) {
|
|
237
|
+
return this.sendCommand(deviceId, 'turnOff');
|
|
238
|
+
}
|
|
239
|
+
async humidifierSetMode(deviceId, mode) {
|
|
240
|
+
return this.sendCommand(deviceId, 'setMode', mode === 'auto' ? 'auto' : '101');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Air Purifier-specific commands
|
|
244
|
+
*/
|
|
245
|
+
async airPurifierTurnOn(deviceId) {
|
|
246
|
+
return this.sendCommand(deviceId, 'turnOn');
|
|
247
|
+
}
|
|
248
|
+
async airPurifierTurnOff(deviceId) {
|
|
249
|
+
return this.sendCommand(deviceId, 'turnOff');
|
|
250
|
+
}
|
|
251
|
+
async airPurifierSetMode(deviceId, mode) {
|
|
252
|
+
return this.sendCommand(deviceId, 'setMode', mode);
|
|
253
|
+
}
|
|
254
|
+
async airPurifierSetFanSpeed(deviceId, speed) {
|
|
255
|
+
return this.sendCommand(deviceId, 'setFanSpeed', speed);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Blind Tilt-specific commands
|
|
259
|
+
*/
|
|
260
|
+
async blindTiltOpen(deviceId) {
|
|
261
|
+
return this.sendCommand(deviceId, 'setPosition', '0,ff,0');
|
|
262
|
+
}
|
|
263
|
+
async blindTiltClose(deviceId) {
|
|
264
|
+
return this.sendCommand(deviceId, 'setPosition', '0,ff,100');
|
|
265
|
+
}
|
|
266
|
+
async blindTiltSetPosition(deviceId, position) {
|
|
267
|
+
return this.sendCommand(deviceId, 'setPosition', `0,ff,${position}`);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get client configuration
|
|
271
|
+
*/
|
|
272
|
+
getConfig() {
|
|
273
|
+
return {
|
|
274
|
+
token: this.token,
|
|
275
|
+
baseURL: this.baseURL,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Update base URL
|
|
280
|
+
*/
|
|
281
|
+
setBaseURL(newBaseURL) {
|
|
282
|
+
this.baseURL = newBaseURL;
|
|
283
|
+
this.logger.info(`Base URL updated to ${newBaseURL}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE5F;;GAEG;AACH,MAAM,OAAO,aAAa;IAId;IACA;IACA;IALF,MAAM,CAAQ;IAEtB,YACU,KAAa,EACb,MAAc,EACd,UAAkB,IAAI,CAAC,IAAI,EACnC,QAAiB;QAHT,UAAK,GAAL,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AAuB,UAAU,EAAE,CAAC,CAAA;IACvD,CAAC;CACF"}
|
package/dist/ble.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Buffer } from 'node:buffer';
|
|
2
|
+
import type { BLEAdvertisement, BLEScanOptions } from './types/ble.js';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
/**
|
|
5
|
+
* BLE Scanner for discovering SwitchBot devices
|
|
6
|
+
*/
|
|
7
|
+
export declare class BLEScanner extends EventEmitter {
|
|
8
|
+
private noble;
|
|
9
|
+
private logger;
|
|
10
|
+
private scanning;
|
|
11
|
+
private discoveredDevices;
|
|
12
|
+
private noblePromise;
|
|
13
|
+
constructor(options?: {
|
|
14
|
+
noble?: any;
|
|
15
|
+
logLevel?: number;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Initialize Noble lazily
|
|
19
|
+
*/
|
|
20
|
+
private initializeNoble;
|
|
21
|
+
/**
|
|
22
|
+
* Ensure Noble is loaded before operations
|
|
23
|
+
*/
|
|
24
|
+
private ensureNoble;
|
|
25
|
+
/**
|
|
26
|
+
* Setup Noble event handlers
|
|
27
|
+
*/
|
|
28
|
+
private setupNobleHandlers;
|
|
29
|
+
/**
|
|
30
|
+
* Handle device discovery
|
|
31
|
+
*/
|
|
32
|
+
private handleDiscovery;
|
|
33
|
+
/**
|
|
34
|
+
* Parse service data from BLE advertisement
|
|
35
|
+
*/
|
|
36
|
+
private parseServiceData;
|
|
37
|
+
/**
|
|
38
|
+
* Start scanning for devices
|
|
39
|
+
*/
|
|
40
|
+
startScan(options?: BLEScanOptions): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Stop scanning
|
|
43
|
+
*/
|
|
44
|
+
stopScan(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get all discovered devices
|
|
47
|
+
*/
|
|
48
|
+
getDiscoveredDevices(): BLEAdvertisement[];
|
|
49
|
+
/**
|
|
50
|
+
* Get discovered device by MAC
|
|
51
|
+
*/
|
|
52
|
+
getDevice(mac: string): BLEAdvertisement | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Check if currently scanning
|
|
55
|
+
*/
|
|
56
|
+
isScanning(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Wait for specific device
|
|
59
|
+
*/
|
|
60
|
+
waitForDevice(mac: string, timeoutMs?: number): Promise<BLEAdvertisement>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* BLE Connection for communicating with SwitchBot devices
|
|
64
|
+
*/
|
|
65
|
+
export declare class BLEConnection {
|
|
66
|
+
private noble;
|
|
67
|
+
private logger;
|
|
68
|
+
private connections;
|
|
69
|
+
private characteristics;
|
|
70
|
+
private noblePromise;
|
|
71
|
+
constructor(options?: {
|
|
72
|
+
noble?: any;
|
|
73
|
+
logLevel?: number;
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* Initialize Noble lazily
|
|
77
|
+
*/
|
|
78
|
+
private initializeNoble;
|
|
79
|
+
/**
|
|
80
|
+
* Ensure Noble is loaded before operations
|
|
81
|
+
*/
|
|
82
|
+
private ensureNoble;
|
|
83
|
+
/**
|
|
84
|
+
* Connect to a device
|
|
85
|
+
*/
|
|
86
|
+
connect(mac: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Discover service characteristics
|
|
89
|
+
*/
|
|
90
|
+
private discoverCharacteristics;
|
|
91
|
+
/**
|
|
92
|
+
* Disconnect from a device
|
|
93
|
+
*/
|
|
94
|
+
disconnect(mac: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Write data to device
|
|
97
|
+
*/
|
|
98
|
+
write(mac: string, data: Buffer): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Read data from device
|
|
101
|
+
*/
|
|
102
|
+
read(mac: string): Promise<Buffer>;
|
|
103
|
+
/**
|
|
104
|
+
* Check if connected to device
|
|
105
|
+
*/
|
|
106
|
+
isConnected(mac: string): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Disconnect all devices
|
|
109
|
+
*/
|
|
110
|
+
disconnectAll(): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Get connected device count
|
|
113
|
+
*/
|
|
114
|
+
getConnectionCount(): number;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=ble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ble.d.ts","sourceRoot":"","sources":["../src/ble.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAkB,MAAM,gBAAgB,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAM1C;;GAEG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,iBAAiB,CAA2C;IACpE,OAAO,CAAC,YAAY,CAA4B;gBAEpC,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,GAAG,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO;IAc5D;;OAEG;YACW,eAAe;IAwB7B;;OAEG;YACW,WAAW;IAMzB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA2B1B;;OAEG;IACH,OAAO,CAAC,eAAe;IAsCvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAiCxB;;OAEG;IACG,SAAS,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC5D;;OAEG;IACH,QAAQ,IAAI,IAAI;IAMhB;;OAEG;IACH,oBAAoB,IAAI,gBAAgB,EAAE;IAI1C;;OAEG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIpD;;OAEG;IACH,UAAU,IAAI,OAAO;IA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