积分 241
金钱 226
威望 0
贡献 0
HASS币 0
中级会员
积分 241
金钱 226
HASS币 0
发表于 2024-6-12 14:13:13
|
显示全部楼层
方式二的原理是在gateway3项目本身支持的设备基础上,自行添加额外的设备和设备特性识别。
写法一,更好维护,以后只需要在大括号里新增设备支持的条目就好了。
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
3083: ["Xiaomi", "Electrical Outlet", "ZNCZ01ZM"],
"spec": [
Converter("outlet", "switch", mi="2.p.1"),
MathConv("power", "sensor", mi="3.p.1", multiply=0.01),
Converter("led", "switch", mi="4.p.1", enabled=False),
BoolConv("enable-upload-power", "switch", mi="6.p.1"),
Converter("power_protect", "switch", mi="7.p.1", enabled=False),
MathConv("power_value", "number", mi="7.p.2", multiply=0.01,
min=0, max=1638400, enabled=False),
],
18051: ["Xiaomi", "Occupancy Sensor", "XMOSB01XS", "xiaomi.sensor_occupy.03"],
"spec": [
# main sensors
BoolConv("occupancy", "binary_sensor", mi="2.p.1078"),#Tested
BaseConv("illuminance", "sensor", mi="2.p.1005"),#Tested
# other sensors
BaseConv("battery", "sensor", mi="3.p.1003"),
],
}] + DEVICES
复制代码
写法二,直接粗暴。
from custom_components.xiaomi_gateway3.core.devices import *
DEVICES = [{
3083: ["Xiaomi", "Electrical Outlet", "ZNCZ01ZM"],
"spec": [
Converter("outlet", "switch", mi="2.p.1"),
MathConv("power", "sensor", mi="3.p.1", multiply=0.01),
Converter("led", "switch", mi="4.p.1", enabled=False),
BoolConv("enable-upload-power", "switch", mi="6.p.1"),
Converter("power_protect", "switch", mi="7.p.1", enabled=False),
MathConv("power_value", "number", mi="7.p.2", multiply=0.01,
min=0, max=1638400, enabled=False),
],
}] + DEVICES
DEVICES = [{
18051: ["Xiaomi", "Occupancy Sensor", "XMOSB01XS", "xiaomi.sensor_occupy.03"],
"spec": [
# main sensors
BoolConv("occupancy", "binary_sensor", mi="2.p.1078"),#Tested
BaseConv("illuminance", "sensor", mi="2.p.1005"),#Tested
# other sensors
BaseConv("battery", "sensor", mi="3.p.1003"),
],
}] + DEVICES
复制代码
两种写法的意义都是在custom_components/xiaomi_gateway3/core/devices.py里面的DEVICES变量的基础上添加额外的识别支持。当你了解了python语法之后,理解起来就不难了