一个somfy开放的api库

pymf的Python项目详细描述


这个库试图在python 3中实现整个somfy api。 somfy api的文档可以在here中找到。

获取开发人员凭据

  1. visthttps://developer.somfy.com
  2. 创建帐户
  3. 打开my apps菜单
  4. 添加新应用程序(用于测试,重定向URL可以是https中的任何内容)
  5. 在下面的测试脚本中插入您的详细信息。

支持的设备

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)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
实现接口方法时不允许java@Override   使用BuffereImage加载映像时java高ram使用率   java For循环混乱,为什么不是循环?   java Android网格视图字符串对齐问题   java如何将方法与比较类型的附加功能进行比较?   在Java Swing中放置JSepator后的间隙大小   java如何避免并发访问我的网站中的支付链接   java如何从现有的Unix服务器连接到FTP服务器?   Spring中的java用户相关bean定义   带有scribesjava库的wordpress Woocommerce REST API返回消费者密钥参数缺失错误消息   java我可以自动检测特定设备连接的串行端口吗?   Javafx棋盘游戏   java使用JTextPane显示HTML,支持SVG吗?   SpringBoot如何在java中将映射转换为实体对象?   如何使用java代码对xls文件进行密码保护   Java JPA(EclipseLink)如何在持久化实际实体之前接收下一个生成的值?   Javaservlet启动外部进程