Skip to content

Commit

Permalink
Add Hub 2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaDiba committed Feb 23, 2024
1 parent 246b721 commit 324cb7e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lucadiba/switchbot-client": minor
---

Add support for Hub 2.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The following devices are supported:
- Curtain
- Curtain 3
- Hub
- Hub 2
- Hub Plus
- Hub Mini
- Humidifier
Expand All @@ -113,7 +114,6 @@ The following devices are currently not supported:

- Battery Circulator Fan
- Blind Tilt
- Hub 2
- Outdoor meter
- Virtual infrared remote devices

Expand Down
5 changes: 5 additions & 0 deletions src/SwitchBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwitchBotContactSensor from "./devices/SwitchBotContactSensor";
import SwitchBotCurtain from "./devices/SwitchBotCurtain";
import SwitchBotCurtain3 from "./devices/SwitchBotCurtain3";
import SwitchBotHub from "./devices/SwitchBotHub";
import SwitchBotHub2 from "./devices/SwitchBotHub2";
import SwitchBotHumidifier from "./devices/SwitchBotHumidifier";
import SwitchBotKeypad from "./devices/SwitchBotKeypad";
import SwitchBotLock from "./devices/SwitchBotLock";
Expand Down Expand Up @@ -90,6 +91,10 @@ export default class SwitchBot {
return new SwitchBotHub(deviceId, this.getDeps());
};

public hub2 = (deviceId: DeviceId) => {
return new SwitchBotHub2(deviceId, this.getDeps());
};

public humidifier = (deviceId: DeviceId) => {
return new SwitchBotHumidifier(deviceId, this.getDeps());
};
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/SwitchBot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwitchBotContactSensor from "../devices/SwitchBotContactSensor";
import SwitchBotCurtain from "../devices/SwitchBotCurtain";
import SwitchBotCurtain3 from "../devices/SwitchBotCurtain3";
import SwitchBotHub from "../devices/SwitchBotHub";
import SwitchBotHub2 from "../devices/SwitchBotHub2";
import SwitchBotHumidifier from "../devices/SwitchBotHumidifier";
import SwitchBotKeypad from "../devices/SwitchBotKeypad";
import SwitchBotLock from "../devices/SwitchBotLock";
Expand Down Expand Up @@ -195,6 +196,10 @@ describe("instantiate devices", () => {
expect(switchBot.hub(deviceId)).toBeInstanceOf(SwitchBotHub);
});

test("Hub 2", () => {
expect(switchBot.hub2(deviceId)).toBeInstanceOf(SwitchBotHub2);
});

test("Humidifier", () => {
expect(switchBot.humidifier(deviceId)).toBeInstanceOf(SwitchBotHumidifier);
});
Expand Down
36 changes: 36 additions & 0 deletions src/devices/SwitchBotHub2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BaseDeviceGetDeviceBody, BaseDeviceStatusBody } from "../types";
import { DEVICE_TYPES } from "../utils/constant";
import { DeviceWithStatus } from "./Device";

type DeviceType = typeof DEVICE_TYPES.HUB_2;

export type GetDeviceBody = BaseDeviceGetDeviceBody<DeviceType>;

export type StatusBody = BaseDeviceStatusBody<DeviceType> & {
/**
* The temperature in Celsius.
*/
temperature: number;

/**
* The humidity in percentage.
*/
humidity: number;

/**
* The level of illuminance of the ambience light, 1~20.
*/
lightLevel: number;

/**
* The current firmware version, e.g. `V4.2`.
*/
version: string;
};

export type CommandBody = never;

export default class SwitchBotHub2 extends DeviceWithStatus<
StatusBody,
CommandBody
> {}
1 change: 1 addition & 0 deletions src/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const DEVICE_TYPES = {
CURTAIN: "Curtain",
CURTAIN_3: "Curtain 3",
HUB: "Hub",
HUB_2: "Hub 2",
HUB_PLUS: "Hub Plus",
HUB_MINI: "Hub Mini",
METER: "Meter",
Expand Down

0 comments on commit 324cb7e

Please sign in to comment.