Smarthome Functionen
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

modules.py 3.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import devices
  5. import logging
  6. import task
  7. try:
  8. from config import APP_NAME as ROOT_LOGGER_NAME
  9. except ImportError:
  10. ROOT_LOGGER_NAME = 'root'
  11. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  12. class heating_function_brennenstuhl(object):
  13. RETURN_TO_DEFAULT_TIME = 45 * 60
  14. BOOST_TEMP_OFFSET = 5
  15. def __init__(self, mqtt_client, topic_valve, default_temperature, topic_boost, topic_setpoint, topic_led):
  16. self.ct = task.periodic(1, self.cyclic_task)
  17. #
  18. self.topic = topic_valve
  19. self.default_temperature = default_temperature
  20. #
  21. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, topic_valve)
  22. self.heating_valve.set_heating_setpoint(self.default_temperature)
  23. self.heating_valve.add_callback(
  24. devices.brennenstuhl_heatingvalve.KEY_HEATING_SETPOINT, None, self.heating_setpoint_actions)
  25. self.gui_value_temp_setp = devices.nodered_gui_heatvalve(mqtt_client, topic_setpoint)
  26. self.gui_value_temp_setp.add_callback(
  27. devices.nodered_gui_heatvalve.KEY_HEATING_SETPOINT, None, self.heating_setpoint_actions)
  28. self.gui_button_boost = devices.nodered_gui_heatvalve(mqtt_client, topic_boost)
  29. self.gui_button_boost.add_callback(None, None, self.boost_actions)
  30. self.gui_led_boost = devices.nodered_gui_heatvalve(mqtt_client, topic_led)
  31. #
  32. self.return_to_default_timer = None
  33. self.return_to_default_setpoint = None
  34. self.gui_led_boost.set_feedback(False)
  35. #
  36. self.ct.run()
  37. def heating_setpoint_actions(self, device, key, data):
  38. if device.topic == self.heating_valve.topic:
  39. # valve setpoint action
  40. self.gui_value_temp_setp.set_feedback(data)
  41. if data > self.default_temperature:
  42. if data != self.return_to_default_setpoint:
  43. logger.info('Got heating setpoint (%.1f°C) \"%s\" with deviation to the default value (%.1f°C). Starting timer for returning to default.',
  44. data, self.topic, self.default_temperature)
  45. self.return_to_default_timer = self.RETURN_TO_DEFAULT_TIME
  46. self.return_to_default_setpoint = data
  47. self.gui_led_boost.set_feedback(True)
  48. else:
  49. if self.return_to_default_timer is not None:
  50. logger.info('Deleting timer \"%s\" for returning to default.', self.topic)
  51. self.return_to_default_timer = None
  52. self.return_to_default_setpoint = None
  53. self.gui_led_boost.set_feedback(False)
  54. elif device.topic == self.gui_value_temp_setp.topic:
  55. # user setpoint action
  56. logger.info('Setpoint change \"%s\" to %.1f°C', self.topic, data)
  57. self.default_temperature = data
  58. self.heating_valve.set_heating_setpoint(self.default_temperature)
  59. self.return_to_default_timer = None
  60. self.return_to_default_setpoint = None
  61. self.gui_led_boost.set_feedback(False)
  62. def boost_actions(self, davice, key, data):
  63. logger.info('Starting boost mode \"%s\" with setpoint %.1f°C.', self.topic, self.default_temperature + self.BOOST_TEMP_OFFSET)
  64. self.heating_valve.set_heating_setpoint(self.default_temperature + self.BOOST_TEMP_OFFSET)
  65. def cyclic_task(self, rt):
  66. if self.return_to_default_timer is not None:
  67. self.return_to_default_timer -= self.ct.cycle_time
  68. if self.return_to_default_timer <= 0:
  69. logger.info('Return to default timer expired \"%s\".', self.topic)
  70. self.heating_valve.set_heating_setpoint(self.default_temperature)
  71. self.return_to_default_timer = None
  72. self.return_to_default_setpoint = None
  73. self.gui_led_boost.set_feedback(False)