switchbot-api 1.0.1__tar.gz → 1.2.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.0.1 → switchbot_api-1.2.0}/PKG-INFO +17 -2
- {switchbot_api-1.0.1 → switchbot_api-1.2.0}/README.md +15 -0
- {switchbot_api-1.0.1 → switchbot_api-1.2.0}/pyproject.toml +1 -1
- {switchbot_api-1.0.1 → switchbot_api-1.2.0}/switchbot_api/__init__.py +26 -15
- switchbot_api-1.0.1/setup.py +0 -30
- {switchbot_api-1.0.1 → switchbot_api-1.2.0}/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
|
-
Name:
|
|
3
|
-
Version: 1.0
|
|
2
|
+
Name: switchbot_api
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: An asynchronous library to use Switchbot API
|
|
5
5
|
Home-page: https://github.com/SeraphicCorp/py-switchbot-api
|
|
6
6
|
License: MIT
|
|
@@ -29,3 +29,18 @@ print(await client.list_devices())
|
|
|
29
29
|
print(await client.get_status('some-id'))
|
|
30
30
|
await client.send_command('some-id', {COMMAND})
|
|
31
31
|
```
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
### Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
poetry install
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Lint
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
poetry run black switchbot_api/
|
|
45
|
+
poetry run mypy switchbot_api/
|
|
46
|
+
```
|
|
@@ -11,4 +11,19 @@ client = SwitchBotAPI(token, secret)
|
|
|
11
11
|
print(await client.list_devices())
|
|
12
12
|
print(await client.get_status('some-id'))
|
|
13
13
|
await client.send_command('some-id', {COMMAND})
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Development
|
|
17
|
+
|
|
18
|
+
### Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
poetry install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Lint
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
poetry run black switchbot_api/
|
|
28
|
+
poetry run mypy switchbot_api/
|
|
14
29
|
```
|
|
@@ -6,6 +6,7 @@ import hashlib
|
|
|
6
6
|
import hmac
|
|
7
7
|
import logging
|
|
8
8
|
import time
|
|
9
|
+
from typing import TypeVar
|
|
9
10
|
import uuid
|
|
10
11
|
|
|
11
12
|
from aiohttp import ClientSession
|
|
@@ -13,7 +14,6 @@ from aiohttp import ClientSession
|
|
|
13
14
|
_API_HOST = "https://api.switch-bot.com"
|
|
14
15
|
|
|
15
16
|
_LOGGER = logging.getLogger(__name__)
|
|
16
|
-
OBSERVED_DEVICE_TYPES = ["Remote", "Plug", "Plug Mini (US)", "Plug Mini (JP)"]
|
|
17
17
|
NON_OBSERVED_REMOTE_TYPES = ["Others"]
|
|
18
18
|
|
|
19
19
|
|
|
@@ -66,26 +66,36 @@ class PowerState(Enum):
|
|
|
66
66
|
OFF = "off"
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
class
|
|
69
|
+
class Commands(Enum):
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class CommonCommands(Commands):
|
|
70
74
|
"""Common commands."""
|
|
71
75
|
|
|
72
76
|
ON = "turnOn"
|
|
73
77
|
OFF = "turnOff"
|
|
74
78
|
|
|
75
79
|
|
|
76
|
-
class OthersCommands(
|
|
80
|
+
class OthersCommands(Commands):
|
|
77
81
|
"""Others commands."""
|
|
78
82
|
|
|
79
83
|
CUSTOMIZE = "customize" # Command {user-defined button name}
|
|
80
84
|
|
|
81
85
|
|
|
82
|
-
class AirConditionerCommands(
|
|
83
|
-
"""
|
|
86
|
+
class AirConditionerCommands(Commands):
|
|
87
|
+
"""Air conditioner commands."""
|
|
84
88
|
|
|
85
89
|
SET_ALL = "setAll" # parameter: {temperature},{mode},{fan speed},{power state}
|
|
86
90
|
|
|
87
91
|
|
|
88
|
-
class
|
|
92
|
+
class HumidifierCommands(Commands):
|
|
93
|
+
"""Humidifier commands."""
|
|
94
|
+
|
|
95
|
+
SET_MODE = "setMode" # parameter: auto, set to Auto Mode, 101, set atomization efficiency to 34%,102, set atomization efficiency to 67%, 103, set atomization efficiency to 100%
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class TVCommands(Commands):
|
|
89
99
|
"""TV commands."""
|
|
90
100
|
|
|
91
101
|
SET_CHANNEL = "SetChannel"
|
|
@@ -95,7 +105,7 @@ class TVCommands(Enum):
|
|
|
95
105
|
CHANNEL_SUB = "channelSub"
|
|
96
106
|
|
|
97
107
|
|
|
98
|
-
class DVDCommands(
|
|
108
|
+
class DVDCommands(Commands):
|
|
99
109
|
"""DVD commands."""
|
|
100
110
|
|
|
101
111
|
SET_MUTE = "setMute"
|
|
@@ -108,14 +118,14 @@ class DVDCommands(Enum):
|
|
|
108
118
|
STOP = "Stop"
|
|
109
119
|
|
|
110
120
|
|
|
111
|
-
class SpeakerCommands(
|
|
121
|
+
class SpeakerCommands(Commands):
|
|
112
122
|
"""Speaker commands."""
|
|
113
123
|
|
|
114
124
|
VOLUME_ADD = "volumeAdd"
|
|
115
125
|
VOLUME_SUB = "volumeSub"
|
|
116
126
|
|
|
117
127
|
|
|
118
|
-
class FanCommands(
|
|
128
|
+
class FanCommands(Commands):
|
|
119
129
|
"""Fan commands."""
|
|
120
130
|
|
|
121
131
|
SWING = "swing"
|
|
@@ -125,13 +135,16 @@ class FanCommands(Enum):
|
|
|
125
135
|
HIGH_SPEED = "highSpeed"
|
|
126
136
|
|
|
127
137
|
|
|
128
|
-
class LightCommands(
|
|
138
|
+
class LightCommands(Commands):
|
|
129
139
|
"""Light commands."""
|
|
130
140
|
|
|
131
141
|
BRIGHTNESS_UP = "brightnessUp"
|
|
132
142
|
BRIGHTNESS_DOWN = "brightnessDown"
|
|
133
143
|
|
|
134
144
|
|
|
145
|
+
T = TypeVar("T", bound=CommonCommands)
|
|
146
|
+
|
|
147
|
+
|
|
135
148
|
class SwitchBotAPI:
|
|
136
149
|
"""SwitchBot API."""
|
|
137
150
|
|
|
@@ -177,9 +190,7 @@ class SwitchBotAPI:
|
|
|
177
190
|
"""List devices."""
|
|
178
191
|
body = await self._request_device("")
|
|
179
192
|
_LOGGER.debug("Devices: %s", body)
|
|
180
|
-
devices = [
|
|
181
|
-
Device(**device) for device in body.get("deviceList") if device.get("deviceType") in OBSERVED_DEVICE_TYPES
|
|
182
|
-
]
|
|
193
|
+
devices = [Device(**device) for device in body.get("deviceList")]
|
|
183
194
|
remotes = [
|
|
184
195
|
Remote(**remote)
|
|
185
196
|
for remote in body.get("infraredRemoteList")
|
|
@@ -195,7 +206,7 @@ class SwitchBotAPI:
|
|
|
195
206
|
async def send_command(
|
|
196
207
|
self,
|
|
197
208
|
device_id: str,
|
|
198
|
-
command:
|
|
209
|
+
command: T,
|
|
199
210
|
command_type: str = "command",
|
|
200
211
|
parameters: dict | str = "default",
|
|
201
212
|
):
|
|
@@ -203,7 +214,7 @@ class SwitchBotAPI:
|
|
|
203
214
|
|
|
204
215
|
Args:
|
|
205
216
|
device_id (str): The ID of the device.
|
|
206
|
-
command (CommonCommands): The command to be sent.
|
|
217
|
+
command (extends CommonCommands): The command to be sent.
|
|
207
218
|
command_type (str, optional): The type of the command. Defaults to "command".
|
|
208
219
|
parameters (dict | str, optional): The parameters for the command. Defaults to "default".
|
|
209
220
|
|
switchbot_api-1.0.1/setup.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
packages = \
|
|
5
|
-
['switchbot_api']
|
|
6
|
-
|
|
7
|
-
package_data = \
|
|
8
|
-
{'': ['*']}
|
|
9
|
-
|
|
10
|
-
install_requires = \
|
|
11
|
-
['aiohttp>=3.8.4,<4.0.0']
|
|
12
|
-
|
|
13
|
-
setup_kwargs = {
|
|
14
|
-
'name': 'switchbot-api',
|
|
15
|
-
'version': '1.0.1',
|
|
16
|
-
'description': 'An asynchronous library to use Switchbot API',
|
|
17
|
-
'long_description': '# py-switchbot-api\nAn asynchronous library to use Switchbot API. Allows to use both devices and remotes.\n\n## Usage\n\n```python\ntoken = "xxx"\nsecret = "yyy"\n\nclient = SwitchBotAPI(token, secret)\nprint(await client.list_devices())\nprint(await client.get_status(\'some-id\'))\nawait client.send_command(\'some-id\', {COMMAND})\n```',
|
|
18
|
-
'author': 'Ravaka Razafimanantsoa',
|
|
19
|
-
'author_email': 'contact@ravaka.dev',
|
|
20
|
-
'maintainer': 'None',
|
|
21
|
-
'maintainer_email': 'None',
|
|
22
|
-
'url': 'https://github.com/SeraphicCorp/py-switchbot-api',
|
|
23
|
-
'packages': packages,
|
|
24
|
-
'package_data': package_data,
|
|
25
|
-
'install_requires': install_requires,
|
|
26
|
-
'python_requires': '>=3.10,<4.0',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
setup(**setup_kwargs)
|
|
File without changes
|