本帖最后由 killadm 于 2018-9-7 22:52 编辑
多dc1的代码效率很高,也很优雅,但是好像有点问题,插座和服务器通讯正常,但是ha提示mac地址错误。
日志是这样的
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 等待活动连接......
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 有1个新事件,开始处理......
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 发送数据:b'{"uuid":"identifyf080","params":{},"auth":"","action":"datapoint"}\n'
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 等待活动连接......
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 有1个新事件,开始处理......
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 192.168.123.30 queue empty
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 等待活动连接......
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 有1个新事件,开始处理......
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 收到数据:b'{"uuid":"identifyf080","status":200,"result":{"status":1111,"I":430,"V":238,"P":51},"msg":"get datapoint success"}\n', client:192.168.123.30
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] 无更新
2018-09-07 20:29:28 DEBUG (Thread-3) [custom_components.switch.PhicommDC1] {'identifyf080': {'status': 15, 'I': 430, 'P': 51, 'V': 238}}
正常配网的dc不会发送mac,而且连接成功后发送的第一个数据包里的"uuid":"identify****"不是固定的,导致无法通过mac和identify****识别设备。
下边是插座连接到服务器后发送的第一个数据包,里边只有device_id是固定的。
{"action":"identify","uuid":"identify9297","auth":"7a3cfa88","params":{"device_id":"7-717575082642****"}}.
还有插座有时会发送下边这样的数据包。
{"action":"kWh+","uuid":"kWh+b130b0f6","auth":"7a3cfa88","params":{"detalKWh":238}}.
好像也识别成了新插座。
更新:
把67、68行的mac改成device_id之后测试ha可以正常获取到数据,控制无延迟,效果非常好。 |