diff --git a/src/main.py b/src/main.py index 9363c18..df97acf 100644 --- a/src/main.py +++ b/src/main.py @@ -5,7 +5,7 @@ import uuid import signal from loguru import logger import paho.mqtt.client as mqtt -from message_processor import process_message # Import the moved function +from message_processor import process_message, prepare_context # MQTT configuration parameters @@ -49,8 +49,8 @@ try: context['boxes'] = boxes # add context dict to each box in the list - for _, config in boxes.items(): - config['context'] = {} + for box_name, config in boxes.items(): + config['context'] = prepare_context(box_name, context) except json.JSONDecodeError as e: logger.error(f"Error parsing JSON configuration for boxes: {e}") sys.exit(1) diff --git a/src/message_processor.py b/src/message_processor.py index ffe1391..63532d4 100644 --- a/src/message_processor.py +++ b/src/message_processor.py @@ -8,10 +8,17 @@ from loguru import logger # boxes['box_name']['context'] # store here what ever is require to represent the state of the box +def prepare_context(box_name, context): + local_context = {} + + + return local_context + def process_message(box_name, topic_key, payload, context): - # logger.info(f"{context=}") try: box = context['boxes'][box_name] + local_context = box['context'] + logger.info(f"{local_context=}") logger.info(f"[{box_name}, {box['label']}] Processing message for '{topic_key}': {payload}") match topic_key.split('/'):