Smarthome Functionen
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

modules.py 3.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(mqtt_client, topic_setpoint)
  26. self.gui_value_temp_setp.add_callback(
  27. devices.nodered_gui.KEY_HEATING_SETPOINT, None, self.heating_setpoint_actions)
  28. self.gui_button_boost = devices.nodered_gui(mqtt_client, topic_boost)
  29. self.gui_button_boost.add_callback(None, None, self.boost_actions)
  30. self.gui_led_boost = devices.nodered_gui(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.',
  64. self.topic, self.default_temperature + self.BOOST_TEMP_OFFSET)
  65. self.heating_valve.set_heating_setpoint(self.default_temperature + self.BOOST_TEMP_OFFSET)
  66. def cyclic_task(self, rt):
  67. if self.return_to_default_timer is not None:
  68. self.return_to_default_timer -= self.ct.cycle_time
  69. if self.return_to_default_timer <= 0:
  70. logger.info('Return to default timer expired \"%s\".', self.topic)
  71. self.heating_valve.set_heating_setpoint(self.default_temperature)
  72. self.return_to_default_timer = None
  73. self.return_to_default_setpoint = None
  74. self.gui_led_boost.set_feedback(False)