Package: nature-remo
Python Client for Nature Remo APIIntroductionnature-remois a Python client for theNature Remo API.Installation$pipinstallnature-remoUsageTo create an instance ofremo.NatureRemoAPIwith 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.528809To 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 ofremo.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 underlyingurllib3debug 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')CLInature-remohas the command line interface as well.
To invoke the command, typeremoon the command line:$remo
Usage:remo[OPTIONS]COMMAND[ARGS]...

Options:--helpShowthismessageandexit.

Commands:appliancedevicelocalsignaluserTheremocommand consists of five subcommands, which represent the object you interact with.
For example, thedevicesubcommand can be used to interact with the Nature Remo devices associated with your account.
Enterremo deviceon the command line to see what actions thedevicesubcommands supports:$remodevice
Usage:remodevice[OPTIONS]COMMAND[ARGS]...

Options:--helpShowthismessageandexit.

Commands:deleteDeleteRemo.getFetchthelistofRemodevicestheuserhas...updateUpdateRemo.update_humidity_offsetUpdatehumidityoffset.update_temperature_offsetUpdatetemperatureoffset.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:$remodeviceget--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>
$remodeviceget[{"created_at":"2020-07-23T03:10:21+00:00",...}]Use the--debugflag to inspect the details about the HTTP connection:$remouserupdatefoo--debug
DEBUG:urllib3.connectionpool:StartingnewHTTPSconnection(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,31Jul202007:26:52GMT
header:Content-Type:application/json;charset=utf-8
header:Content-Length:62header:Connection:keep-alive
header:Access-Control-Allow-Origin:*
header:Cache-Control:no-cache,no-store,must-revalidate,private,max-age=0header:Expires:Thu,01Jan197000:00:00UTC
header:Pragma:no-cache
header:Strict-Transport-Security:max-age=86400header:Vary:Accept-Encoding
header:X-Accel-Expires:0header:X-Content-Type-Options:nosniff
header:X-Frame-Options:SAMEORIGIN
header:X-Rate-Limit-Limit:30header:X-Rate-Limit-Remaining:21header:X-Rate-Limit-Reset:1596180600header: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, thoseremo <subcommand> <action> (<args>)commands are mapped to the Nature Remo API.
The full list of those mappings is as follows:CommandNature Remo APIremo user getGET /1/users/meremo user updatePOST /1/users/meremo device getGET /1/devicesremo device updatePOST /1/devices/{device}remo device deletePOST /1/devices/{device}/deleteremo device update_temperature_offsetPOST /1/devices/{device}/temperature_offsetremo device update_humidity_offsetPOST /1/devices/{device}/humidity_offsetremo appliance detectPOST /1/detectapplianceremo appliance createPOST /1/appliancesremo appliance getGET /1/appliancesremo appliance updatePOST /1/appliances/{appliance}remo appliance deletePOST /1/appliances/{appliance}/deleteremo appliance update_ordersPOST /1/appliance_ordersremo appliance update_aircon_settingsPOST /1/appliances/{appliance}/aircon_settingsremo appliance send_tv_infrared_signalPOST /1/appliances/{appliance}/tvremo appliance send_light_infrared_signalPOST /1/appliances/{appliance}/lightremo signal create/1/appliances/{appliance}/signalsremo signal getGET /1/appliances/{appliance}/signalsremo signal updatePOST /1/signals/{signal}remo signal delete/1/signals/{signal}/deleteremo signal send/1/signals/{signal}/sendremo signal update_orders/1/appliances/{appliance}/signal_ordersDevelopment StatusCloud API(Base URL:api.nature.global/)StatusHTTP MethodEndpointAPI⚡️GET/1/users/meget_user⚡️POST/1/users/meupdate_user⚡️GET/1/devicesget_devices️⚡️POST/1/detectappliancedetect_appliance⚡️GET/1/appliancesget_appliances⚡POST/1/appliancescreate_appliance⚡️POST/1/appliance_ordersupdate_appliance_orders⚡POST/1/appliances/{appliance}/deletedelete_appliance⚡️POST/1/appliances/{appliance}update_appliance⚡POST/1/appliances/{appliance}/aircon_settingsupdate_aircon_settings⚡️POST/1/appliances/{appliance}/tvsend_tv_infrared_signal️⚡POST/1/appliances/{appliance}/lightsend_light_infrared_signal⚡️GET/1/appliances/{appliance}/signalsget_signals⚡POST/1/appliances/{appliance}/signalscreate_signal⚡POST/1/appliances/{appliance}/signal_ordersupdate_signal_orders⚡POST/1/signals/{signal}update_signal⚡POST/1/signals/{signal}/deletedelete_signal⚡POST/1/signals/{signal}/sendsend_signal⚡️POST/1/devices/{device}update_device⚡️POST/1/devices/{device}/deletedelete_device⚡️POST/1/devices/{device}/temperature_offsetupdate_temperature_offset⚡️POST/1/devices/{device}/humidity_offsetupdate_humidity_offsetLocal API(Base URL:remo.local/)StatusHTTP MethodEndpointAPI⚡️GET/messagesget_ir_signal⚡️POST/messagessend_ir_signalHow to Develop$gitclonegit@github.com:morinokami/nature-remo.git
$cdnature-remo
$pipenvsync--dev
$pipenvshell
$pre-commitinstallはじめにnature-remoは、Nature Remo APIの Python クライアントです。インストール$pipinstallnature-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")現在の呼び出し制限 (Rate Limit) を確認する:>>>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))remo.NatureRemoLocalAPIのインスタンスを作成する:>>>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)urllib3のデバッグ情報を出力する:>>>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')CLInature-remoにはコマンドラインインターフェイスもあります。
コマンドを実行するには、コマンドラインでremoと入力してください:$remo
Usage:remo[OPTIONS]COMMAND[ARGS]...

Options:--helpShowthismessageandexit.

Commands:appliancedevicelocalsignaluserremoコマンドは五つのサブコマンドから成り、それぞれが操作の対象を表わしています。
たとえば、deviceサブコマンドは、あなたのアカウントに紐付いている Nature Remo の機器に対する操作を可能とします。
コマンドライン上でremo deviceと入力し、deviceがサポートしている操作を確認してみましょう:$remodevice
Usage:remodevice[OPTIONS]COMMAND[ARGS]...

Options:--helpShowthismessageandexit.

Commands:deleteDeleteRemo.getFetchthelistofRemodevicestheuserhas...updateUpdateRemo.update_humidity_offsetUpdatehumidityoffset.update_temperature_offsetUpdatetemperatureoffset.このサブコマンドは五つの操作をサポートしていることがわかります。
これより、たとえばあなたのアカウントに紐付いている Remo の機器について知りたければ、次のコマンドを実行してください:$remodeviceget--token<access_token>[{"created_at":"2020-07-23T03:10:21+00:00",...}]アクセストークンは環境変数により指定することもできます:$exportREMO_ACCESS_TOKEN=<access_token>
$remodeviceget[{"created_at":"2020-07-23T03:10:21+00:00",...}]--debugフラグにより、HTTP 通信の詳細を確認することが可能です:$remouserupdatefoo--debug
DEBUG:urllib3.connectionpool:StartingnewHTTPSconnection(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,31Jul202007:26:52GMT
header:Content-Type:application/json;charset=utf-8
header:Content-Length:62header:Connection:keep-alive
header:Access-Control-Allow-Origin:*
header:Cache-Control:no-cache,no-store,must-revalidate,private,max-age=0header:Expires:Thu,01Jan197000:00:00UTC
header:Pragma:no-cache
header:Strict-Transport-Security:max-age=86400header:Vary:Accept-Encoding
header:X-Accel-Expires:0header:X-Content-Type-Options:nosniff
header:X-Frame-Options:SAMEORIGIN
header:X-Rate-Limit-Limit:30header:X-Rate-Limit-Remaining:21header:X-Rate-Limit-Reset:1596180600header: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"}内部では、こうしたremo <subcommand> <action> (<args>)コマンドは Nature Remo API へとマップされています。
マッピングのフルリストは以下の通りです:CommandNature Remo APIremo user getGET /1/users/meremo user updatePOST /1/users/meremo device getGET /1/devicesremo device updatePOST /1/devices/{device}remo device deletePOST /1/devices/{device}/deleteremo device update_temperature_offsetPOST /1/devices/{device}/temperature_offsetremo device update_humidity_offsetPOST /1/devices/{device}/humidity_offsetremo appliance detectPOST /1/detectapplianceremo appliance createPOST /1/appliancesremo appliance getGET /1/appliancesremo appliance updatePOST /1/appliances/{appliance}remo appliance deletePOST /1/appliances/{appliance}/deleteremo appliance update_ordersPOST /1/appliance_ordersremo appliance update_aircon_settingsPOST /1/appliances/{appliance}/aircon_settingsremo appliance send_tv_infrared_signalPOST /1/appliances/{appliance}/tvremo appliance send_light_infrared_signalPOST /1/appliances/{appliance}/lightremo signal create/1/appliances/{appliance}/signalsremo signal getGET /1/appliances/{appliance}/signalsremo signal updatePOST /1/signals/{signal}remo signal delete/1/signals/{signal}/deleteremo signal send/1/signals/{signal}/sendremo signal update_orders/1/appliances/{appliance}/signal_orders