This commit is contained in:
2024-11-05 15:53:03 +01:00
parent db89541352
commit d57becf736
4 changed files with 33 additions and 2 deletions

View File

@ -42,6 +42,11 @@ context['publish'] = PUBLISH_PREFIX
# Load box configurations from JSON
try:
boxes = json.loads(BOXES_CONFIG)
# here, boxes store their internal state
boxes['context'] = {}
# boxes structure added to global context to give process_message access to it
context['boxes'] = boxes
except json.JSONDecodeError as e:
logger.error(f"Error parsing JSON configuration for boxes: {e}")
@ -83,6 +88,9 @@ def on_connect(client, userdata, flags, rc):
# Generate topics based on configured box-specific prefixes and box label
topics = {}
for topic_key, prefix in box_topic_prefixes.items():
if topic_key == 'window':
for window in boxes.windows:
topics[topic_key] = f"{prefix}{label}"
config["subscribe"] = topics # Store the generated topics