一个用于通过RaspyRFM模块发送rc信号的库
项目描述
raspyrfm-client 
一个允许生成RaspyRFM rc模块(以及其他网关!)网络代码的Python 3.4+库。
构建状态
主分支 |
测试版 |
开发版 |
---|---|---|
如何使用
安装
pip安装raspyrfm-client
用法
基本示例请参考example.py文件。
如果您需要更多信息,请参考文档,它应该会有所帮助。
基本示例
导入所需模块
from raspyrfm_client import RaspyRFMClient
from raspyrfm_client.device_implementations.controlunit.actions import Action
from raspyrfm_client.device_implementations.controlunit.controlunit_constants import ControlUnitModel
from raspyrfm_client.device_implementations.gateway.manufacturer.gateway_constants import GatewayModel
from raspyrfm_client.device_implementations.manufacturer_constants import Manufacturer
创建RaspyRFMClient
对象
通过调用获取客户端实例
rfm_client = RaspyRFMClient()
创建Gateway
实例
您可以使用以下方式自动搜索LAN中可用的网关
gateways = rfm_client.search()
这将返回一个网关列表,稍后可以使用这些网关发送信号。
要快速查看哪些网关制造商和型号受到支持,请调用
rfm_client.list_supported_gateways()
使用指定的网关IP
和端口
创建网关实例
gateway = rfm_client.get_gateway(Manufacturer.SEEGEL_SYSTEME, GatewayModel.RASPYRFM, "192.168.2.10", 9876)
或
gateway = rfm_client.get_gateway(Manufacturer.SEEGEL_SYSTEME, GatewayModel.RASPYRFM, "192.168.2.10") # defaults to 49880 or the gateway implementations default
获取一个ControlUnit
ControlUnit是接收通过网关发送的rc信号并接收的设备,例如电源插座。
要快速查看哪些ControlUnit 制造商和型号受到支持,请调用
rfm_client.list_supported_controlunits()
这将提供一个类似以下的缩进列表,列出支持的制造商及其支持的型号
Elro
RC3500-A IP44 DE
AB440S
AB440D 200W
AB440D 300W
AB440ID
AB440IS
AB440L
AB440SC
AB440WD
BAT
RC AAA1000-A IP44 Outdoor
Brennenstuhl
RCS 1000 N Comfort
RCS 1044 N Comfort
Intertek
Model 1919361
[...]
为了为设备生成代码,您首先需要获取其实例,如下所示:
brennenstuhl_rcs1000 = rfm_client.get_controlunit(manufacturer_constants.BRENNENSTUHL,
manufacturer_constants.RCS_1000_N_COMFORT)
get_controlunit()
方法的参数始终需要指定类型的枚举值。您可以通过名称来获取枚举常量,如下所示:
manufacturer = Manufacturer("Intertechno")
model = ControlUnitModel("IT-1500")
ControlUnit
通道配置
在您可以使用您的新颖的网关和 ControlUnit
实现生成代码之前,您必须为您的 ControlUnit
指定一个通道配置。这些配置对于每个设备都可能会有很大差异。了解特定设备的正确通道配置方法,最好的方式是查看源代码(是的,我知道……)或通过试错(更糟糕)。一个好的 ControlUnit
实现应该在您错误指定配置时告诉您应该如何进行配置。
然而,所有配置都是一个 键控字典。因此,通常有两种传递通道配置参数的方法。一种是(内联)
device.set_channel_config(value1=1, value2=2)
另一种是(作为字典)
device.set_channel_config(**{
'value1': 1,
'value2': 2
})
注意,键始终需要是一个 字符串
。第二种方法更推荐,因为它通常会产生更易于阅读的源代码。
对于我们的 Brennenstuhl 设备,它看起来像这样:
brennenstuhl_rcs1000.set_channel_config(**{
'1': True,
'2': True,
'3': True,
'4': True,
'5': True,
'CH': 'A'
})
生成动作代码
现在,您已经正确设置了 ControlUnit
,您可以使用之前导入的 Action
枚举常量来生成它支持的动作的代码。
要获取 ControlUnit
支持的动作列表,请调用
brennenstuhl_rcs1000.get_supported_actions()
然后使用您的 Gateway
实例生成其中一个动作的代码
code = gateway.generate_code(brennenstuhl_rcs1000, Action.ON)
将代码发送到 RaspyRFM
模块
要发送您选择的设备的代码,您可以组合此调用中的对象
rfm_client.send(gateway, brennenstuhl_rcs1000, Action.ON)
这将生成特定于传入网关实现的代码,并在发送到其主地址后立即发送。
自定义实现
raspyrfm-client
库设计得让您可以以(希望)非常简单的方式实现自定义设备。
文件结构
所有 ControlUnit
实现都位于 /device_implementations/controlunit/manufacturer/
模块中,并实现了位于 /device_implementations/controlunit/base.py
的基础类 Device
。
创建新的 ControlUnit
要为新的制造商和型号创建新的 ControlUnit
实现创建一个新的子目录用于您的制造商,以及一个用于您的型号的 Python 文件
───raspyrfm_client
│ │ client.py
│ │
│ └───device
│ │ actions.py
│ │ base.py
│ │
│ └───manufacturer
│ │ manufacturer_constants.py
│ │
│ ├───intertek
│ │ Model1919361.py
│ │
│ ├───rev
│ │ Ritter.py
│ │ Telecontrol.py
│ │
│ ├───universal
│ │ HX2262Compatible.py
│ │
│ └───yourmanufacturer
│ yourmodel.py
──────────────────────────────────────────
实现 ControlUnit
现在,您 ControlUnit
的基本实现应该如下所示
from raspyrfm_client.device_implementations.controlunit.actions import Action
from raspyrfm_client.device_implementations.controlunit.base import ControlUnit
class YourModel(ControlUnit):
def __init__(self):
from raspyrfm_client.device_implementations.manufacturer_constants import Manufacturer
from raspyrfm_client.device_implementations.controlunit.controlunit_constants import ControlUnitModel
super().__init__(Manufacturer.YourManufacturer, ControlUnitModel.YourModel)
def get_channel_config_args(self):
return {}
def get_pulse_data(self, action: Action):
return [[0, 0], [0, 0]], 0, 0
def get_supported_actions(self) -> [str]:
return [Action.ON]
最重要的是,您必须像所示那样调用 super().__init__
方法。这将确保您的实现能被 RaspyRFMClient
找到,您可以使用之前显示的 rfm_client.get_controlunit()
获取您的设备实例。
如果您的制造商尚不存在,请在新创建的 manufacturer_constants.py
文件中创建一个新的枚举常量,并在您的 __init__
中使用其值。在 controlunit_constants.py
文件中为您的型号名称也做同样的事情。
您还必须实现 Device
类的所有抽象方法。查看其文档以了解这些方法都涉及什么。
在您实现了所有方法后,您就可以使用了!只需调用 rfm_client.reload_implementation_classes()
和 rfm_client.list_supported_controlunits()
检查您的实现是否被列出。如果一切看起来都很好,您就可以像使用其他实现一样使用它。
排除 WIP 实现
要防止 RaspyRFM 客户端导入您的不完整或基础类实现,只需包含一个类字段,如下所示:
class YourModel(ControlUnit):
DISABLED = True
[...]
贡献
GitHub是用于社交编码的:如果您想编写代码,我鼓励您通过从本仓库的分支进行拉取请求来贡献。为错误和新功能创建GitHub问题单,并对您感兴趣的问题进行评论。
许可证
raspyrfm-client by Markus Ressel Copyright (C) 2017 Markus Ressel This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://gnu.ac.cn/licenses/>.
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。