node-switchbot 2.5.0-beta.9 → 3.0.0
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/workflows/beta-release.yml +25 -2
- package/.github/workflows/release.yml +13 -0
- package/BLE.md +1144 -0
- package/CHANGELOG.md +14 -0
- package/OpenAPI.md +185 -0
- package/README.md +20 -1189
- package/branding/Node_x_SwitchBot.svg +9 -0
- package/branding/icon.png +0 -0
- package/branding/switchbot.png +0 -0
- package/dist/advertising.d.ts +3 -3
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +26 -26
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +19 -50
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +41 -100
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +41 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +72 -128
- package/dist/device/wobulb.js.map +1 -1
- package/dist/device/woceilinglight.d.ts +47 -21
- package/dist/device/woceilinglight.d.ts.map +1 -1
- package/dist/device/woceilinglight.js +96 -171
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +11 -1
- package/dist/device/wocontact.d.ts.map +1 -1
- package/dist/device/wocontact.js +23 -22
- package/dist/device/wocontact.js.map +1 -1
- package/dist/device/wocurtain.d.ts +39 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +69 -103
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +37 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +55 -89
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +11 -1
- package/dist/device/wohub2.d.ts.map +1 -1
- package/dist/device/wohub2.js +21 -29
- package/dist/device/wohub2.js.map +1 -1
- package/dist/device/wohumi.d.ts +37 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +52 -83
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +12 -1
- package/dist/device/woiosensorth.d.ts.map +1 -1
- package/dist/device/woiosensorth.js +25 -29
- package/dist/device/woiosensorth.js.map +1 -1
- package/dist/device/woplugmini.d.ts +45 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +71 -77
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +11 -1
- package/dist/device/wopresence.d.ts.map +1 -1
- package/dist/device/wopresence.js +21 -27
- package/dist/device/wopresence.js.map +1 -1
- package/dist/device/wosensorth.d.ts +18 -2
- package/dist/device/wosensorth.d.ts.map +1 -1
- package/dist/device/wosensorth.js +34 -50
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +63 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +114 -195
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +16 -12
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +34 -29
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +4 -3
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +5 -4
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +13 -5
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +13 -2
- package/dist/device.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/parameter-checker.d.ts +10 -13
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +16 -1
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +41 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +43 -0
- package/dist/settings.js.map +1 -1
- package/dist/{switchbot.d.ts → switchbot-ble.d.ts} +13 -8
- package/dist/switchbot-ble.d.ts.map +1 -0
- package/dist/switchbot-ble.js +427 -0
- package/dist/switchbot-ble.js.map +1 -0
- package/dist/switchbot-openapi.d.ts +131 -0
- package/dist/switchbot-openapi.d.ts.map +1 -0
- package/dist/switchbot-openapi.js +311 -0
- package/dist/switchbot-openapi.js.map +1 -0
- package/dist/test/advertising.test.d.ts +2 -0
- package/dist/test/advertising.test.d.ts.map +1 -0
- package/dist/test/advertising.test.js +99 -0
- package/dist/test/advertising.test.js.map +1 -0
- package/dist/test/device.test.d.ts +2 -0
- package/dist/test/device.test.d.ts.map +1 -0
- package/dist/test/device.test.js +38 -0
- package/dist/test/device.test.js.map +1 -0
- package/dist/test/index.test.d.ts +2 -0
- package/dist/test/index.test.d.ts.map +1 -0
- package/dist/test/index.test.js +35 -0
- package/dist/test/index.test.js.map +1 -0
- package/dist/test/parameter-checker.test.d.ts +2 -0
- package/dist/test/parameter-checker.test.d.ts.map +1 -0
- package/dist/test/parameter-checker.test.js +108 -0
- package/dist/test/parameter-checker.test.js.map +1 -0
- package/dist/test/settings.test.d.ts +2 -0
- package/dist/test/settings.test.d.ts.map +1 -0
- package/dist/test/settings.test.js +49 -0
- package/dist/test/settings.test.js.map +1 -0
- package/dist/test/switchbot-openapi.test.d.ts +2 -0
- package/dist/test/switchbot-openapi.test.d.ts.map +1 -0
- package/dist/test/switchbot-openapi.test.js +96 -0
- package/dist/test/switchbot-openapi.test.js.map +1 -0
- package/dist/test/switchbot.test.d.ts +2 -0
- package/dist/test/switchbot.test.d.ts.map +1 -0
- package/dist/test/switchbot.test.js +106 -0
- package/dist/test/switchbot.test.js.map +1 -0
- package/dist/test/woblindtilt.test.js +70 -20
- package/dist/test/woblindtilt.test.js.map +1 -1
- package/dist/test/wobulb.test.js +87 -44
- package/dist/test/wobulb.test.js.map +1 -1
- package/dist/test/woceilinglight.test.js +72 -54
- package/dist/test/woceilinglight.test.js.map +1 -1
- package/dist/test/wocontact.test.js +51 -20
- package/dist/test/wocontact.test.js.map +1 -1
- package/dist/test/wocurtain.test.js +65 -23
- package/dist/test/wocurtain.test.js.map +1 -1
- package/dist/test/wohand.test.js +34 -40
- package/dist/test/wohand.test.js.map +1 -1
- package/dist/test/wohub2.test.d.ts +2 -0
- package/dist/test/wohub2.test.d.ts.map +1 -0
- package/dist/test/wohub2.test.js +80 -0
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/test/wohumi.test.js +70 -49
- package/dist/test/wohumi.test.js.map +1 -1
- package/dist/test/woiosensorth.test.js +33 -32
- package/dist/test/woiosensorth.test.js.map +1 -1
- package/dist/test/woplugmini.test.js +80 -57
- package/dist/test/woplugmini.test.js.map +1 -1
- package/dist/test/wopresence.test.js +44 -18
- package/dist/test/wopresence.test.js.map +1 -1
- package/dist/test/wosensorth.test.js +44 -52
- package/dist/test/wosensorth.test.js.map +1 -1
- package/dist/test/wosmartlock.test.js +126 -59
- package/dist/test/wosmartlock.test.js.map +1 -1
- package/dist/test/wosmartlockpro.test.js +96 -69
- package/dist/test/wosmartlockpro.test.js.map +1 -1
- package/dist/test/wostrip.test.js +70 -83
- package/dist/test/wostrip.test.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +4 -12
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/devicelist.js +0 -4
- package/dist/types/devicelist.js.map +1 -1
- package/dist/types/devicepush.d.ts +13 -0
- package/dist/types/devicepush.d.ts.map +1 -0
- package/dist/types/devicepush.js +2 -0
- package/dist/types/devicepush.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +2 -3
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +32 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/types.d.ts +23 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +14 -0
- package/dist/types/types.js.map +1 -1
- package/docs/assets/highlight.css +12 -47
- package/docs/assets/main.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/SwitchBotBLE.html +64 -0
- package/docs/classes/SwitchBotOpenAPI.html +47 -0
- package/docs/classes/SwitchbotDevice.html +32 -33
- package/docs/enums/LogLevel.html +10 -0
- package/docs/enums/SwitchBotBLEModel.html +2 -2
- package/docs/enums/SwitchBotBLEModelFriendlyName.html +2 -2
- package/docs/enums/SwitchBotBLEModelName.html +2 -2
- package/docs/enums/SwitchBotModel.html +2 -2
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +16 -993
- package/docs/interfaces/Ad-1.html +5 -0
- package/docs/interfaces/AdvertisementData.html +3 -0
- package/docs/interfaces/Chars.html +4 -0
- package/docs/interfaces/ErrorObject.html +3 -0
- package/docs/interfaces/Params.html +6 -0
- package/docs/interfaces/ServiceData.html +2 -0
- package/docs/interfaces/SwitchBotBLEDevice.html +21 -0
- package/docs/interfaces/WebhookDetail.html +6 -0
- package/docs/interfaces/ad.html +5 -0
- package/docs/interfaces/body.html +3 -0
- package/docs/interfaces/bodyChange.html +4 -0
- package/docs/interfaces/deleteWebhookResponse.html +4 -0
- package/docs/interfaces/device.html +7 -0
- package/docs/interfaces/deviceList.html +2 -0
- package/docs/interfaces/deviceStatus.html +7 -0
- package/docs/interfaces/deviceStatusRequest.html +4 -0
- package/docs/interfaces/deviceWebhook.html +4 -0
- package/docs/interfaces/deviceWebhookContext.html +4 -0
- package/docs/interfaces/devices.html +4 -0
- package/docs/interfaces/infraredRemoteList.html +2 -0
- package/docs/interfaces/irdevice.html +5 -0
- package/docs/interfaces/pushResponse.html +4 -0
- package/docs/interfaces/queryWebhookResponse.html +4 -0
- package/docs/interfaces/setupWebhookResponse.html +4 -0
- package/docs/interfaces/switchbot.html +3 -0
- package/docs/interfaces/updateWebhookResponse.html +4 -0
- package/docs/interfaces/webhookRequest.html +4 -0
- package/docs/media/BLE.md +1109 -0
- package/docs/media/OpenAPI.md +185 -0
- package/docs/modules.html +136 -3
- package/docs/types/MacAddress.html +1 -0
- package/docs/types/batteryCirculatorFan.html +1 -0
- package/docs/types/batteryCirculatorFanServiceData.html +1 -0
- package/docs/types/batteryCirculatorFanStatus.html +1 -0
- package/docs/types/batteryCirculatorFanWebhookContext.html +1 -0
- package/docs/types/blindTilt.html +1 -0
- package/docs/types/blindTiltServiceData.html +1 -0
- package/docs/types/blindTiltStatus.html +1 -0
- package/docs/types/blindTiltWebhookContext.html +1 -0
- package/docs/types/bot.html +1 -0
- package/docs/types/botServiceData.html +1 -0
- package/docs/types/botStatus.html +1 -0
- package/docs/types/botWebhookContext.html +1 -0
- package/docs/types/ceilingLight.html +1 -0
- package/docs/types/ceilingLightPro.html +1 -0
- package/docs/types/ceilingLightProServiceData.html +1 -0
- package/docs/types/ceilingLightProStatus.html +1 -0
- package/docs/types/ceilingLightProWebhookContext.html +1 -0
- package/docs/types/ceilingLightServiceData.html +1 -0
- package/docs/types/ceilingLightStatus.html +1 -0
- package/docs/types/ceilingLightWebhookContext.html +1 -0
- package/docs/types/colorBulb.html +1 -0
- package/docs/types/colorBulbServiceData.html +1 -0
- package/docs/types/colorBulbStatus.html +1 -0
- package/docs/types/colorBulbWebhookContext.html +1 -0
- package/docs/types/contactSensor.html +1 -0
- package/docs/types/contactSensorServiceData.html +1 -0
- package/docs/types/contactSensorStatus.html +1 -0
- package/docs/types/contactSensorWebhookContext.html +1 -0
- package/docs/types/curtain.html +1 -0
- package/docs/types/curtain3.html +1 -0
- package/docs/types/curtain3ServiceData.html +1 -0
- package/docs/types/curtain3WebhookContext.html +1 -0
- package/docs/types/curtainServiceData.html +1 -0
- package/docs/types/curtainStatus.html +1 -0
- package/docs/types/curtainWebhookContext.html +1 -0
- package/docs/types/floorCleaningRobotS10.html +1 -0
- package/docs/types/floorCleaningRobotS10Status.html +1 -0
- package/docs/types/floorCleaningRobotS10WebhookContext.html +1 -0
- package/docs/types/hub2.html +1 -0
- package/docs/types/hub2ServiceData.html +1 -0
- package/docs/types/hub2Status.html +1 -0
- package/docs/types/hub2WebhookContext.html +1 -0
- package/docs/types/humidifier.html +1 -0
- package/docs/types/humidifierServiceData.html +1 -0
- package/docs/types/humidifierStatus.html +1 -0
- package/docs/types/humidifierWebhookContext.html +1 -0
- package/docs/types/indoorCam.html +1 -0
- package/docs/types/indoorCameraWebhookContext.html +1 -0
- package/docs/types/keypad.html +1 -0
- package/docs/types/keypadTouch.html +1 -0
- package/docs/types/keypadTouchWebhookContext.html +1 -0
- package/docs/types/keypadWebhookContext.html +1 -0
- package/docs/types/lock.html +1 -0
- package/docs/types/lockPro.html +1 -0
- package/docs/types/lockProServiceData.html +1 -0
- package/docs/types/lockProStatus.html +1 -0
- package/docs/types/lockProWebhookContext.html +1 -0
- package/docs/types/lockServiceData.html +1 -0
- package/docs/types/lockStatus.html +1 -0
- package/docs/types/lockWebhookContext.html +1 -0
- package/docs/types/meter.html +1 -0
- package/docs/types/meterPlus.html +1 -0
- package/docs/types/meterPlusServiceData.html +1 -0
- package/docs/types/meterPlusStatus.html +1 -0
- package/docs/types/meterPlusWebhookContext.html +1 -0
- package/docs/types/meterServiceData.html +1 -0
- package/docs/types/meterStatus.html +1 -0
- package/docs/types/meterWebhookContext.html +1 -0
- package/docs/types/motionSensor.html +1 -0
- package/docs/types/motionSensorServiceData.html +1 -0
- package/docs/types/motionSensorStatus.html +1 -0
- package/docs/types/motionSensorWebhookContext.html +1 -0
- package/docs/types/outdoorMeter.html +1 -0
- package/docs/types/outdoorMeterServiceData.html +1 -0
- package/docs/types/outdoorMeterStatus.html +1 -0
- package/docs/types/outdoorMeterWebhookContext.html +1 -0
- package/docs/types/panTiltCamWebhookContext.html +1 -0
- package/docs/types/pantiltCam.html +1 -0
- package/docs/types/pantiltCam2k.html +1 -0
- package/docs/types/plug.html +1 -0
- package/docs/types/plugMini.html +1 -0
- package/docs/types/plugMiniJPServiceData.html +1 -0
- package/docs/types/plugMiniJPWebhookContext.html +1 -0
- package/docs/types/plugMiniStatus.html +1 -0
- package/docs/types/plugMiniUSServiceData.html +1 -0
- package/docs/types/plugMiniUSWebhookContext.html +1 -0
- package/docs/types/plugStatus.html +1 -0
- package/docs/types/plugWebhookContext.html +1 -0
- package/docs/types/remote.html +1 -0
- package/docs/types/robotVacuumCleanerS1.html +1 -0
- package/docs/types/robotVacuumCleanerS1Plus.html +1 -0
- package/docs/types/robotVacuumCleanerS1PlusStatus.html +1 -0
- package/docs/types/robotVacuumCleanerS1PlusWebhookContext.html +1 -0
- package/docs/types/robotVacuumCleanerS1Status.html +1 -0
- package/docs/types/robotVacuumCleanerS1WebhookContext.html +1 -0
- package/docs/types/robotVacuumCleanerServiceData.html +1 -0
- package/docs/types/stripLight.html +1 -0
- package/docs/types/stripLightServiceData.html +1 -0
- package/docs/types/stripLightStatus.html +1 -0
- package/docs/types/stripLightWebhookContext.html +1 -0
- package/docs/types/waterLeakDetector.html +1 -0
- package/docs/types/waterLeakDetectorServiceData.html +1 -0
- package/docs/types/waterLeakDetectorStatus.html +1 -0
- package/docs/types/waterLeakDetectorWebhookContext.html +1 -0
- package/package.json +13 -11
- package/.github/npm-version-script.cjs +0 -81
- package/dist/switchbot.d.ts.map +0 -1
- package/dist/switchbot.js +0 -259
- package/dist/switchbot.js.map +0 -1
- package/dist/test/wohand2.test.d.ts +0 -2
- package/dist/test/wohand2.test.d.ts.map +0 -1
- package/dist/test/wohand2.test.js +0 -50
- package/dist/test/wohand2.test.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/docs/classes/SwitchBot.html +0 -16
- package/docs/types/SwitchBotBLEDevice.html +0 -1
package/dist/test/wohand.test.js
CHANGED
|
@@ -1,61 +1,55 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import
|
|
3
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
4
|
-
/* eslint-disable no-console */
|
|
5
|
-
// wohand.test.ts
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
6
3
|
import { WoHand } from '../device/wohand.js';
|
|
4
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
7
5
|
describe('woHand', () => {
|
|
6
|
+
const emitLog = vi.fn();
|
|
8
7
|
describe('parseServiceData', () => {
|
|
9
|
-
it('should
|
|
10
|
-
const serviceData = Buffer.from([
|
|
11
|
-
const result = await WoHand.parseServiceData(serviceData,
|
|
12
|
-
expect(result).toBeNull();
|
|
13
|
-
});
|
|
14
|
-
it('should parse service data correctly', async () => {
|
|
15
|
-
const serviceData = Buffer.from([0x00, 0b11000000, 0b01111111]);
|
|
16
|
-
const result = await WoHand.parseServiceData(serviceData, console.log);
|
|
8
|
+
it('should parse valid service data correctly', async () => {
|
|
9
|
+
const serviceData = Buffer.from([0x00, 0x80, 0x64]); // Example buffer
|
|
10
|
+
const result = await WoHand.parseServiceData(serviceData, emitLog);
|
|
17
11
|
expect(result).toEqual({
|
|
18
12
|
model: SwitchBotBLEModel.Bot,
|
|
19
13
|
modelName: SwitchBotBLEModelName.Bot,
|
|
20
14
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.Bot,
|
|
21
15
|
mode: true,
|
|
22
|
-
state:
|
|
23
|
-
battery:
|
|
16
|
+
state: true,
|
|
17
|
+
battery: 100,
|
|
24
18
|
});
|
|
25
19
|
});
|
|
20
|
+
it('should return null for invalid buffer length', async () => {
|
|
21
|
+
const serviceData = Buffer.from([0x00, 0x80]); // Invalid buffer length
|
|
22
|
+
const result = await WoHand.parseServiceData(serviceData, emitLog);
|
|
23
|
+
expect(result).toBeNull();
|
|
24
|
+
expect(emitLog).toHaveBeenCalledWith('error', '[parseServiceData] Buffer length 2 !== 3!');
|
|
25
|
+
});
|
|
26
26
|
});
|
|
27
|
-
describe('
|
|
28
|
-
let
|
|
27
|
+
describe('operateBot', () => {
|
|
28
|
+
let woHand;
|
|
29
29
|
beforeEach(() => {
|
|
30
|
-
const peripheral = {};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return Buffer.from([0x01, 0x00, 0x00]);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it('should press the button', async () => {
|
|
37
|
-
await expect(wohand.press()).resolves.toBeUndefined();
|
|
30
|
+
const peripheral = {};
|
|
31
|
+
woHand = new WoHand(peripheral, emitLog);
|
|
32
|
+
vi.spyOn(woHand, 'command').mockResolvedValue(Buffer.from([0x01, 0x00, 0x00]));
|
|
38
33
|
});
|
|
39
|
-
it('should
|
|
40
|
-
await
|
|
34
|
+
it('should send the correct command for press', async () => {
|
|
35
|
+
await woHand.press();
|
|
36
|
+
expect(woHand.command).toHaveBeenCalledWith(Buffer.from([0x57, 0x01, 0x00]));
|
|
41
37
|
});
|
|
42
|
-
it('should
|
|
43
|
-
await
|
|
38
|
+
it('should send the correct command for turnOn', async () => {
|
|
39
|
+
await woHand.turnOn();
|
|
40
|
+
expect(woHand.command).toHaveBeenCalledWith(Buffer.from([0x57, 0x01, 0x01]));
|
|
44
41
|
});
|
|
45
|
-
it('should
|
|
46
|
-
await
|
|
42
|
+
it('should send the correct command for turnOff', async () => {
|
|
43
|
+
await woHand.turnOff();
|
|
44
|
+
expect(woHand.command).toHaveBeenCalledWith(Buffer.from([0x57, 0x01, 0x02]));
|
|
47
45
|
});
|
|
48
|
-
it('should
|
|
49
|
-
await
|
|
46
|
+
it('should send the correct command for down', async () => {
|
|
47
|
+
await woHand.down();
|
|
48
|
+
expect(woHand.command).toHaveBeenCalledWith(Buffer.from([0x57, 0x01, 0x03]));
|
|
50
49
|
});
|
|
51
|
-
it('should
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
it('should throw an error if the device returns an error', async () => {
|
|
55
|
-
jest.spyOn(wohand, 'command').mockImplementation(async () => {
|
|
56
|
-
return Buffer.from([0x00, 0x00, 0x00]);
|
|
57
|
-
});
|
|
58
|
-
await expect(wohand.operateBot([0x57, 0x01, 0x00])).rejects.toThrow('The device returned an error: 0x000000');
|
|
50
|
+
it('should send the correct command for up', async () => {
|
|
51
|
+
await woHand.up();
|
|
52
|
+
expect(woHand.command).toHaveBeenCalledWith(Buffer.from([0x57, 0x01, 0x04]));
|
|
59
53
|
});
|
|
60
54
|
});
|
|
61
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohand.test.js","sourceRoot":"","sources":["../../src/test/wohand.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wohand.test.js","sourceRoot":"","sources":["../../src/test/wohand.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,OAAO,GAAG,EAAE,CAAC,EAAE,EAAE,CAAA;IAEvB,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,2CAA2C,EAAE,KAAK,IAAI,EAAE;YACzD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA,CAAC,iBAAiB;YACrE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAA;YAElE,MAAM,CAAC,MAAM,CA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 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wohub2.test.d.ts","sourceRoot":"","sources":["../../src/test/wohub2.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
|
+
import { WoHub2 } from '../device/wohub2.js';
|
|
4
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
5
|
+
describe('woHub2', () => {
|
|
6
|
+
describe('parseServiceData', () => {
|
|
7
|
+
const emitLog = vi.fn();
|
|
8
|
+
it('should parse valid manufacturer data correctly', async () => {
|
|
9
|
+
const manufacturerData = Buffer.from([
|
|
10
|
+
0x01,
|
|
11
|
+
0x82,
|
|
12
|
+
0x41,
|
|
13
|
+
0x00,
|
|
14
|
+
0x00,
|
|
15
|
+
0x00,
|
|
16
|
+
0x00,
|
|
17
|
+
0x00,
|
|
18
|
+
0x00,
|
|
19
|
+
0x00,
|
|
20
|
+
0x00,
|
|
21
|
+
0x00,
|
|
22
|
+
0x1F,
|
|
23
|
+
0x00,
|
|
24
|
+
0x00,
|
|
25
|
+
0x00,
|
|
26
|
+
]);
|
|
27
|
+
const result = await WoHub2.parseServiceData(manufacturerData, emitLog);
|
|
28
|
+
expect(result).toEqual({
|
|
29
|
+
model: SwitchBotBLEModel.Hub2,
|
|
30
|
+
modelName: SwitchBotBLEModelName.Hub2,
|
|
31
|
+
modelFriendlyName: SwitchBotBLEModelFriendlyName.Hub2,
|
|
32
|
+
celsius: 2.1,
|
|
33
|
+
fahrenheit: 35.8,
|
|
34
|
+
fahrenheit_mode: true,
|
|
35
|
+
humidity: 65,
|
|
36
|
+
lightLevel: 31,
|
|
37
|
+
});
|
|
38
|
+
expect(emitLog).not.toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
it('should return null for invalid buffer length', async () => {
|
|
41
|
+
const manufacturerData = Buffer.from([0x01, 0x82]);
|
|
42
|
+
const result = await WoHub2.parseServiceData(manufacturerData, emitLog);
|
|
43
|
+
expect(result).toBeNull();
|
|
44
|
+
expect(emitLog).toHaveBeenCalledWith('error', '[parseServiceDataForWoHub2] Buffer length 2 !== 16!');
|
|
45
|
+
});
|
|
46
|
+
it('should parse negative temperature correctly', async () => {
|
|
47
|
+
const manufacturerData = Buffer.from([
|
|
48
|
+
0x01,
|
|
49
|
+
0x02,
|
|
50
|
+
0x41,
|
|
51
|
+
0x00,
|
|
52
|
+
0x00,
|
|
53
|
+
0x00,
|
|
54
|
+
0x00,
|
|
55
|
+
0x00,
|
|
56
|
+
0x00,
|
|
57
|
+
0x00,
|
|
58
|
+
0x00,
|
|
59
|
+
0x00,
|
|
60
|
+
0x1F,
|
|
61
|
+
0x00,
|
|
62
|
+
0x00,
|
|
63
|
+
0x00,
|
|
64
|
+
]);
|
|
65
|
+
const result = await WoHub2.parseServiceData(manufacturerData, emitLog);
|
|
66
|
+
expect(result).toEqual({
|
|
67
|
+
model: SwitchBotBLEModel.Hub2,
|
|
68
|
+
modelName: SwitchBotBLEModelName.Hub2,
|
|
69
|
+
modelFriendlyName: SwitchBotBLEModelFriendlyName.Hub2,
|
|
70
|
+
celsius: -2.1,
|
|
71
|
+
fahrenheit: 28.2,
|
|
72
|
+
fahrenheit_mode: true,
|
|
73
|
+
humidity: 65,
|
|
74
|
+
lightLevel: 31,
|
|
75
|
+
});
|
|
76
|
+
expect(emitLog).not.toHaveBeenCalled();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=wohub2.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wohub2.test.js","sourceRoot":"","sources":["../../src/test/wohub2.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EA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
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
-
import
|
|
3
|
-
// wohumi.test.ts
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
3
|
import { WoHumi } from '../device/wohumi.js';
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
SwitchbotDevice: jest.fn().mockImplementation(() => {
|
|
8
|
-
return {
|
|
9
|
-
command: jest.fn(),
|
|
10
|
-
};
|
|
11
|
-
}),
|
|
12
|
-
};
|
|
13
|
-
});
|
|
4
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
14
5
|
describe('woHumi', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
const emitLog = vi.fn();
|
|
7
|
+
describe('parseServiceData', () => {
|
|
8
|
+
it('should return parsed data for valid service data', async () => {
|
|
9
|
+
const serviceData = Buffer.from([0x00, 0x80, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00]);
|
|
10
|
+
const result = await WoHumi.parseServiceData(serviceData, emitLog);
|
|
11
|
+
expect(result).toEqual({
|
|
12
|
+
model: SwitchBotBLEModel.Humidifier,
|
|
13
|
+
modelName: SwitchBotBLEModelName.Humidifier,
|
|
14
|
+
modelFriendlyName: SwitchBotBLEModelFriendlyName.Humidifier,
|
|
15
|
+
onState: true,
|
|
16
|
+
autoMode: true,
|
|
17
|
+
percentage: 0,
|
|
18
|
+
humidity: 0,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
it('should return null for invalid service data length', async () => {
|
|
22
|
+
const serviceData = Buffer.from([0x00, 0x80, 0x00]);
|
|
23
|
+
const result = await WoHumi.parseServiceData(serviceData, emitLog);
|
|
24
|
+
expect(result).toBeNull();
|
|
25
|
+
expect(emitLog).toHaveBeenCalledWith('error', '[parseServiceDataForWoHumi] Buffer length 3 !== 8!');
|
|
26
|
+
});
|
|
29
27
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
describe('operateHumi', () => {
|
|
29
|
+
it('should throw an error if the device returns an error', async () => {
|
|
30
|
+
const peripheral = {};
|
|
31
|
+
const wohumi = new WoHumi(peripheral, emitLog);
|
|
32
|
+
vi.spyOn(wohumi, 'command').mockResolvedValue(Buffer.from([0x00, 0x00, 0x00]));
|
|
33
|
+
await expect(wohumi.operateHumi([0x57, 0x01, 0x00])).rejects.toThrow('The device returned an error: 0x000000');
|
|
34
|
+
});
|
|
34
35
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
describe('press', () => {
|
|
37
|
+
it('should call operateHumi with correct bytes', async () => {
|
|
38
|
+
const peripheral = {};
|
|
39
|
+
const wohumi = new WoHumi(peripheral, emitLog);
|
|
40
|
+
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
41
|
+
await wohumi.press();
|
|
42
|
+
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x00]);
|
|
43
|
+
});
|
|
39
44
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
describe('turnOn', () => {
|
|
46
|
+
it('should call operateHumi with correct bytes', async () => {
|
|
47
|
+
const peripheral = {};
|
|
48
|
+
const wohumi = new WoHumi(peripheral, emitLog);
|
|
49
|
+
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
50
|
+
await wohumi.turnOn();
|
|
51
|
+
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x01]);
|
|
52
|
+
});
|
|
44
53
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
describe('turnOff', () => {
|
|
55
|
+
it('should call operateHumi with correct bytes', async () => {
|
|
56
|
+
const peripheral = {};
|
|
57
|
+
const wohumi = new WoHumi(peripheral, emitLog);
|
|
58
|
+
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
59
|
+
await wohumi.turnOff();
|
|
60
|
+
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x02]);
|
|
61
|
+
});
|
|
49
62
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
describe('down', () => {
|
|
64
|
+
it('should call operateHumi with correct bytes', async () => {
|
|
65
|
+
const peripheral = {};
|
|
66
|
+
const wohumi = new WoHumi(peripheral, emitLog);
|
|
67
|
+
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
68
|
+
await wohumi.down();
|
|
69
|
+
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x03]);
|
|
70
|
+
});
|
|
54
71
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
describe('up', () => {
|
|
73
|
+
it('should call operateHumi with correct bytes', async () => {
|
|
74
|
+
const peripheral = {};
|
|
75
|
+
const wohumi = new WoHumi(peripheral, emitLog);
|
|
76
|
+
const operateHumiSpy = vi.spyOn(wohumi, 'operateHumi').mockResolvedValue();
|
|
77
|
+
await wohumi.up();
|
|
78
|
+
expect(operateHumiSpy).toHaveBeenCalledWith([0x57, 0x01, 0x04]);
|
|
79
|
+
});
|
|
59
80
|
});
|
|
60
81
|
});
|
|
61
82
|
//# sourceMappingURL=wohumi.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wohumi.test.js","sourceRoot":"","sources":["../../src/test/wohumi.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wohumi.test.js","sourceRoot":"","sources":["../../src/test/wohumi.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,M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AAC,CAAA;YACrD,MAAM,cAAc,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,iBAAiB,EAAE,CAAA;YAC1E,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YACnB,MAAM,CAAC,cAAc,CAAC,CAAC,oBAAoB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE;QAClB,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;YAC1D,MAAM,UAAU,GAAG,EAAiC,CAAA;YACpD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,OAAc,CAAC,CAAA;YACrD,MAAM,cAAc,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,iBAAiB,EAAE,CAAA;YAC1E,MAAM,MAAM,CAAC,EAAE,EAAE,CAAA;YACjB,MAAM,CAAC,cAAc,CAAC,CAAC,oBAAoB,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
3
|
import { WoIOSensorTH } from '../device/woiosensorth.js';
|
|
4
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
3
5
|
describe('woIOSensorTH', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
describe('parseServiceData', () => {
|
|
7
|
+
const emitLog = vi.fn();
|
|
8
|
+
it('should return parsed data for valid buffers', async () => {
|
|
9
|
+
const serviceData = Buffer.from([0x00, 0x00, 0x64]);
|
|
10
|
+
const manufacturerData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x2A, 0x50, 0x00]);
|
|
11
|
+
const result = await WoIOSensorTH.parseServiceData(serviceData, manufacturerData, emitLog);
|
|
12
|
+
expect(result).toEqual({
|
|
13
|
+
model: SwitchBotBLEModel.OutdoorMeter,
|
|
14
|
+
modelName: SwitchBotBLEModelName.OutdoorMeter,
|
|
15
|
+
modelFriendlyName: SwitchBotBLEModelFriendlyName.OutdoorMeter,
|
|
16
|
+
celsius: 42.6,
|
|
17
|
+
fahrenheit: 108.7,
|
|
18
|
+
fahrenheit_mode: true,
|
|
19
|
+
humidity: 80,
|
|
20
|
+
battery: 100,
|
|
21
|
+
});
|
|
22
|
+
expect(emitLog).not.toHaveBeenCalled();
|
|
23
|
+
});
|
|
24
|
+
it('should return null for invalid serviceData length', async () => {
|
|
25
|
+
const serviceData = Buffer.from([0x00, 0x00]);
|
|
26
|
+
const manufacturerData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x2A, 0x50, 0x00]);
|
|
27
|
+
const result = await WoIOSensorTH.parseServiceData(serviceData, manufacturerData, emitLog);
|
|
28
|
+
expect(result).toBeNull();
|
|
29
|
+
expect(emitLog).toHaveBeenCalledWith('error', '[parseServiceDataForWoIOSensorTH] Service Data Buffer length 2 !== 3!');
|
|
30
|
+
});
|
|
31
|
+
it('should return null for invalid manufacturerData length', async () => {
|
|
32
|
+
const serviceData = Buffer.from([0x00, 0x00, 0x64]);
|
|
33
|
+
const manufacturerData = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x2A]);
|
|
34
|
+
const result = await WoIOSensorTH.parseServiceData(serviceData, manufacturerData, emitLog);
|
|
35
|
+
expect(result).toBeNull();
|
|
36
|
+
expect(emitLog).toHaveBeenCalledWith('error', '[parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length 12 !== 14!');
|
|
29
37
|
});
|
|
30
|
-
});
|
|
31
|
-
it('should log messages for incorrect data lengths', async () => {
|
|
32
|
-
const onlog = jest.fn();
|
|
33
|
-
await WoIOSensorTH.parseServiceData(invalidServiceData, validManufacturerData, onlog);
|
|
34
|
-
expect(onlog).toHaveBeenCalledWith('[parseServiceDataForWoIOSensorTH] Service Data Buffer length 2 !== 3!');
|
|
35
|
-
await WoIOSensorTH.parseServiceData(validServiceData, invalidManufacturerData, onlog);
|
|
36
|
-
expect(onlog).toHaveBeenCalledWith('[parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length 11 !== 14!');
|
|
37
38
|
});
|
|
38
39
|
});
|
|
39
40
|
//# sourceMappingURL=woiosensorth.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"woiosensorth.test.js","sourceRoot":"","sources":["../../src/test/woiosensorth.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"woiosensorth.test.js","sourceRoot":"","sources":["../../src/test/woiosensorth.test.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB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