Python客户端for Nature Remo API
nature-remo的Python项目详细描述
Python Client for Nature Remo API
Introduction
nature-remo
is a Python client for the Nature Remo API.
Installation
$ pip install nature-remo
Usage
To create an instance of remo.NatureRemoAPI
with your access token:
>>>fromremoimportNatureRemoAPI>>>api=NatureRemoAPI('access_token')
To fetch the authenticated user's information:
>>>user=api.get_user()>>>user.id'user_id'>>>user.nickname'your_nickname'
To fetch the list of Remo devices and print the temperature of the first device:
>>>devices=api.get_devices()>>>devices[0].newest_events['te'].val26.528809
To fetch the list of appliances:
>>>appliances=api.get_appliances()>>>appliances[0].id'appliance_id'>>>appliances[0].type'AC'
To update air conditioner settings:
>>>aircon=appliances[0]>>>api.update_aircon_settings(aircon.id,'cool','27','auto','swing','')
To send a tv infrared signal:
>>>appliances[1].type'TV'>>>tv=appliances[1]>>>api.send_tv_infrared_signal(tv.id,'power')
To check the current rate limit status:
>>>api.get_user()...>>>api.rate_limitRateLimit(checked_at=datetime.datetime(2020,7,28,8,11,4),limit=30,remaining=29,reset=datetime.datetime(2020,7,28,8,15))>>>api.rate_limit.checked_at,api.rate_limit.limit,api.rate_limit.remaining,api.rate_limit.reset(datetime.datetime(2020,7,28,8,11,4),30,29,datetime.datetime(2020,7,28,8,15))
To create an instance of remo.NatureRemoLocalAPI
:
>>>fromremoimportNatureRemoLocalAPI>>>local_api=NatureRemoLocalAPI('ip_addr')
To fetch the newest received IR signal:
>>>local_api.get_ir_signal()IRSignal(freq=38,data=[0],format='us')
To emit an IR signal:
>>>message='{"format": "us", "freq": 38, "data": [0]}'>>>local_api.send_ir_signal(message)
To print the underlying urllib3
debug information:
>>>api=NatureRemoAPI('access_token',debug=True)>>>api.get_user()DEBUG:urllib3.connectionpool:StartingnewHTTPSconnection(1):api.nature.global:443send:b'GET /1/users/me HTTP/1.1\r\nHost: api.nature.global\r\nUser-Agent: nature-remo/0.1.0 (https://github.com/morinokami/nature-remo)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nAuthorization: Bearer access_token\r\n\r\n'reply:'HTTP/1.1 200 OK\r\n'header:Date:Mon,27Jul202015:53:12GMTheader:Content-Type:application/json;charset=utf-8header:Content-Length:72header:Connection:keep-aliveheader:Access-Control-Allow-Origin:*header:Cache-Control:no-cache,no-store,must-revalidate,private,max-age=0header:Expires:Thu,01Jan197000:00:00UTCheader:Pragma:no-cacheheader:Strict-Transport-Security:max-age=86400header:Vary:Accept-Encodingheader:X-Accel-Expires:0header:X-Content-Type-Options:nosniffheader:X-Frame-Options:SAMEORIGINheader:X-Rate-Limit-Limit:30header:X-Rate-Limit-Remaining:29header:X-Rate-Limit-Reset:1595865300header:X-Xss-Protection:1;mode=blockDEBUG:urllib3.connectionpool:https://api.nature.global:443"GET /1/users/me HTTP/1.1"20072User(id='user_id',nickname='your_nickname')
CLI
nature-remo
has the command line interface as well.
To invoke the command, type remo
on the command line:
$ remo Usage: remo [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: appliance device local signal user
The remo
command consists of five subcommands, which represent the object you interact with.
For example, the device
subcommand can be used to interact with the Nature Remo devices associated with your account.
Enter remo device
on the command line to see what actions the device
subcommands supports:
$ remo device Usage: remo device [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: delete Delete Remo. get Fetch the list of Remo devices the user has... update Update Remo. update_humidity_offset Update humidity offset. update_temperature_offset Update temperature offset.
We can see that the subcommand has five actions. Thus, for example, if you want to know about the Remo devices associated with your account, enter the following command:
$ remo device get --token <access_token> [{"created_at": "2020-07-23T03:10:21+00:00", ...}]
The access token can be specified as an environment variable:
$ exportREMO_ACCESS_TOKEN=<access_token> $ remo device get [{"created_at": "2020-07-23T03:10:21+00:00", ...}]
Use the --debug
flag to inspect the details about the HTTP connection:
$ remo user update foo --debug DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.nature.global:443 send: b'POST /1/users/me HTTP/1.1\r\nHost: api.nature.global\r\nUser-Agent: nature-remo/0.3.0 (https://github.com/morinokami/nature-remo)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nAuthorization: Bearer access_token\r\nContent-Length: 12\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n' send: b'nickname=foo' reply: 'HTTP/1.1 200 OK\r\n' header: Date: Fri, 31 Jul 202007:26:52 GMT header: Content-Type: application/json;charset=utf-8 header: Content-Length: 62 header: Connection: keep-alive header: Access-Control-Allow-Origin: * header: Cache-Control: no-cache, no-store, must-revalidate, private, max-age=0 header: Expires: Thu, 01 Jan 197000:00:00 UTC header: Pragma: no-cache header: Strict-Transport-Security: max-age=86400 header: Vary: Accept-Encoding header: X-Accel-Expires: 0 header: X-Content-Type-Options: nosniff header: X-Frame-Options: SAMEORIGIN header: X-Rate-Limit-Limit: 30 header: X-Rate-Limit-Remaining: 21 header: X-Rate-Limit-Reset: 1596180600 header: X-Xss-Protection: 1;mode=block DEBUG:urllib3.connectionpool:https://api.nature.global:443 "POST /1/users/me HTTP/1.1"20062{"id": "user_id", "nickname": "foo"}
Internally, those remo <subcommand> <action> (<args>)
commands are mapped to the Nature Remo API.
The full list of those mappings is as follows:
Command | Nature Remo API |
---|---|
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
Development Status
Cloud API (Base URL: api.nature.global/
)
Status | HTTP Method | Endpoint | API |
---|---|---|---|
⚡️ | GET | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
⚡️ | GET | ^{ | ^{ |
️⚡️ | POST | ^{ | ^{ |
⚡️ | GET | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
️⚡ | POST | ^{ | ^{ |
⚡️ | GET | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
Local API (Base URL: remo.local/
)
Status | HTTP Method | Endpoint | API |
---|---|---|---|
⚡️ | GET | ^{ | ^{ |
⚡️ | POST | ^{ | ^{ |
How to Develop
$ git clone git@github.com:morinokami/nature-remo.git
$ cd nature-remo
$ pipenv sync --dev
$ pipenv shell
$ pre-commit install
开始
^{cd1>}是Nature Remo API的Python客户端。
安装
$ pip install nature-remo
使用方法
指定访问令牌创建remo.NatureRemoAPI
实例:
>>>fromremoimportNatureRemoAPI>>>api=NatureRemoAPI('access_token')
获取认证用户信息:
>>>user=api.get_user()>>>user.id'user_id'>>>user.nickname'your_nickname'
获取Remo的设备列表并显示第一设备的温度:
>>>devices=api.get_devices()>>>devices[0].newest_events['te'].val26.528809
获取家电产品列表:
>>>appliances=api.get_appliances()>>>appliances[0].id'appliance_id'>>>appliances[0].type'AC'
更改空调设置:
>>>aircon=appliances[0]>>>api.update_aircon_settings(aircon.id,'cool','27','auto','swing','')发送电视
>>>appliances[1].type'TV'>>>tv=appliances[1]>>>api.send_tv_infrared_signal(tv.id,"power") 确认当前列表
>>>api.get_user()...>>>api.rate_limitRateLimit(checked_at=datetime.datetime(2020,7,28,8,11,4),limit=30,remaining=29,reset=datetime.datetime(2020,7,28,8,15))>>>api.rate_limit.checked_at,api.rate_limit.limit,api.rate_limit.remaining,api.rate_limit.reset(datetime.datetime(2020,7,28,8,11,4),30,29,datetime.datetime(2020,7,28,8,15))创建
^
>>>fromremoimportNatureRemoLocalAPI>>>local_api=NatureRemoLocalAPI('ip_addr')
获取接收到的最新红外信号:
>>>local_api.get_ir_signal()IRSignal(freq=38,data=[0],format='us')
发送红外:
>>>message='{"format": "us", "freq": 38, "data": [0]}'>>>local_api.send_ir_signal(message)输出
^
>>>api=NatureRemoAPI('access_token',debug=True)>>>api.get_user()DEBUG:urllib3.connectionpool:StartingnewHTTPSconnection(1):api.nature.global:443send:b'GET /1/users/me HTTP/1.1\r\nHost: api.nature.global\r\nUser-Agent: nature-remo/0.1.0 (https://github.com/morinokami/nature-remo)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nAuthorization: Bearer access_token\r\n\r\n'reply:'HTTP/1.1 200 OK\r\n'header:Date:Mon,27Jul202015:53:12GMTheader:Content-Type:application/json;charset=utf-8header:Content-Length:72header:Connection:keep-aliveheader:Access-Control-Allow-Origin:*header:Cache-Control:no-cache,no-store,must-revalidate,private,max-age=0header:Expires:Thu,01Jan197000:00:00UTCheader:Pragma:no-cacheheader:Strict-Transport-Security:max-age=86400header:Vary:Accept-Encodingheader:X-Accel-Expires:0header:X-Content-Type-Options:nosniffheader:X-Frame-Options:SAMEORIGINheader:X-Rate-Limit-Limit:30header:X-Rate-Limit-Remaining:29header:X-Rate-Limit-Reset:1595865300header:X-Xss-Protection:1;mode=blockDEBUG:urllib3.connectionpool:https://api.nature.global:443"GET /1/users/me HTTP/1.1"20072User(id='user_id',nickname='your_nickname')
CLI
^{cd1>}中也有命令行接口。
要执行命令,请在命令行中输入remo
:
$ remo Usage: remo [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: appliance device local signal user
^{cd6>}命令由五个子命令组成,分别表示操作对象。
例如,device
子命令可对与您账户相关联的Nature Remo的设备进行操作。
在命令行上输入^
$ remo device Usage: remo device [OPTIONS] COMMAND [ARGS]... Options: --help Show this message and exit. Commands: delete Delete Remo. get Fetch the list of Remo devices the user has... update Update Remo. update_humidity_offset Update humidity offset. update_temperature_offset Update temperature offset.
可以看出该子命令支持五个操作。 因此,如果您想知道例如与您的账户相关联的Remo的设备,请执行以下命令:
$ remo device get --token <access_token> [{"created_at": "2020-07-23T03:10:21+00:00", ...}]
访问令牌也可以由环境变量指定:
$ exportREMO_ACCESS_TOKEN=<access_token> $ remo device get [{"created_at": "2020-07-23T03:10:21+00:00", ...}]
^{cd11>}可以通过标志确认HTTP通信的详细信息:
$ remo user update foo --debug DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.nature.global:443 send: b'POST /1/users/me HTTP/1.1\r\nHost: api.nature.global\r\nUser-Agent: nature-remo/0.3.0 (https://github.com/morinokami/nature-remo)\r\nAccept-Encoding: gzip, deflate\r\nAccept: application/json\r\nConnection: keep-alive\r\nAuthorization: Bearer access_token\r\nContent-Length: 12\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n' send: b'nickname=foo' reply: 'HTTP/1.1 200 OK\r\n' header: Date: Fri, 31 Jul 202007:26:52 GMT header: Content-Type: application/json;charset=utf-8 header: Content-Length: 62 header: Connection: keep-alive header: Access-Control-Allow-Origin: * header: Cache-Control: no-cache, no-store, must-revalidate, private, max-age=0 header: Expires: Thu, 01 Jan 197000:00:00 UTC header: Pragma: no-cache header: Strict-Transport-Security: max-age=86400 header: Vary: Accept-Encoding header: X-Accel-Expires: 0 header: X-Content-Type-Options: nosniff header: X-Frame-Options: SAMEORIGIN header: X-Rate-Limit-Limit: 30 header: X-Rate-Limit-Remaining: 21 header: X-Rate-Limit-Reset: 1596180600 header: X-Xss-Protection: 1;mode=block DEBUG:urllib3.connectionpool:https://api.nature.global:443 "POST /1/users/me HTTP/1.1"20062{"id": "user_id", "nickname": "foo"}在
内部,这样的^
Command | Nature Remo API |
---|---|
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
^{ | ^{ |
- 项目
标签: