Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit 872d160

Browse files
authored
Merge pull request #109 from kzosabe/add-cleaner-device
Add RobotVacuumCleaner devices
2 parents af8e5cc + 70287e6 commit 872d160

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

switchbot_client/devices/physical.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
PlugDeviceStatus,
1919
PlugMiniJpDeviceStatus,
2020
PlugMiniUsDeviceStatus,
21+
RobotVacuumCleanerDeviceStatus,
2122
SmartFanDeviceStatus,
2223
StripLightDeviceStatus,
2324
)
@@ -85,6 +86,10 @@ def create_by_api_object( # noqa
8586
return Remote(client, device)
8687
if device_type == DeviceType.LOCK:
8788
return Lock(client, device)
89+
if device_type == DeviceType.ROBOT_VACUUM_CLEANER_S1:
90+
return RobotVacuumCleanerS1(client, device)
91+
if device_type == DeviceType.ROBOT_VACUUM_CLEANER_S1_PLUS:
92+
return RobotVacuumCleanerS1Plus(client, device)
8893

8994
raise TypeError(f"invalid physical device object: {device}")
9095

@@ -887,3 +892,54 @@ def lock_state(self) -> str:
887892

888893
def door_state(self) -> str:
889894
return self.status().door_state
895+
896+
897+
class RobotVacuumCleanerS1(SwitchBotPhysicalDevice):
898+
def __init__(self, client: SwitchBotClient, device: APIPhysicalDeviceObject):
899+
super().__init__(client, device)
900+
self._check_device_type(DeviceType.ROBOT_VACUUM_CLEANER_S1)
901+
902+
@staticmethod
903+
def create_by_id(client: SwitchBotClient, device_id: str) -> RobotVacuumCleanerS1:
904+
device = SwitchBotPhysicalDevice.get_device_by_id(client, device_id)
905+
return RobotVacuumCleanerS1(client, device)
906+
907+
def status(self) -> RobotVacuumCleanerDeviceStatus:
908+
status = super().status()
909+
return RobotVacuumCleanerDeviceStatus(
910+
device_id=status.device_id,
911+
device_type=status.device_type,
912+
device_name=status.device_name,
913+
hub_device_id=status.hub_device_id,
914+
raw_data=status.raw_data,
915+
working_status=status.raw_data["working_status"],
916+
online_status=status.raw_data["online_status"],
917+
battery=status.raw_data["battery"],
918+
)
919+
920+
def working_status(self) -> str:
921+
return self.status().working_status
922+
923+
def online_status(self) -> str:
924+
return self.status().online_status
925+
926+
def battery(self) -> int:
927+
return self.status().battery
928+
929+
def start(self) -> SwitchBotCommandResult:
930+
return self.command(ControlCommand.RobotVacuumCleaner.START)
931+
932+
def stop(self) -> SwitchBotCommandResult:
933+
return self.command(ControlCommand.RobotVacuumCleaner.STOP)
934+
935+
def dock(self) -> SwitchBotCommandResult:
936+
return self.command(ControlCommand.RobotVacuumCleaner.DOCK)
937+
938+
def pow_level(self, level: int) -> SwitchBotCommandResult:
939+
return self.command(ControlCommand.RobotVacuumCleaner.POW_LEVEL, parameter=f"{level}")
940+
941+
942+
class RobotVacuumCleanerS1Plus(RobotVacuumCleanerS1):
943+
def __init__(self, client: SwitchBotClient, device: APIPhysicalDeviceObject):
944+
super().__init__(client, device)
945+
self._check_device_type(DeviceType.ROBOT_VACUUM_CLEANER_S1_PLUS)

switchbot_client/devices/status.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ class LockDeviceStatus(DeviceStatus):
134134
door_state: str
135135

136136

137+
@dataclass()
138+
class RobotVacuumCleanerDeviceStatus(DeviceStatus):
139+
working_status: str
140+
online_status: str
141+
battery: int
142+
143+
137144
@dataclass
138145
class PseudoRemoteDeviceStatus(DeviceStatus):
139146
power: Optional[str]

switchbot_client/enums.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class DeviceType:
1919
INDOOR_CAM = "Indoor Cam"
2020
REMOTE = "Remote" # undocumented in official api reference?
2121
LOCK = "Lock"
22+
ROBOT_VACUUM_CLEANER_S1_PLUS = "Robot Vacuum Cleaner S1"
23+
ROBOT_VACUUM_CLEANER_S1 = "Robot Vacuum Cleaner S1 Plus"
2224

2325

2426
class RemoteType:
@@ -72,6 +74,12 @@ class StripLight:
7274
SET_BRIGHTNESS = "setBrightness"
7375
SET_COLOR = "setColor"
7476

77+
class RobotVacuumCleaner:
78+
START = "start"
79+
STOP = "stop"
80+
DOCK = "dock"
81+
POW_LEVEL = "PowLevel"
82+
7583
class VirtualInfrared:
7684
SET_ALL = "setAll"
7785
SET_CHANNEL = "SetChannel"

0 commit comments

Comments
 (0)