用于与使用asyncio和aiohttp构建的smartthings云api交互的python库。

pysmartthings的Python项目详细描述


pysmartthings

Build StatusCoverage Statusimageimageimageimage

用于与使用asyncioaiohttp构建的SmartThings云API交互的Python库。

功能

该软件包仍处于测试阶段,但提供以下功能:

  1. 地点:列表,获取
  2. 房间:列出、获取、创建、更新、删除
  3. 设备:列表、获取、命令、状态
  4. 应用程序:list、get、create、update、delete、settings get&update、oauth:get、update和generate
  5. 安装应用程序:列出、获取、删除
  6. 订阅:列出、获取、创建、删除、全部删除
  7. 场景:列表,执行
  8. OAuth:生成刷新/访问令牌对

安装

pip install pysmartthings

pip install --use-wheel pysmartthings

用法

初始化

smartthings类封装了api操作,构造函数接受aiohttpWebSession和您的personal access token

import aiohttp
import pysmartthings

token = 'PERSONAL_ACCESS_TOKEN'

async with aiohttp.ClientSession() as session:
    api = pysmartthings.SmartThings(session, token)
    # ...

位置

可以通过调用协同路由locations()来检索SmartThings中的位置列表。

    locations = await api.locations()
    print(len(locations))

    location = locations[0]
    print(location.name)
    print(location.location_id) 

输出:

2
'Test Home'
'5c03e518-118a-44cb-85ad-7877d0b302e4'

设备

可以通过调用协同路由devices(location_ids=None, capabilities=None, device_ids=None)来检索设备列表。可选参数允许筛选返回的列表。

    devices = await api.devices()
    print(len(devices))

    device = devices[0]
    print(device.device_id)
    print(device.name)
    print(device.label)
    print(device.capabilities)

输出:

19
'0d38d5ca-705f-44f7-89bd-36a8cf73678d'
'GE In-Wall Smart Dimmer'
'Back Patio Light'
['switch', 'switchLevel', 'refresh', 'indicator', 'button', 'sensor', 'actuator', 'healthCheck', 'light']

当调用协程status.refresh()时,将填充设备的当前状态。devicestatus类表示功能的当前值,并提供几个规范化的属性访问器。

    await device.status.refresh()    
    print(device.status.values)
    print(device.status.switch)
    print(device.status.level)

输出:

{'button': 'pressed', 'numberOfButtons': None, 'supportedButtonValues': None, 'indicatorStatus': 'when off', 'switch': 'on', 'checkInterval': 1920, 'healthStatus': None, 'DeviceWatch-DeviceStatus': None, 'level': 100}
True
100

设备命令

可以通过调用coroutinecommand(capability, command, args=None)函数在设备上执行命令。capability参数对应于检测到的功能之一,command是define命令之一。args是要传递给命令的参数数组(可选)。有关详细信息,请参见SmartThings Capability Reference

    result = await device.command("switch", "on")
    assert result == True

    result = await device.command("switchLevel", "setLevel", [75, 2])
    assert result == True

具有switch功能的设备具有以下协同程序:

    result = await device.switch_on()
    assert result == True

    result = await device.switch_off()
    assert result == True

具有switchLevel功能的设备具有以下功能,可以使用特定的持续时间(秒)设置目标亮度级别和转换。

    result = await device.set_level(75, 2)
    assert result == True

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

推荐PyPI第三方库


热门话题
java我需要在一个数组中添加1000个介于1和100之间的整数及其出现次数,然后显示它们   如何在java中将两个不同的excel文件作为数据库连接到同一台服务器上?   java JSP编译错误令牌“throws”语法错误,应为throw   java如何使用Jetty HTTP客户端和MultiPartContentProvider上载BuffereImage?   具有多个方法对象的java测试类   在java中比较字符串和打印剩余字符时出现意外输出?   java设置JPanel的大小,当其中没有组件时   使用exoplayer播放m3u8文件的java   JSON中未添加Jackson@type的java Rest JSON   java如何为heroku创建procfile文件?   基于数组的java信息存储   sockets java。网SocketTimeoutException:在Tomcat下读取超时   安卓x的java问题。偏爱安卓工作室   java我的方法没有按预期运行   java如何通过单击单选按钮将值从表传递到servlet?   java无法获取instagram个人资料图片的完整大小