用于与运动百叶窗接口的Python库

motionblinds的Python项目详细描述


活动百叶窗

用于与运动百叶窗接口的Python库

此库允许您从Coulisse B.V.控制运动百叶窗。 此库主要用于与HomeAssistant一起使用,但也可以单独使用。在

有关产品,请参见https://motion-blinds.comhttps://coulisse.com/products/motion。在

出售这些百叶窗的商店:

安装

pip使用:

$ pip install motionblinds

或者

$ pip install --use-wheel motionblinds

检索密钥

motionblinds API使用一个16个字符的键,可以从IosAndroid的官方“Motion Blinds”应用程序中检索。 打开应用程序,点击右上角的3个点,进入“设置”,进入“关于运动应用程序”,请快速点击此“关于运动应用程序”页面5次,弹出窗口将弹出,为您提供按键。在

alt textalt text

请注意,提供给此库时,密钥中需要包含“-”字符。 密钥需要与“12ab345c-d67e-8f”相同

使用

要创建设备,您可以使用以下代码行(使用正确的网关IP和从应用程序检索的密钥)

from motionblinds import MotionGateway
m = MotionGateway(ip = "192.168.1.100", key = "12ab345c-d67e-8f")

此库没有轮询。因此,您需要使用GetDeviceList方法填充已连接的盲板,并使用update方法更新设备信息。 请注意,可以处理来自网关的多播推送以检索即时状态更新(请参阅多播推送部分)

^{pr2}$

注意,在使用Update之前需要运行GetDeviceList,因为设备类型、mac和令牌是使用GetDeviceList方法检索的。 使用GetDeviceList方法发现连接的百叶窗后,可以通过设备列表属性列出它们:

m.device_list

这将返回一个dict,其中键为盲人的mac_地址,值为可用于检索盲人信息和控制盲人的运动盲设备。在

一些示例代码将打印网关和所有连接的百叶窗的信息:

>>> from motionblinds import MotionGateway
>>> m = MotionGateway(ip = "192.168.1.100", key = "12ab345c-d67e-8f")
>>> m.GetDeviceList()
{'abcdefghujkl0001': <MotionBlind mac: abcdefghujkl0001, type: None, status: None, position: None %, angle: None, limit: None, battery: None, RSSI: None dBm>}
>>> m.Update()
>>> print(m)
<MotionGateway ip: 192.168.1.100, mac: abcdefghujkl, protocol: 0.9, N_devices: 1, status: Working, RSSI: -71 dBm>
>>> for blind in m.device_list.values():
>>>     blind.Update()
>>>     print(blind)
<MotionBlind mac: abcdefghujkl0001, type: RollerBlind, status: Stopped, position: 0 %, angle: 0, limit: Limits, battery: 1195, RSSI: -82 dBm>

要打开盲板,可以使用以下示例代码:

>>> from motionblinds import MotionGateway
>>> m = MotionGateway(ip = "192.168.1.100", key = "12ab345c-d67e-8f")
>>> m.GetDeviceList()
>>> m.Update()
>>> blind_1 = list(m.device_list.values())[0]
>>> blind_1.Update()
>>> blind_1.Open()

您还可以使用blind_1.Close()、blind_1.Stop()、blind_1.Set_位置(50)或blind_1.Set_angle(90)代替blind_1.Open()

多播推送

这个库允许在并行线程中监听来自网关的多播推送,并处理这些推送以获得网关和已连接盲板状态的即时更新。 要使用这种并行推送处理,需要初始化MotionMulticast类对象。 这个MotionMulticast.Start_侦听()和MotionMulticast.Stop_侦听()可用于启动和停止侦听传入推送的并行线程。 MotionMulticast类对象可以提供给MotionGateway类,让它更新该网关及其连接的盲板。 可以为网关设备和盲设备注册外部回调(见下表) 一个示例代码,用于监听推送30秒,并在推送进来时(当盲人完成移动时)打印出网关或盲板信息:

