From fd57e7c565e82a397615a198e445fedabf958392 Mon Sep 17 00:00:00 2001 From: Li Shuzhen Date: Mon, 30 Jun 2025 11:12:18 +0800 Subject: [PATCH] fix: reconnect delay time (#1200) * fix: reset the reconnect interval when connected (#1175) * feat: set the default reconnect delay time as 10 seconds * fix: get the minimum reconnect interval --- custom_components/xiaomi_home/miot/miot_mips.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/xiaomi_home/miot/miot_mips.py b/custom_components/xiaomi_home/miot/miot_mips.py index 4513aef..5cf884d 100644 --- a/custom_components/xiaomi_home/miot/miot_mips.py +++ b/custom_components/xiaomi_home/miot/miot_mips.py @@ -216,7 +216,7 @@ class _MipsClient(ABC): MQTT_INTERVAL_S = 1 MIPS_QOS: int = 2 UINT32_MAX: int = 0xFFFFFFFF - MIPS_RECONNECT_INTERVAL_MIN: float = 30 + MIPS_RECONNECT_INTERVAL_MIN: float = 10 MIPS_RECONNECT_INTERVAL_MAX: float = 600 MIPS_SUB_PATCH: int = 300 MIPS_SUB_INTERVAL: float = 1 @@ -641,6 +641,7 @@ class _MipsClient(ABC): if not self._mqtt.is_connected(): return self.log_info(f'mips connect, {flags}, {rc}, {props}') + self.__reset_reconnect_time() self._mqtt_state = True self._internal_loop.call_soon( self._on_mips_connect, rc, props) @@ -822,7 +823,7 @@ class _MipsClient(ABC): self._internal_loop.stop() def __get_next_reconnect_time(self) -> float: - if self._mips_reconnect_interval == 0: + if self._mips_reconnect_interval < self.MIPS_RECONNECT_INTERVAL_MIN: self._mips_reconnect_interval = self.MIPS_RECONNECT_INTERVAL_MIN else: self._mips_reconnect_interval = min( @@ -830,6 +831,9 @@ class _MipsClient(ABC): self.MIPS_RECONNECT_INTERVAL_MAX) return self._mips_reconnect_interval + def __reset_reconnect_time(self) -> None: + self._mips_reconnect_interval = 0 + class MipsCloudClient(_MipsClient): """MIoT Pub/Sub Cloud Client."""