一个somfy开放的api库
pymf的Python项目详细描述
这个库试图在python 3中实现整个somfy api。 somfy api的文档可以在here中找到。
获取开发人员凭据
- visthttps://developer.somfy.com
- 创建帐户
- 打开my apps菜单
- 添加新应用程序(用于测试,重定向URL可以是https中的任何内容)
- 在下面的测试脚本中插入您的详细信息。
支持的设备
somfy当前公开以下类型的设备:
如果您在这个page设备上发现此设备尚未处理 资源库,不要犹豫打开一个问题。
示例用法
打印所有封面名称。
importosimportjsonfromurllib.parseimporturlparse,parse_qsfrompymfy.api.devices.roller_shutterimportRollerShutterfrompymfy.api.somfy_apiimportSomfyApifrompymfy.api.devices.categoryimportCategoryclient_id=r'<CLIENT_ID>'# Consumer Keyredir_url='<REDIR_URL>'# Callback URL (for testing, can be anything)secret=r'<secret>'# Consumer Secretdefget_token():try:withopen(cache_path,'r')ascache:returnjson.loads(cache.read())exceptIOError:passdefset_token(token)->None:withopen(cache_path,'w')ascache:cache.write(json.dumps(token))cache_path='/optional/cache/path'api=SomfyApi(client_id,secret,redir_url,token=get_token(),token_updater=set_token)ifnotos.path.isfile(cache_path):authorization_url,_=api.get_authorization_url()print('Please go to {} and authorize access.'.format(authorization_url))authorization_response=input('Enter the full callback URL')code=parse_qs(urlparse(authorization_response).query)['code'][0]set_token(api.request_token(code=code))devices=api.get_devices(category=Category.ROLLER_SHUTTER)covers=[RollerShutter(d,api)fordindevices]forcoverincovers:print("Cover {} has the following position: {}".format(cover.device.name,cover.get_position()))
贡献
当前的documentation没有提供足够的信息来实现所有设备。 如果您想参与此存储库添加新设备,可以使用此脚本的输出创建问题:
importjsonimportrefromurllib.parseimporturlparse,parse_qsclient_id=r'<CLIENT_ID>'# Consumer Keyredir_url='<REDIR_URL>'# Callback URL (for testing, can be anything)secret=r'<secret>'# Consumer Secretfrompymfy.api.somfy_apiimportSomfyApiapi=SomfyApi(client_id,secret,redir_url)authorization_url,_=api.get_authorization_url()print('Please go to {} and authorize access.'.format(authorization_url))authorization_response=input('Enter the full callback URL')code=parse_qs(urlparse(authorization_response).query)['code'][0]api.request_token(code=code)devices=api.get_devices()# Remove personal informationdumps=json.dumps(devices,sort_keys=True,indent=4,separators=(',',': '))dumps=re.sub('".*id.*": ".*",\n','',dumps)print(dumps)