11# switchbot-client
22
3- An unofficial Python client implementation of the SwitchBot API.
4-
53[ ![ PyPI - Python Version] ( https://img.shields.io/pypi/pyversions/switchbot-client.svg )] ( https://pypi.org/project/switchbot-client/ )
64[ ![ PyPI - Library Version] ( https://img.shields.io/pypi/v/switchbot-client.svg )] ( https://pypi.org/project/switchbot-client/ )
75[ ![ PyPI - Downloads] ( https://img.shields.io/pypi/dm/switchbot-client )] ( https://pypi.org/project/switchbot-client )
86[ ![ License] ( https://img.shields.io/badge/license-MIT%2FApache--2.0-informational?style=flat-square )] ( README.md#License )
97[ ![ Code style: black] ( https://img.shields.io/badge/code%20style-black-000000.svg )] ( https://github.com/psf/black )
108
9+ An unofficial Python client implementation of the SwitchBot API.
1110
1211## Table of Contents
1312
@@ -37,8 +36,10 @@ python3 your_script.py
3736
3837``` python
3938# your_script.py
39+ from switchbot_client import SwitchBotAPIClient
40+
4041client = SwitchBotAPIClient()
41- result = client.devices()
42+ print ( client.devices() )
4243```
4344
4445### Constructor Arguments
@@ -50,9 +51,27 @@ from switchbot_client import SwitchBotAPIClient
5051
5152your_token = " your_switchbot_open_token"
5253client = SwitchBotAPIClient(token = your_token)
53- result = client.devices()
54+ print ( client.devices() )
5455```
5556
57+ ### Config file
58+
59+ If ` ~/.config/switchbot-client/config.yml ` exists and has a ` token ` entry,
60+ this client will automatically use the value.
61+
62+ ``` shell
63+ mkdir -p ~ /.config/switchbot-client
64+ echo " token: your_switchbot_open_token" >> ~ /.config/switchbot-client/config.yml
65+ python3 your_script.py
66+ ```
67+
68+ ``` python
69+ # your_script.py
70+ from switchbot_client import SwitchBotAPIClient
71+
72+ client = SwitchBotAPIClient()
73+ print (client.devices())
74+ ```
5675
5776## Usage
5877
@@ -101,7 +120,7 @@ from switchbot_client import SwitchBotAPIClient, ControlCommand
101120
102121client = SwitchBotAPIClient()
103122device_id = " 12345" # My Light(virtual infrared remote devices)
104- print (client.devices_control (device_id, ControlCommand.VirtualInfrared.TURN_ON ))
123+ print (client.devices_commands (device_id, ControlCommand.VirtualInfrared.TURN_ON ))
105124```
106125
107126```
@@ -127,6 +146,7 @@ SwitchBotAPIResponse(status_code=100, message='success', body=[{'sceneId': '1234
127146```
128147
129148You can get a list of all the scenes associated with your SwitchBot account.
149+ Note that only manual scenes are returned from this api.
130150
131151### Execute Scene
132152``` python
@@ -143,7 +163,7 @@ The specified scene can be executed immediately.
143163
144164### Object interface
145165
146- Devices can be manipulated via an easy-to-use object wrapped API(currently only some device types are supported) .
166+ Devices can be manipulated via an easy-to-use object wrapped API.
147167
148168``` python
149169from switchbot_client import SwitchBotAPIClient
@@ -180,7 +200,7 @@ def control_all_infrared_remotes_by_type(type: str, command: str):
180200 devices = filter (lambda d : d[" remoteType" ] == type , infrared_remotes)
181201
182202 for d in devices:
183- client.devices_control (d[" deviceId" ], command)
203+ client.devices_commands (d[" deviceId" ], command)
184204
185205
186206def call_this_function_when_i_go_out ():
0 commit comments