Netatmo的客户端库
netatmo-client的Python项目详细描述
安装
到目前为止,唯一的来源是安装它的方式:
来源
构建库运行:
$ python setup.py install
如何使用
首先,您必须声明自己的own应用程序,并获取client id和client secret。
构建实例
fromnetatmo_client.clientimportNetatmoClientscopes=('read_station','read_thermostat','write_thermostat','read_camera')client_id='client id'client_secret='client secret'client=NetatmoClient(client_id,client_secret)
获取代币
库提供了两种记录客户机的方法
授权代码处理
假设您在netatmo站点上将http://somewhere.org/callback/grant/code声明为重定向uri, 您可以使用下面这样的代码使用授权代码方式获取令牌。
client=NetatmoClient('client-id','client-secret')scopes=('read_station','read_thermostat','write_thermostat','read_camera')redirect_uri='http://somewhere.org/callback/grant/code'grant_url=client.generate_auth_url(redirect_uri,'state-test',*scopes)sys.stdout\ .write("Open the following url ( %s ), follow the steps and enter the code you will see in the navigation bar: "%grant_url)code=sys.stdin.readline()code=code.rstrip('\r\n')client.request_token_with_code(code,redirect_uri,*scopes)# use the apiprintjson.dumps(client.station.get_station_data())
用户将进入授权代码流程并返回到您的站点 一个url,如http://somewhere.org/callback/grant/code?code=<yourcode>&state=state-test。 然后,您的web服务器通常处理get请求,并使用与上面相同的redirect uri交换代码。
客户端凭据
您也可以按如下方式选择此过程:
client=NetatmoClient('client-id','client-secret')scopes=('read_station','read_thermostat','write_thermostat','read_camera')client.request_token_with_client_credentials('username','password',*scopes)# use the apiprintjson.dumps(client.thermostat.get_thermostat_data())
api调用
客户定义了三个部分:
- common:
- get_measure
- public:
- get_public_data
- station:
- get_station_data
- thermostat:
- get_thermostat_data
- create_new_schedule
- set_therm_point
- switch_schedule
- sync_schedule
- welcome
- get_camera_picture
- get_events_until
- get_next_events
- get_home_data
- get_last_event_of
- add_webhook
- drop_webhook
- ping
问题和贡献
请提交问题/请求。