import time
from motionblinds import MotionMulticast, MotionGateway

def callback_func_gateway():
    print(m)

def callback_func_blind():
    for blind in m.device_list.values():
        print(blind)

motion_multicast = MotionMulticast()
motion_multicast.Start_listen()

m = MotionGateway(ip="192.168.1.100", key="12ab345c-d67e-8f", multicast = motion_multicast)
m.GetDeviceList()
m.Update()

m.Register_callback("1", callback_func_gateway)
for blind in m.device_list.values():
    blind.Register_callback("1", callback_func_blind)

time.sleep(30)

motion_multicast.Stop_listen()

发现

可以使用MotionDiscovery类在网络上发现运动网关。 下面的示例将尝试在10秒钟内发现网关,然后打印一个包含所发现的网关及其连接的百叶窗的dict。在

>>> from motionblinds import MotionDiscovery
>>> d = MotionDiscovery()
>>> motion_gateways = d.discover()
>>> print(motion_gateways)

{'192.168.1.100': {
    'msgType': 'GetDeviceListAck',
    'mac': 'abcdefghujkl',
    'deviceType': '02000002',
    'ProtocolVersion': '0.9',
    'token': '12345A678B9CDEFG',
    'data': [
        {'mac': 'abcdefghujkl',     'deviceType': '02000002'},
        {'mac': 'abcdefghujkl0001', 'deviceType': '10000000'},
        {'mac': 'abcdefghujkl0002', 'deviceType': '10000000'}
    ]
}}

网关设备

网关设备(分配给变量“m”)具有以下方法和属性:

methodargumentsargument typeexplanation
"m.GetDeviceList()"--Get the device list from the Motion Gateway and update the properties listed below
"m.Update()"--Get the status of the Motion Gateway and update the properties listed below
"m.Register_callback("1", func)id, callbackstring, functionRegister a external callback function for updates of the gateway
"m.Remove_callback("1")idstringRemove a external callback using its id
"m.Clear_callbacks()--Remove all external registered callbacks for updates of the gateway
^{tb2}$

盲板装置

盲设备(指定为变量“blind_1”)具有以下方法和属性:

methodargumentsargument typeexplanation
"blind_1.Update_from_cache()"--Get the status of the blind from the cache of the Motion Gateway, No 433MHz radio communication with the blind takes place
"blind_1.Update()"--Get the status of the blind from the blind through the Motion Gateway (WiFi) using 433MHz radio communication between the gateway and the blind
"blind_1.Stop()"--Stop the motion of the blind
"blind_1.Open()"--Open the blind/move the blind up
"blind_1.Close()"--Close the blind/move the blind down
"blind_1.Set_position(50)"postionint (0-100)Set the position of the blind
"blind_1.Set_angle(90)"angleint (0-180)Set the angle/rotation of the blind
"blind_1.Register_callback("1", func)id, callbackstring, functionRegister a external callback function for updates of the blind
"blind_1.Remove_callback("1")idstringRemove a external callback using its id
"blind_1.Clear_callbacks()--Remove all external registered callbacks for updates of the blind
propertyvalue typeexplanation
"blind_1.device_type"stringReturn the device type which is a 8 character number
"blind_1.blind_type"stringReturn the type of the blind from BlindType enum
"blind_1.type"enumReturn the type of the blind as a BlindType enum
"blind_1.mac"stringReturn the mac address of the blind
"blind_1.available"booleanReturn if the blind is available
"blind_1.status"stringReturn the current status of the blind from BlindStatus enum
"blind_1.limit_status"stringReturn the current status of the limit detection of the blind from LimitStatus enum
"blind_1.position"intReturn the current position of the blind in % (0-100)
"blind_1.angle"intReturn the current angle of the blind 0-180
"blind_1.battery_voltage"doubleReturn the current battery voltage of the blind in V
"blind_1.battery_level"doubleReturn the current battery level of the blind in %
"blind_1.RSSI"intReturn the radio connection strength of the blind to the gateway in dBm

