Smarthome Functionen
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

__init__.py 6.1KB

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