seems to work

This commit is contained in:
2024-11-06 14:38:53 +01:00
parent a24f4a4def
commit 63a8b3cf2d

View File

@ -62,29 +62,61 @@ def process_message(box_name, topic_key, payload, context):
except Exception as e:
logger.error(f"[{box_name}] Error processing '{topic_key}': {e}")
def _calculate_output_temperature(local_context):
# maintenance_mode has the highest priority, even higher than general_off
if local_context['maintenance_mode']:
local_context['output_temperature'] = local_context['maintenance_temperature']
return
# general_off has the next highest priority
if local_context['general_off']:
local_context['output_temperature'] = local_context['off_temperature']
return
# an open window shuts off the heating
for w in local_context['window_state'].values():
if w == 'open':
local_context['output_temperature'] = local_context['off_temperature']
return
# finally evaluate the mode
if local_context['mode'] == 'off':
local_context['output_temperature'] = local_context['off_temperature']
return
if local_context['mode'] == 'low':
local_context['output_temperature'] = local_context['low_temperature']
return
if local_context['mode'] == 'high':
local_context['output_temperature'] = local_context['high_temperature']
return
logger.error(f"Error in calculation of output_temperature: {local_context=}")
return
def process_status(box_name, context, local_context, payload):
return (f"{local_context}", True)
def process_general_off(box_name, context, local_context, payload):
local_context['general_off'] = (payload.lower() in ('true'))
_calculate_output_temperature(local_context)
return (local_context['output_temperature'], False)
def process_maintenance_mode(box_name, context, local_context, payload):
local_context['maintenance_mode'] = (payload.lower() in ('true'))
_calculate_output_temperature(local_context)
return (local_context['output_temperature'], False)
def process_cmd(box_name, context, local_context, payload):
if payload.lower() in ('high', 'low', 'off'):
local_context['mode'] = payload.lower()
_calculate_output_temperature(local_context)
else:
logger.error(f"Invalid cmd for {box_name} received: {payload}")
return (local_context['output_temperature'], False)
def process_high_temp(box_name, context, local_context, payload):
local_context['high_temperature'] = payload
_calculate_output_temperature(local_context)
return (local_context['output_temperature'], False)
def process_window(box_name, context, local_context, sub_key, payload):
local_context['window_state'][sub_key] = 'closed' if (payload.lower() in ('true', 'close', 'closed')) else 'open'
_calculate_output_temperature(local_context)
return (local_context['output_temperature'], False)