switchbot-api 2.8.0__tar.gz → 2.10.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: switchbot_api
3
- Version: 2.8.0
3
+ Version: 2.10.0
4
4
  Summary: An asynchronous library to use Switchbot API
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "switchbot_api"
3
- version = "2.8.0"
3
+ version = "2.10.0"
4
4
  description = "An asynchronous library to use Switchbot API"
5
5
  authors = ["Ravaka Razafimanantsoa <contact@ravaka.dev>"]
6
6
  license = "MIT"
@@ -18,6 +18,7 @@ from aiohttp.hdrs import METH_GET, METH_POST
18
18
  from switchbot_api.commands import (
19
19
  AirConditionerCommands,
20
20
  AirPurifierCommands,
21
+ ArtFrameCommands,
21
22
  BatteryCirculatorFanCommands,
22
23
  BlindTiltCommands,
23
24
  BotCommands,
@@ -30,9 +31,11 @@ from switchbot_api.commands import (
30
31
  FanCommands,
31
32
  HumidifierCommands,
32
33
  HumidifierV2Commands,
34
+ KeyPadCommands,
33
35
  LightCommands,
34
36
  LockCommands,
35
37
  LockV2Commands,
38
+ LockV3Commands,
36
39
  OthersCommands,
37
40
  RGBWLightCommands,
38
41
  RGBWWLightCommands,
@@ -54,6 +57,7 @@ from switchbot_api.exceptions import (
54
57
  )
55
58
  from switchbot_api.models import (
56
59
  BatteryCirculatorFanMode,
60
+ BatteryLevel,
57
61
  PowerState,
58
62
  SmartRadiatorThermostatMode,
59
63
  VacuumCleanMode,
@@ -64,8 +68,10 @@ from switchbot_api.models import (
64
68
  __all__ = [
65
69
  "AirConditionerCommands",
66
70
  "AirPurifierCommands",
71
+ "ArtFrameCommands",
67
72
  "BatteryCirculatorFanCommands",
68
73
  "BatteryCirculatorFanMode",
74
+ "BatteryLevel",
69
75
  "BlindTiltCommands",
70
76
  "BotCommands",
71
77
  "CeilingLightCommands",
@@ -78,9 +84,11 @@ __all__ = [
78
84
  "FanCommands",
79
85
  "HumidifierCommands",
80
86
  "HumidifierV2Commands",
87
+ "KeyPadCommands",
81
88
  "LightCommands",
82
89
  "LockCommands",
83
90
  "LockV2Commands",
91
+ "LockV3Commands",
84
92
  "OthersCommands",
85
93
  "PowerState",
86
94
  "RGBWLightCommands",
@@ -93,7 +93,21 @@ class LockV2Commands(Commands):
93
93
  @classmethod
94
94
  def get_supported_devices(cls) -> list[str]:
95
95
  """Get supported devices."""
96
- return ["Smart Lock", "Smart Lock Pro", "Smart Lock Ultra"]
96
+ return ["Smart Lock", "Smart Lock Pro", "Smart Lock Ultra", "Smart Lock Vision"]
97
+
98
+
99
+ class LockV3Commands(Commands):
100
+ """Lock commands."""
101
+
102
+ LOCK = "lock"
103
+ UNLOCK = "unlock"
104
+ DEADBOLT = "deadbolt"
105
+ NIGHT_LATCH_UNLOCK = "nightLatchUnlock"
106
+
107
+ @classmethod
108
+ def get_supported_devices(cls) -> list[str]:
109
+ """Get supported devices."""
110
+ return ["Smart Lock Vision Pro"]
97
111
 
98
112
 
99
113
  class HumidifierCommands(Commands):
@@ -190,13 +204,15 @@ class RGBWLightCommands(Commands):
190
204
 
191
205
  # Supported Device list:
192
206
  # Strip Light
207
+ # RGBIC Neon Rope Light
208
+ # RGBIC Neon Wire Rope Light
193
209
  SET_BRIGHTNESS = "setBrightness"
194
210
  SET_COLOR = "setColor"
195
211
 
196
212
  @classmethod
197
213
  def get_supported_devices(cls) -> list[str]:
198
214
  """Get supported devices."""
199
- return ["Strip Light"]
215
+ return ["Strip Light", "RGBIC Neon Rope Light", "RGBIC Neon Wire Rope Light"]
200
216
 
201
217
 
202
218
  class RGBWWLightCommands(Commands):
@@ -206,6 +222,8 @@ class RGBWWLightCommands(Commands):
206
222
  # Floor Lamp
207
223
  # Strip Light 3
208
224
  # Color Bulb
225
+ # RGBICWW Floor Lamp
226
+ # RGBICWW Strip Light
209
227
  SET_BRIGHTNESS = "setBrightness"
210
228
  SET_COLOR = "setColor"
211
229
  SET_COLOR_TEMPERATURE = "setColorTemperature"
@@ -213,7 +231,39 @@ class RGBWWLightCommands(Commands):
213
231
  @classmethod
214
232
  def get_supported_devices(cls) -> list[str]:
215
233
  """Get supported devices."""
216
- return ["Strip Light 3", "Floor Lamp", "Color Bulb"]
234
+ return [
235
+ "Strip Light 3",
236
+ "Floor Lamp",
237
+ "Color Bulb",
238
+ "RGBICWW Floor Lamp",
239
+ "RGBICWW Strip Light",
240
+ ]
241
+
242
+
243
+ class CeilingLightCommands(Commands):
244
+ """Ceiling light commands."""
245
+
246
+ # 1-100
247
+ SET_BRIGHTNESS = "setBrightness"
248
+ # 2700-6500
249
+ SET_COLOR_TEMPERATURE = "setColorTemperature"
250
+
251
+ @classmethod
252
+ def get_supported_devices(cls) -> list[str]:
253
+ """Get supported devices."""
254
+ return ["Ceiling Light", "Ceiling Light Pro"]
255
+
256
+
257
+ class ArtFrameCommands(Commands):
258
+ """AI Art Frame commands."""
259
+
260
+ PREVIOUS = "previous"
261
+ NEXT = "next"
262
+
263
+ @classmethod
264
+ def get_supported_devices(cls) -> list[str]:
265
+ """Get supported devices."""
266
+ return ["AI Art Frame"]
217
267
 
218
268
 
219
269
  class DoorBellCommands(Commands):
@@ -285,20 +335,6 @@ class VacuumCleanerV3Commands(Commands):
285
335
  return ["Robot Vacuum Cleaner S10", "S20"]
286
336
 
287
337
 
288
- class CeilingLightCommands(Commands):
289
- """Ceiling light commands."""
290
-
291
- # 1-100
292
- SET_BRIGHTNESS = "setBrightness"
293
- # 2700-6500
294
- SET_COLOR_TEMPERATURE = "setColorTemperature"
295
-
296
- @classmethod
297
- def get_supported_devices(cls) -> list[str]:
298
- """Get supported devices."""
299
- return ["Ceiling Light", "Ceiling Light Pro"]
300
-
301
-
302
338
  class BlindTiltCommands(Commands):
303
339
  """Blind Tilt commands."""
304
340
 
@@ -396,4 +432,16 @@ class SmartRadiatorThermostatCommands(Commands):
396
432
  return ["Smart Radiator Thermostat"]
397
433
 
398
434
 
435
+ class KeyPadCommands(Commands):
436
+ """Keypad commands."""
437
+
438
+ DELETE_KEY = "deleteKey"
439
+ CREATE_KEY = "createKey"
440
+
441
+ @classmethod
442
+ def get_supported_devices(cls) -> list[str]:
443
+ """Get supported devices."""
444
+ return ["Keypad", "Keypad Touch", "Keypad Vision", "Keypad Vision pro"]
445
+
446
+
399
447
  T = TypeVar("T", bound=CommonCommands)
@@ -15,3 +15,7 @@ class SwitchBotAuthenticationError(SwitchBotError):
15
15
 
16
16
  class SwitchBotDeviceOfflineError(SwitchBotError):
17
17
  """Device currently offline."""
18
+
19
+
20
+ class SwitchBotDeviceRequestError(SwitchBotError):
21
+ """Device request error."""
@@ -68,3 +68,26 @@ class SmartRadiatorThermostatMode(Enum):
68
68
  cls.COMFORT,
69
69
  cls.FAST_HEATING,
70
70
  ]
71
+
72
+
73
+ class BatteryLevel(Enum):
74
+ """Battery Level modes."""
75
+
76
+ High = "high"
77
+ Medium = "medium"
78
+ Low = "low"
79
+ Critical = "critical"
80
+ Unknown = "unknown"
81
+
82
+ @classmethod
83
+ def get_battery_level(cls, value: int) -> BatteryLevel:
84
+ """Return a battery level."""
85
+ if 100 >= value >= 60:
86
+ return cls.High
87
+ if 60 > value >= 20:
88
+ return cls.Medium
89
+ if 20 > value >= 10:
90
+ return cls.Low
91
+ if 10 > value >= 0:
92
+ return cls.Critical
93
+ return cls.Unknown
@@ -0,0 +1,28 @@
1
+ """util for SwitchBot API."""
2
+
3
+ import aiohttp
4
+ from aiohttp import ClientResponse
5
+
6
+ from .exceptions import SwitchBotDeviceRequestError
7
+
8
+
9
+ def check_response_status(response: ClientResponse) -> None:
10
+ """Check https response status."""
11
+ if response.status != 200:
12
+ msg = f"status code != 200 (actual: {response.status})"
13
+ raise SwitchBotDeviceRequestError(msg)
14
+
15
+
16
+ async def get_file_stream_from_cloud(url: str, timeout: float = 5) -> bytes:
17
+ """Get file stream from cloud."""
18
+ # now only for download <AI Art Frame> Picture
19
+ try:
20
+ async with (
21
+ aiohttp.ClientSession() as session,
22
+ session.get(url, timeout=aiohttp.ClientTimeout(total=timeout)) as response,
23
+ ):
24
+ check_response_status(response)
25
+ return await response.read()
26
+ except Exception as e:
27
+ msg = f"{e}"
28
+ raise SwitchBotDeviceRequestError(msg) from e
File without changes
File without changes