自上而下自下而上(TDBU)设备

TDBU遮阳帘装置有两个电机,分别由“T”=顶部和“B”=底部来控制遮阳帘的两个部分。 使用“C”=组合作为电机,两个部件可以一起控制。 TDBU设备(被指定为变量“blind_1”)具有以下方法和特性:

methodargumentsargument typeexplanation
"blind_1.Update()"--Get the status of the blind from the Motion Gateway
"blind_1.Stop(motor = 'B')"motor'B', 'T' or 'C'Stop the motion of Bottom or Top motor of the blind
"blind_1.Open(motor = 'B')"motor'B', 'T' or 'C'Move the Bottom or Top motor of the blind up
"blind_1.Close(motor = 'B')"motor'B', 'T' or 'C'Move the Bottom or Top motor of the blind down
"blind_1.Set_position(50, motor = 'B', width = 20)"position, motor, widthint (0-100), 'B', 'T' or 'C', int (0-100)Set the position of the Bottom or Top motor of the blind, optionaly specify width
"blind_1.Set_scaled_position(50, motor = 'B')"position, motorint (0-100), 'B', 'T' or 'C'Set the position of the motor of the blind within the alowed space in which it can move
"blind_1.Set_angle(90, motor = 'B')"angle, motorint (0-180), 'B', 'T' or 'C'Set the angle/rotation of the Bottom or Top motor of the blind
"blind_1.Register_callback("1", func)id, callbackstring, functionRegister a external callback function for updates of the blind
"blind_1.Remove_callback("1")idstringRemove a external callback using its id
"blind_1.Clear_callbacks()--Remove all external registered callbacks for updates of the blind
propertyvalue typeexplanation
"blind_1.device_type"stringReturn the device type which is a 8 character number
"blind_1.blind_type"stringReturn the type of the blind from BlindType enum
"blind_1.type"enumReturn the type of the blind as a BlindType enum
"blind_1.mac"stringReturn the mac address of the blind
"blind_1.available"booleanReturn if the blind is available
"blind_1.status"{"T": string, "B": string}Return the current status of the blind from BlindStatus enum
"blind_1.limit_status"{"T": string, "B": string}Return the current status of the limit detection of the blind from LimitStatus enum
"blind_1.position"{"T": int, "B": int, "C": double}Return the current position of the blind in % (0-100)
"blind_1.scaled_position"{"T": double, "B": double, "C": double}Return the current position of the blind, scaled to the alowed space in which it can move, in % (0-100)
"blind_1.width"intReturn the area that is covered by the blind in % (0-100)
"blind_1.angle"{"T": int, "B": int}Return the current angle of the blind 0-180
"blind_1.battery_voltage"{"T": double, "B": double}Return the current battery voltage of the blind in V
"blind_1.battery_level"{"T": double, "B": double}Return the current battery level of the blind in %
"blind_1.RSSI"intReturn the radio connection strength of the blind to the gateway in dBm

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

推荐PyPI第三方库


热门话题
构造函数的java条件调用   类Dog中的java构造函数Dog不能应用于给定类型   java jsch和运行“sudo su”   java将队列和堆栈相互复制   java如何在netbeans项目的文件夹中添加库   java While循环在我的代码中不存在   如何在XML中使用java方法的返回值   java是否可以在不写入文件的情况下将字符串/字节数组作为文件发布?   java为什么这些字符串不相等?   sockets客户机-服务器java编程,用户可选择   java如何在SpringMVC和hibernate中保存模型返回视图的列表   java如何修复组织。openqa。硒。WebDriverException:未知错误   Java,Ant错误:编码Cp1252的不可映射字符   JAVAlang.ClassCastException:[Ljava.lang.String;与java.lang.String不兼容   java如何使用JDK8(可选)为空字段创建自定义IntelliJ getter模板   java Tomcat6响应。sendRedirect()404错误