添加测试代码

This commit is contained in:
不求圣剑
2026-02-02 14:31:59 +08:00
parent b9721d9b19
commit 00e09d28d8

View File

@@ -546,44 +546,50 @@ class JackeryDataCoordinator:
ts = int(time.time()) ts = int(time.time())
# 1. Poll Device Status (Type 25) # 1. Poll Device Status (Type 25)
payload_25 = { try:
"type": 25, payload_25 = {
"eventId": 0, "type": 25,
"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,
"eventId": 0, "eventId": 0,
"messageId": random.randint(1000, 9999), "messageId": random.randint(1000, 9999),
"ts": ts, "ts": ts,
"token": self._token, "token": self._token,
"body": { "body": None
"devType": dev_type
}
} }
await ha_mqtt.async_publish( await ha_mqtt.async_publish(
self.hass, self.hass,
action_topic, action_topic,
json.dumps(payload_100), json.dumps(payload_25),
0, 0,
False 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}") _LOGGER.debug(f"Sent poll requests (25 & 100 [2,6]) to {action_topic}")