From 00e09d28d81fccf520ab972121aa433244f40630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E6=B1=82=E5=9C=A3=E5=89=91?= Date: Mon, 2 Feb 2026 14:31:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/jackery/sensor.py | 60 ++++++++++++++++------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/custom_components/jackery/sensor.py b/custom_components/jackery/sensor.py index 924d8cb..2511b47 100644 --- a/custom_components/jackery/sensor.py +++ b/custom_components/jackery/sensor.py @@ -546,44 +546,50 @@ class JackeryDataCoordinator: ts = int(time.time()) # 1. Poll Device Status (Type 25) - payload_25 = { - "type": 25, - "eventId": 0, - "messageId": random.randint(1000, 9999), - "ts": ts, - "token": self._token, - "body": None - } - - await ha_mqtt.async_publish( - self.hass, - action_topic, - json.dumps(payload_25), - 0, - False - ) - - # 2. Poll Sub-devices (Type 100) - CTs (2) and Plugs (6) - for dev_type in [2, 6]: - payload_100 = { - "type": 100, + try: + payload_25 = { + "type": 25, "eventId": 0, "messageId": random.randint(1000, 9999), "ts": ts, "token": self._token, - "body": { - "devType": dev_type - } + "body": None } - + await ha_mqtt.async_publish( self.hass, action_topic, - json.dumps(payload_100), + json.dumps(payload_25), 0, False ) - await asyncio.sleep(0.5) # Avoid spamming too fast + except Exception as e: + _LOGGER.warning(f"Error polling device status (Type 25): {e}") + + # 2. Poll Sub-devices (Type 100) - CTs (2) and Plugs (6) + try: + for dev_type in [2, 6]: + payload_100 = { + "type": 100, + "eventId": 0, + "messageId": random.randint(1000, 9999), + "ts": ts, + "token": self._token, + "body": { + "devType": dev_type + } + } + + await ha_mqtt.async_publish( + self.hass, + action_topic, + json.dumps(payload_100), + 0, + False + ) + await asyncio.sleep(0.5) # Avoid spamming too fast + except Exception as e: + _LOGGER.warning(f"Error polling sub-devices (Type 100): {e}") _LOGGER.debug(f"Sent poll requests (25 & 100 [2,6]) to {action_topic}")