This commit is contained in:
@@ -489,9 +489,9 @@ class JackeryDataCoordinator:
|
||||
self.add_switch_entities_callback = None # Callback to add new switch entities
|
||||
self._data_cache = {} # Cache for merged data from status and events
|
||||
|
||||
# Topic patterns
|
||||
self._topic_status_wildcard = f"{self._topic_root}/device/+/status"
|
||||
self._topic_event_wildcard = f"{self._topic_root}/device/+/event"
|
||||
# Topic patterns — device-specific so multiple instances don't cross-receive
|
||||
self._topic_status = f"{self._topic_root}/device/{self._device_sn}/status"
|
||||
self._topic_event = f"{self._topic_root}/device/{self._device_sn}/event"
|
||||
|
||||
def register_sensor(self, sensor_id: str, entity: "JackerySensor") -> None:
|
||||
"""注册传感器实体."""
|
||||
@@ -515,20 +515,20 @@ class JackeryDataCoordinator:
|
||||
|
||||
await ha_mqtt.async_subscribe(
|
||||
self.hass,
|
||||
self._topic_status_wildcard,
|
||||
self._topic_status,
|
||||
message_received,
|
||||
1
|
||||
)
|
||||
_LOGGER.info(f"Coordinator subscribed to: {self._topic_status_wildcard}")
|
||||
_LOGGER.info(f"Coordinator subscribed to: {self._topic_status}")
|
||||
|
||||
# Subscribe to event topic for sub-device data (Type 101)
|
||||
await ha_mqtt.async_subscribe(
|
||||
self.hass,
|
||||
self._topic_event_wildcard,
|
||||
self._topic_event,
|
||||
message_received,
|
||||
1
|
||||
)
|
||||
_LOGGER.info(f"Coordinator subscribed to: {self._topic_event_wildcard}")
|
||||
_LOGGER.info(f"Coordinator subscribed to: {self._topic_event}")
|
||||
|
||||
self._subscribed = True
|
||||
|
||||
@@ -557,17 +557,6 @@ class JackeryDataCoordinator:
|
||||
if isinstance(payload, bytes):
|
||||
payload = payload.decode("utf-8")
|
||||
|
||||
# Extract device SN from topic: {prefix}/device/{sn}/status OR .../event
|
||||
match = re.search(rf"{self._topic_root}/device/([^/]+)/(status|event)", topic)
|
||||
if match:
|
||||
sn = match.group(1)
|
||||
msg_type = match.group(2) # 'status' or 'event'
|
||||
if not self._device_sn:
|
||||
self._device_sn = sn
|
||||
_LOGGER.info(f"Discovered device SN: {self._device_sn}")
|
||||
elif self._device_sn != sn:
|
||||
_LOGGER.debug(f"Received data from another device: {sn}")
|
||||
return
|
||||
|
||||
# Parse Payload
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user