AlexxIT / XiaomiGateway3

Home Assistant custom component for control Xiaomi Multimode Gateway (aka Gateway 3), Xiaomi Multimode Gateway 2, Aqara Hub E1 on default firmwares over LAN
https://github.com/AlexxIT/Blog
MIT License
2.42k stars 340 forks source link

Add lemesh.switch.sw4a02 mesh switch #1356

Closed invoker-karl closed 1 week ago

invoker-karl commented 4 months ago

最近购买了米家寄存器。型号是https://home.miot-spec.com/spec/ddy.switch.sw4a02。 `我发现当前版本的gateway3不支持该设备。我尝试自己写了一个转换器,看起来所有功能都工作正常。我希望在未来的版本中能够添加对该设备的支持。谢谢。

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
     15418: ["LeMesh", "Mesh Switch", "lemesh.switch.sw4a02"],
    "spec": [
        BaseConv("channel_1", "switch", mi="2.p.1"),
        BaseConv("channel_2", "switch", mi="3.p.1"),
        BaseConv("channel_3", "switch", mi="4.p.1"),
        BaseConv("channel_4", "switch", mi="12.p.1"),
        BaseConv("channel_5", "switch", mi="5.p.1"),
        MapConv("power_on_state_1", "select", mi="2.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("power_on_state_2", "select", mi="3.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("power_on_state_3", "select", mi="4.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("power_on_state_4", "select", mi="12.p.2", map={1: "On", 2: "Off", 3: "Default"}),
        MapConv("wireless_1", "select", mi="2.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("wireless_2", "select", mi="3.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("wireless_3", "select", mi="4.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("wireless_4", "select", mi="12.p.3", map={0: "default", 1: "Wireless", 2: "Wireless", 3: "Wireless"}),
        MapConv("mode", "select", mi="8.p.1", map={1: "Top Speed Mode", 2: "Standard Mode"}),
        BaseConv("action", "sensor", entity=ENTITY_DISABLED),
        ConstConv("action", mi="14.e.1", value=BUTTON_1_SINGLE),
        ConstConv("action", mi="14.e.2", value=BUTTON_1_DOUBLE),
        ConstConv("action", mi="14.e.3", value=BUTTON_1_HOLD),
        ConstConv("action", mi="15.e.1", value=BUTTON_2_SINGLE),
        ConstConv("action", mi="15.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="15.e.3", value=BUTTON_2_HOLD),
        ConstConv("action", mi="16.e.1", value=BUTTON_3_SINGLE),
        ConstConv("action", mi="16.e.2", value=BUTTON_2_DOUBLE),
        ConstConv("action", mi="16.e.3", value=BUTTON_3_HOLD),
        ConstConv("action", mi="17.e.1", value=BUTTON_4_SINGLE),
        ConstConv("action", mi="17.e.2", value="button_4_double"),
        ConstConv("action", mi="17.e.3", value=BUTTON_4_HOLD),
    ],
}] + DEVICES
1043717432 commented 3 months ago

你好。请问你用什么转换器写的?我买了一个橱柜电源也是蓝牙的。也没识别成功。

invoker-karl commented 3 months ago

参照gateway3的代码手写的呀。 转换器的意思是 按照gateway3的代码,依据米家的代码,比如说mi="2.p.1"(网页可查),然后转换的呀。 换句话说,上面的代码就是转换器。

1043717432 commented 3 months ago

https://home.miot-spec.com/spec/ftd.light.dsplmp 请问这个如何转换。目前在HA最新版本和Xiaomi Gateway 3 最新固件里。他显示的只是一个开关,其实是一个调光调色的电源驱动。。谢谢了!

invoker-karl commented 3 months ago

https://bbs.hassbian.com/thread-17548-1-3.html 请参考这篇帖子,同时参考本插件的devices设备,模仿写。

1043717432 commented 3 months ago

https://bbs.hassbian.com/thread-17548-1-3.html 请参考这篇帖子,同时参考本插件的devices设备,模仿写。

谢谢。。我看一下。

AlexxIT commented 1 week ago

https://github.com/AlexxIT/XiaomiGateway3/releases/tag/v4.0.6