Smarthome Functionen
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

__init__.py 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import devices
  5. from function.stairway import stairway
  6. from function.ground_floor_west import ground_floor_west_floor, ground_floor_west_marion, ground_floor_west_dirk
  7. from function.first_floor_west import first_floor_west_julian, first_floor_west_living
  8. from function.first_floor_east import first_floor_east_floor, first_floor_east_kitchen, first_floor_east_dining, first_floor_east_sleep, first_floor_east_living
  9. from function.common import common_heating, common_circulation_pump
  10. import inspect
  11. import logging
  12. try:
  13. from config import APP_NAME as ROOT_LOGGER_NAME
  14. except ImportError:
  15. ROOT_LOGGER_NAME = 'root'
  16. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  17. # TODO: implement devices.nodered_gui_timer (for circulation pump)
  18. # implement devices.nodered_gui_heatvalve incl. setpoint, boost, ... and functions from funtion.module
  19. # improve devices.brennenstuhl_heatvalve
  20. # improve the implementation in common if highly reduced, just move it to function.__init__.py
  21. # TODO: implement garland (incl. day events like sunset, sunrise, ...)
  22. # TODO: implement warning message
  23. class all_functions(object):
  24. def __init__(self, mqtt_client):
  25. self.mqtt_client = mqtt_client
  26. #
  27. self.__devices__ = None
  28. # heating and warm water
  29. self.common_ffe_heat_sleep = common_heating(self.mqtt_client)
  30. self.common_circulation_pump = common_circulation_pump(self.mqtt_client)
  31. # stairway
  32. self.stw_stairway = stairway(self.mqtt_client)
  33. # ground floor west
  34. self.gfw_floor = ground_floor_west_floor(self.mqtt_client)
  35. self.gfw_marion = ground_floor_west_marion(self.mqtt_client)
  36. self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
  37. # first floor west
  38. self.ffw_julian = first_floor_west_julian(self.mqtt_client)
  39. self.ffw_living = first_floor_west_living(self.mqtt_client)
  40. # first floor east
  41. self.ffe_floor = first_floor_east_floor(self.mqtt_client)
  42. self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)
  43. self.ffe_dining = first_floor_east_dining(self.mqtt_client)
  44. self.ffe_sleep = first_floor_east_sleep(self.mqtt_client)
  45. self.ffe_living = first_floor_east_living(self.mqtt_client)
  46. #
  47. # Interactions
  48. #
  49. # cross_room_interactions
  50. self.init_cross_room_interactions()
  51. # Circulation pump
  52. self.init_circulation_pump()
  53. # Off Buttons
  54. self.init_off_functionality()
  55. def init_off_functionality(self):
  56. # Off Buttons
  57. self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
  58. self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
  59. self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffw/common/off/button")
  60. self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffe/common/off/button")
  61. #
  62. self.gui_button_all_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.all_off)
  63. self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
  64. self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
  65. self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
  66. # Long push ffe_floor
  67. self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.all_off_feedback)
  68. self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
  69. # Long push input device
  70. self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe_off)
  71. def getmembers(self, prefix):
  72. rv = []
  73. for name, obj in inspect.getmembers(self):
  74. if name.startswith(prefix) and obj.__module__.split('.')[0] == 'function' and len(obj.__module__.split('.')) == 2:
  75. rv.append(obj)
  76. return rv
  77. def common_off(self, device=None, key=None, data=None):
  78. logger.info("Switching \"common\" off.")
  79. for common in self.getmembers('common'):
  80. common.all_off()
  81. def gfw_off(self, device=None, key=None, data=None):
  82. logger.info("Switching \"ground floor west\" off.")
  83. for gfw in self.getmembers('gfw'):
  84. gfw.all_off()
  85. def ffw_off(self, device=None, key=None, data=None):
  86. logger.info("Switching \"first floor west\" off.")
  87. for ffw in self.getmembers('ffw'):
  88. ffw.all_off()
  89. def ffe_off(self, device=None, key=None, data=None):
  90. logger.info("Switching \"first floor east\" off.")
  91. for ffe in self.getmembers('ffe'):
  92. ffe.all_off()
  93. def all_off(self, device=None, key=None, data=None):
  94. self.common_off(device, key, data)
  95. self.gfw_off(device, key, data)
  96. self.ffw_off(device, key, data)
  97. self.ffe_off(device, key, data)
  98. def init_cross_room_interactions(self):
  99. # shelly dirk input 1
  100. self.last_gfw_dirk_input_1 = None
  101. self.gfw_dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
  102. # tradfri button ffe_sleep right click
  103. self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
  104. devices.tradfri_button.ACTION_RIGHT, self.ffe_floor.main_light_shelly.toggle_output_0_mcb)
  105. def init_circulation_pump(self):
  106. self.common_circulation_pump.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.ffe_kitchen.flash_main_light)
  107. def gfw_dirk_input_1(self, device, key, data):
  108. if self.last_gfw_dirk_input_1 is not None:
  109. if self.last_gfw_dirk_input_1 != data:
  110. self.gfw_floor.main_light_shelly.toggle_main_light(device, key, data)
  111. self.last_gfw_dirk_input_1 = data
  112. def devicelist(self):
  113. if self.__devices__ is None:
  114. self.__devices__ = []
  115. for name, obj in inspect.getmembers(self):
  116. if obj.__class__.__module__ == "devices":
  117. self.__devices__.append(obj)
  118. elif obj.__class__.__module__.split('.')[0] == 'function':
  119. for devicename, device in inspect.getmembers(obj):
  120. if device.__class__.__module__ == "devices":
  121. self.__devices__.append(device)
  122. return self.__devices__