switchbot-api 1.3.0__tar.gz → 2.1.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.
- {switchbot_api-1.3.0 → switchbot_api-2.1.0}/PKG-INFO +1 -1
- {switchbot_api-1.3.0 → switchbot_api-2.1.0}/pyproject.toml +2 -2
- {switchbot_api-1.3.0 → switchbot_api-2.1.0}/switchbot_api/__init__.py +37 -3
- {switchbot_api-1.3.0 → switchbot_api-2.1.0}/LICENSE +0 -0
- {switchbot_api-1.3.0 → switchbot_api-2.1.0}/README.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "switchbot_api"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "2.1.0"
|
|
4
4
|
description = "An asynchronous library to use Switchbot API"
|
|
5
5
|
authors = ["Ravaka Razafimanantsoa <contact@ravaka.dev>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -16,7 +16,7 @@ aiohttp = "^3.8.4"
|
|
|
16
16
|
[tool.poetry.group.dev.dependencies]
|
|
17
17
|
pytest = "^7.2.2"
|
|
18
18
|
flake8 = "^6.0.0"
|
|
19
|
-
black = "
|
|
19
|
+
black = ">=23.1,<25.0"
|
|
20
20
|
coverage = "^7.2.1"
|
|
21
21
|
parameterized = "^0.8.1"
|
|
22
22
|
isort = "^5.12.0"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Tools to query the SwitchBot API."""
|
|
2
|
+
|
|
2
3
|
import base64
|
|
3
4
|
from dataclasses import dataclass
|
|
4
5
|
from enum import Enum
|
|
@@ -25,6 +26,10 @@ class InvalidAuth(Exception):
|
|
|
25
26
|
"""Invalid auth for the SwitchBot API."""
|
|
26
27
|
|
|
27
28
|
|
|
29
|
+
class DeviceOffline(Exception):
|
|
30
|
+
"""Device currently offline."""
|
|
31
|
+
|
|
32
|
+
|
|
28
33
|
@dataclass
|
|
29
34
|
class Device:
|
|
30
35
|
"""Device."""
|
|
@@ -142,6 +147,22 @@ class LightCommands(Commands):
|
|
|
142
147
|
BRIGHTNESS_DOWN = "brightnessDown"
|
|
143
148
|
|
|
144
149
|
|
|
150
|
+
class LockCommands(Commands):
|
|
151
|
+
"""Lock commands"""
|
|
152
|
+
|
|
153
|
+
LOCK = "lock"
|
|
154
|
+
UNLOCK = "unlock"
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class CeilingLightCommands(Commands):
|
|
158
|
+
"""Ceiling light commands."""
|
|
159
|
+
|
|
160
|
+
# 1-100
|
|
161
|
+
SET_BRIGHTNESS = "setBrightness"
|
|
162
|
+
# 2700-6500
|
|
163
|
+
SET_COLOR_TEMPERATURE = "setColorTemperature"
|
|
164
|
+
|
|
165
|
+
|
|
145
166
|
class VacuumCommands(Commands):
|
|
146
167
|
"""Vacuum commands."""
|
|
147
168
|
|
|
@@ -189,11 +210,24 @@ class SwitchBotAPI:
|
|
|
189
210
|
) as response:
|
|
190
211
|
if response.status == 403:
|
|
191
212
|
raise InvalidAuth()
|
|
213
|
+
|
|
192
214
|
body = await response.json()
|
|
193
|
-
|
|
194
|
-
|
|
215
|
+
|
|
216
|
+
if response.status >= 400:
|
|
195
217
|
raise CannotConnect()
|
|
196
|
-
|
|
218
|
+
|
|
219
|
+
match body.get("statusCode"):
|
|
220
|
+
case 100:
|
|
221
|
+
return body.get("body")
|
|
222
|
+
case 161 | 171:
|
|
223
|
+
# SwitchBot docs claim that 161 is the code for device
|
|
224
|
+
# being offline, and 171 for a _hub_ being offline.
|
|
225
|
+
# In testing, the Plug Mini (JP) return 171 when not
|
|
226
|
+
# online too.
|
|
227
|
+
raise DeviceOffline()
|
|
228
|
+
case _:
|
|
229
|
+
_LOGGER.error("Error %s: %s", response.status, body)
|
|
230
|
+
raise CannotConnect()
|
|
197
231
|
|
|
198
232
|
async def list_devices(self):
|
|
199
233
|
"""List devices."""
|
|
File without changes
|
|
File without changes
|