1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
-
- import devices
- import logging
- import task
-
- try:
- from config import APP_NAME as ROOT_LOGGER_NAME
- except ImportError:
- ROOT_LOGGER_NAME = 'root'
- logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
-
-
- class heating_function_brennenstuhl(object):
- RETURN_TO_DEFAULT_TIME = 45 * 60
- BOOST_TEMP_OFFSET = 5
-
- def __init__(self, mqtt_client, topic_valve, default_temperature, topic_boost, topic_setpoint, topic_led):
- self.ct = task.periodic(1, self.cyclic_task)
- #
- self.topic = topic_valve
- self.default_temperature = default_temperature
- #
- self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, topic_valve)
- self.heating_valve.set_heating_setpoint(self.default_temperature)
- self.heating_valve.add_callback(
- devices.brennenstuhl_heatingvalve.KEY_HEATING_SETPOINT, None, self.heating_setpoint_actions)
-
- self.gui_value_temp_setp = devices.nodered_gui(mqtt_client, topic_setpoint)
- self.gui_value_temp_setp.add_callback(
- devices.nodered_gui.KEY_HEATING_SETPOINT, None, self.heating_setpoint_actions)
-
- self.gui_button_boost = devices.nodered_gui(mqtt_client, topic_boost)
- self.gui_button_boost.add_callback(None, None, self.boost_actions)
-
- self.gui_led_boost = devices.nodered_gui(mqtt_client, topic_led)
-
- #
- self.return_to_default_timer = None
- self.return_to_default_setpoint = None
- self.gui_led_boost.set_feedback(False)
- #
- self.ct.run()
-
- def heating_setpoint_actions(self, device, key, data):
- if device.topic == self.heating_valve.topic:
- # valve setpoint action
- self.gui_value_temp_setp.set_feedback(data)
- if data > self.default_temperature:
- if data != self.return_to_default_setpoint:
- logger.info('Got heating setpoint (%.1f°C) \"%s\" with deviation to the default value (%.1f°C). Starting timer for returning to default.',
- data, self.topic, self.default_temperature)
- self.return_to_default_timer = self.RETURN_TO_DEFAULT_TIME
- self.return_to_default_setpoint = data
- self.gui_led_boost.set_feedback(True)
- else:
- if self.return_to_default_timer is not None:
- logger.info('Deleting timer \"%s\" for returning to default.', self.topic)
- self.return_to_default_timer = None
- self.return_to_default_setpoint = None
- self.gui_led_boost.set_feedback(False)
- elif device.topic == self.gui_value_temp_setp.topic:
- # user setpoint action
- logger.info('Setpoint change \"%s\" to %.1f°C', self.topic, data)
- self.default_temperature = data
- self.heating_valve.set_heating_setpoint(self.default_temperature)
- self.return_to_default_timer = None
- self.return_to_default_setpoint = None
- self.gui_led_boost.set_feedback(False)
-
- def boost_actions(self, davice, key, data):
- logger.info('Starting boost mode \"%s\" with setpoint %.1f°C.',
- self.topic, self.default_temperature + self.BOOST_TEMP_OFFSET)
- self.heating_valve.set_heating_setpoint(self.default_temperature + self.BOOST_TEMP_OFFSET)
-
- def cyclic_task(self, rt):
- if self.return_to_default_timer is not None:
- self.return_to_default_timer -= self.ct.cycle_time
- if self.return_to_default_timer <= 0:
- logger.info('Return to default timer expired \"%s\".', self.topic)
- self.heating_valve.set_heating_setpoint(self.default_temperature)
- self.return_to_default_timer = None
- self.return_to_default_setpoint = None
- self.gui_led_boost.set_feedback(False)
|