『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 475|回复: 0

[技术探讨] MX射频控制器PLUS发起命令超时重试

[复制链接]

1

主题

13

帖子

138

积分

注册会员

Rank: 2

积分
138
金钱
125
HASS币
0
发表于 2024-9-21 00:23:38 | 显示全部楼层 |阅读模式
本帖最后由 1120319827 于 2024-9-21 00:29 编辑
import logging
from homeassistant.components.button import ButtonEntity
from miio.miot_device import MiotDevice

_LOGGER = logging.getLogger(__name__)

_MAPPING = {
    'key-num': {"siid": 3, "piid": 12}
}

class MyIntegrationButton(ButtonEntity):
    def __init__(self, name, ip, token, siid, piid, value):
        self._unique_id = f"{ip}_{value}" 
        self._name = name
        self._ip = ip
        self._token = token
        self._siid = siid
        self._piid = piid
        self._value = value
        self._device = MiotDevice(ip=ip, token=token, mapping=_MAPPING, timeout=3)

    def _send_command(self):
        """Send the command to the Miot device."""
        try:
            property_request = [
                {"siid": self._siid, "piid": self._piid, "value": self._value}
            ]
            self._device.send("set_properties", property_request)
            _LOGGER.info(f"Sent value {self._value} to siid={self._siid}, piid={self._piid}")
        except Exception as e:
            _LOGGER.error(f"Failed to send command to the device: {e}")</span>


上面是核心代码部分, 每次点击具体按钮后设备会执行相应的命令, 但是self._device.send("set_properties", property_request)内部代码似乎没有收到设备的反馈自动重试4次, 调整了timeout也没有用

错误日志如下:
2024-09-21 00:02:40.152 ERROR (SyncWorker_60) [miio.miioprotocol] Got error when receiving: timed out  < 报错位置: self._device.send("set_properties", property_request)
2024-09-21 00:02:40.155 ERROR (SyncWorker_60) [custom_components.mx_control.button] Failed to send command to the device: No response from the device




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2025-1-10 16:58 , Processed in 0.086214 second(s), 22 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表