refactored 6

This commit is contained in:
2025-11-18 16:03:20 +01:00
parent d9d17d37e5
commit 734ee18e85

View File

@@ -330,36 +330,36 @@ async def mqtt_worker(config: dict[str, Any], redis_client: aioredis.Redis) -> N
retain = getattr(message, 'retain', None)
logger.debug(f"MQTT message received on ({retain=}) {topic}: {payload_str}")
# Check if this is an abstract SET message
if topic.startswith("home/") and topic.endswith("/set"):
payload = json.loads(payload_str)
# Extract device_type and device_id from topic
parts = topic.split("/")
if len(parts) == 4: # home/<type>/<id>/set
device_type = parts[1]
device_id = parts[2]
if device_id in devices:
device = devices[device_id]
vendor_topic = device["topics"]["set"]
device_technology = device.get("technology", "unknown")
await handle_abstract_set(
client, device_id, device_type, device_technology, vendor_topic, payload
)
# Check if this is a vendor STATE message
else:
# Find device by vendor state topic for other technologies
for device_id, device in devices.items():
if topic == device["topics"]["state"]:
device_technology = device.get("technology", "unknown")
await handle_vendor_state(
client, redis_client, device_id, device["type"],
device_technology, payload_str, redis_channel
)
break
# # Check if this is an abstract SET message
# if topic.startswith("home/") and topic.endswith("/set"):
#
# payload = json.loads(payload_str)
#
# # Extract device_type and device_id from topic
# parts = topic.split("/")
# if len(parts) == 4: # home/<type>/<id>/set
# device_type = parts[1]
# device_id = parts[2]
#
# if device_id in devices:
# device = devices[device_id]
# vendor_topic = device["topics"]["set"]
# device_technology = device.get("technology", "unknown")
# await handle_abstract_set(
# client, device_id, device_type, device_technology, vendor_topic, payload
# )
#
# # Check if this is a vendor STATE message
# else:
# # Find device by vendor state topic for other technologies
# for device_id, device in devices.items():
# if topic == device["topics"]["state"]:
# device_technology = device.get("technology", "unknown")
# await handle_vendor_state(
# client, redis_client, device_id, device["type"],
# device_technology, payload_str, redis_channel
# )
# break
except json.JSONDecodeError:
logger.error(f"Failed to decode JSON payload on topic {topic}: {payload_str}")