Smarthome Functionen
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

__init__.py 6.1KB

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