1212 MeterDeviceStatus ,
1313 MotionSensorDeviceStatus ,
1414 PlugDeviceStatus ,
15+ PlugMiniJpDeviceStatus ,
16+ PlugMiniUsDeviceStatus ,
1517 SmartFanDeviceStatus ,
18+ StripLightDeviceStatus ,
1619)
1720from switchbot_client .enums import ControlCommand , DeviceType
1821from switchbot_client .types import APIPhysicalDeviceObject
@@ -48,6 +51,10 @@ def create_by_api_object( # noqa
4851 return Bot (client , device )
4952 if device_type == DeviceType .PLUG :
5053 return Plug (client , device )
54+ if device_type == DeviceType .PLUG_MINI_US :
55+ return PlugMiniUs (client , device )
56+ if device_type == DeviceType .PLUG_MINI_JP :
57+ return PlugMiniJp (client , device )
5158 if device_type == DeviceType .CURTAIN :
5259 return Curtain (client , device )
5360 if device_type == DeviceType .METER :
@@ -62,6 +69,8 @@ def create_by_api_object( # noqa
6269 return Humidifier (client , device )
6370 if device_type == DeviceType .SMART_FAN :
6471 return SmartFan (client , device )
72+ if device_type == DeviceType .STRIP_LIGHT :
73+ return StripLight (client , device )
6574 if device_type == DeviceType .INDOOR_CAM :
6675 return IndoorCam (client , device )
6776 if device_type == DeviceType .REMOTE :
@@ -198,6 +207,106 @@ def turn_off(self) -> SwitchBotCommandResult:
198207 return self .command (ControlCommand .Plug .TURN_OFF )
199208
200209
210+ class PlugMiniUs (SwitchBotPhysicalDevice ):
211+ def __init__ (self , client : SwitchBotClient , device : APIPhysicalDeviceObject ):
212+ super ().__init__ (client , device )
213+ self ._check_device_type (DeviceType .PLUG_MINI_US )
214+
215+ @staticmethod
216+ def create_by_id (client : SwitchBotClient , device_id : str ) -> PlugMiniUs :
217+ device = SwitchBotPhysicalDevice .get_device_by_id (client , device_id )
218+ return PlugMiniUs (client , device )
219+
220+ def status (self ) -> PlugMiniUsDeviceStatus :
221+ status = super ().status ()
222+ return PlugMiniUsDeviceStatus (
223+ device_id = status .device_id ,
224+ device_type = status .device_type ,
225+ device_name = status .device_name ,
226+ hub_device_id = status .hub_device_id ,
227+ raw_data = status .raw_data ,
228+ power = status .raw_data ["power" ],
229+ voltage = status .raw_data ["voltage" ],
230+ weight = status .raw_data ["weight" ],
231+ electricity_of_day = status .raw_data ["electricityOfDay" ],
232+ electric_current = status .raw_data ["electricCurrent" ],
233+ )
234+
235+ def power (self ) -> str :
236+ return self .status ().power
237+
238+ def voltage (self ) -> int :
239+ return self .status ().voltage
240+
241+ def weight (self ) -> int :
242+ return self .status ().weight
243+
244+ def electricity_of_day (self ) -> int :
245+ return self .status ().electricity_of_day
246+
247+ def electric_current (self ) -> int :
248+ return self .status ().electric_current
249+
250+ def turn_on (self ) -> SwitchBotCommandResult :
251+ return self .command (ControlCommand .PlugMiniUs .TURN_ON )
252+
253+ def turn_off (self ) -> SwitchBotCommandResult :
254+ return self .command (ControlCommand .PlugMiniUs .TURN_OFF )
255+
256+ def toggle (self ) -> SwitchBotCommandResult :
257+ return self .command (ControlCommand .PlugMiniUs .TOGGLE )
258+
259+
260+ class PlugMiniJp (SwitchBotPhysicalDevice ):
261+ def __init__ (self , client : SwitchBotClient , device : APIPhysicalDeviceObject ):
262+ super ().__init__ (client , device )
263+ self ._check_device_type (DeviceType .PLUG_MINI_JP )
264+
265+ @staticmethod
266+ def create_by_id (client : SwitchBotClient , device_id : str ) -> PlugMiniJp :
267+ device = SwitchBotPhysicalDevice .get_device_by_id (client , device_id )
268+ return PlugMiniJp (client , device )
269+
270+ def status (self ) -> PlugMiniJpDeviceStatus :
271+ status = super ().status ()
272+ return PlugMiniJpDeviceStatus (
273+ device_id = status .device_id ,
274+ device_type = status .device_type ,
275+ device_name = status .device_name ,
276+ hub_device_id = status .hub_device_id ,
277+ raw_data = status .raw_data ,
278+ power = status .raw_data ["power" ],
279+ voltage = status .raw_data ["voltage" ],
280+ weight = status .raw_data ["weight" ],
281+ electricity_of_day = status .raw_data ["electricityOfDay" ],
282+ electric_current = status .raw_data ["electricCurrent" ],
283+ )
284+
285+ def power (self ) -> str :
286+ return self .status ().power
287+
288+ def voltage (self ) -> int :
289+ return self .status ().voltage
290+
291+ def weight (self ) -> int :
292+ return self .status ().weight
293+
294+ def electricity_of_day (self ) -> int :
295+ return self .status ().electricity_of_day
296+
297+ def electric_current (self ) -> int :
298+ return self .status ().electric_current
299+
300+ def turn_on (self ) -> SwitchBotCommandResult :
301+ return self .command (ControlCommand .PlugMiniJp .TURN_ON )
302+
303+ def turn_off (self ) -> SwitchBotCommandResult :
304+ return self .command (ControlCommand .PlugMiniJp .TURN_OFF )
305+
306+ def toggle (self ) -> SwitchBotCommandResult :
307+ return self .command (ControlCommand .PlugMiniJp .TOGGLE )
308+
309+
201310class Curtain (SwitchBotPhysicalDevice ):
202311 class Parameters :
203312 MODE_PERFORMANCE = "0"
@@ -388,10 +497,10 @@ def color_temperature(self) -> int:
388497 return self .status ().color_temperature
389498
390499 def turn_on (self ) -> SwitchBotCommandResult :
391- return self .command (ControlCommand .Humidifier .TURN_ON )
500+ return self .command (ControlCommand .ColorBulb .TURN_ON )
392501
393502 def turn_off (self ) -> SwitchBotCommandResult :
394- return self .command (ControlCommand .Humidifier .TURN_OFF )
503+ return self .command (ControlCommand .ColorBulb .TURN_OFF )
395504
396505 def set_brightness (self , brightness : int ) -> SwitchBotCommandResult :
397506 """
@@ -598,6 +707,71 @@ def set_shake_range(self, shake_range: int) -> SwitchBotCommandResult:
598707 )
599708
600709
710+ class StripLight (SwitchBotPhysicalDevice ):
711+ def __init__ (self , client : SwitchBotClient , device : APIPhysicalDeviceObject ):
712+ super ().__init__ (client , device )
713+ self ._check_device_type (DeviceType .STRIP_LIGHT )
714+
715+ @staticmethod
716+ def create_by_id (client : SwitchBotClient , device_id : str ) -> StripLight :
717+ device = SwitchBotPhysicalDevice .get_device_by_id (client , device_id )
718+ return StripLight (client , device )
719+
720+ def status (self ) -> StripLightDeviceStatus :
721+ status = super ().status ()
722+ colors = [int (i ) for i in status .raw_data ["color" ].split (":" )]
723+ color_hex = f"#{ colors [0 ]:02x} { colors [1 ]:02x} { colors [2 ]:02x} "
724+ return StripLightDeviceStatus (
725+ device_id = status .device_id ,
726+ device_type = status .device_type ,
727+ device_name = status .device_name ,
728+ hub_device_id = status .hub_device_id ,
729+ raw_data = status .raw_data ,
730+ power = status .raw_data ["power" ],
731+ color_hex = color_hex ,
732+ brightness = status .raw_data ["brightness" ],
733+ )
734+
735+ def power (self ) -> str :
736+ return self .status ().power
737+
738+ def brightness (self ) -> int :
739+ return self .status ().brightness
740+
741+ def color_hex (self ) -> str :
742+ """
743+ returns #rrggbb format color string
744+ """
745+ return self .status ().color_hex
746+
747+ def turn_on (self ) -> SwitchBotCommandResult :
748+ return self .command (ControlCommand .StripLight .TURN_ON )
749+
750+ def turn_off (self ) -> SwitchBotCommandResult :
751+ return self .command (ControlCommand .StripLight .TURN_OFF )
752+
753+ def toggle (self ) -> SwitchBotCommandResult :
754+ return self .command (ControlCommand .StripLight .TOGGLE )
755+
756+ def set_brightness (self , brightness : int ) -> SwitchBotCommandResult :
757+ """
758+ brightness: 1 ~ 100
759+ """
760+ return self .command (ControlCommand .StripLight .SET_BRIGHTNESS , parameter = f"{ brightness } " )
761+
762+ def set_color_by_number (self , red : int , green : int , blue : int ) -> SwitchBotCommandResult :
763+ """
764+ red: 0 ~ 255
765+ green: 0 ~ 255
766+ blue: 0 ~ 255
767+ """
768+ return self .command (ControlCommand .StripLight .SET_COLOR , parameter = f"{ red } :{ green } :{ blue } " )
769+
770+ def set_color (self , color_hex : str ) -> SwitchBotCommandResult :
771+ rgb = tuple (int (color_hex .lstrip ("#" )[i : i + 2 ], 16 ) for i in (0 , 2 , 4 ))
772+ return self .set_color_by_number (rgb [0 ], rgb [1 ], rgb [2 ])
773+
774+
601775class IndoorCam (SwitchBotPhysicalDevice ):
602776 def __init__ (self , client : SwitchBotClient , device : APIPhysicalDeviceObject ):
603777 super ().__init__ (client , device )
0 commit comments