add prepare_context
This commit is contained in:
@ -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)
|
||||
|
@ -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('/'):
|
||||
|
Reference in New Issue
Block a user