From 0b6b9a01fb5c16494acde1ebf304aec117dbd4e1 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 18 Nov 2025 16:05:58 +0100 Subject: [PATCH] refactored 7 --- apps/abstraction/main.py | 60 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/apps/abstraction/main.py b/apps/abstraction/main.py index fcad1b0..e581f1c 100644 --- a/apps/abstraction/main.py +++ b/apps/abstraction/main.py @@ -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///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///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}")