Smarthome Functionen
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

__init__.py 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, first_floor_west_bath, first_floor_west_sleep
  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. 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. #
  24. # Rooms
  25. #
  26. # stairway
  27. self.stw_stairway = stairway(self.mqtt_client)
  28. # ground floor west
  29. self.gfw_floor = ground_floor_west_floor(self.mqtt_client)
  30. self.gfw_marion = ground_floor_west_marion(self.mqtt_client)
  31. self.gfw_dirk = ground_floor_west_dirk(self.mqtt_client)
  32. # first floor west
  33. self.ffw_julian = first_floor_west_julian(self.mqtt_client)
  34. self.ffw_bath = first_floor_west_bath(self.mqtt_client)
  35. self.ffw_living = first_floor_west_living(self.mqtt_client)
  36. self.ffw_sleep = first_floor_west_sleep(self.mqtt_client)
  37. # first floor east
  38. self.ffe_floor = first_floor_east_floor(self.mqtt_client)
  39. self.ffe_kitchen = first_floor_east_kitchen(self.mqtt_client)
  40. self.ffe_dining = first_floor_east_dining(self.mqtt_client)
  41. self.ffe_sleep = first_floor_east_sleep(self.mqtt_client)
  42. self.ffe_living = first_floor_east_living(self.mqtt_client)
  43. #
  44. # Interactions
  45. #
  46. # cross_room_interactions
  47. self.init_cross_room_interactions()
  48. # Off Buttons
  49. self.init_off_functionality()
  50. def init_cross_room_interactions(self):
  51. # shelly dirk input 1
  52. self.last_gfw_dirk_input_1 = None
  53. self.gfw_dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
  54. # tradfri button ffe_sleep right click
  55. self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
  56. devices.tradfri_button.ACTION_RIGHT, self.ffe_floor.main_light_shelly.toggle_output_0_mcb)
  57. def init_off_functionality(self):
  58. ##### TEMPORARY ###################################################################################################################
  59. # Off Buttons
  60. self.gui_button_all_off = devices.nodered_gui_button(self.mqtt_client, "gui/all/common/off/button")
  61. self.gui_button_gfw_off = devices.nodered_gui_button(self.mqtt_client, "gui/gfw/common/off/button")
  62. self.gui_button_ffw_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffw/common/off/button")
  63. self.gui_button_ffe_off = devices.nodered_gui_button(self.mqtt_client, "gui/ffe/common/off/button")
  64. #
  65. self.gui_button_all_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.all_off)
  66. self.gui_button_gfw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.gfw_off)
  67. self.gui_button_ffw_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffw_off)
  68. self.gui_button_ffe_off.add_callback(devices.nodered_gui_button.KEY_STATE, True, self.ffe_off)
  69. ##### TEMPORARY ###################################################################################################################
  70. # ALL OFF - Long push stairway
  71. self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw_stairway.main_light_shelly.flash_0_mcb)
  72. self.stw_stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
  73. # FFE ALL OFF - Long push ffe_floor
  74. self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_floor.main_light_shelly.flash_0_mcb)
  75. self.ffe_floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe_off)
  76. # FFE ALL OFF - Long push input device
  77. self.ffe_sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe_off)
  78. def gfw_dirk_input_1(self, device, key, data):
  79. if self.last_gfw_dirk_input_1 is not None:
  80. if self.last_gfw_dirk_input_1 != data:
  81. self.gfw_floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
  82. self.last_gfw_dirk_input_1 = data
  83. def getmembers(self, prefix):
  84. rv = []
  85. for name, obj in inspect.getmembers(self):
  86. if name.startswith(prefix) and obj.__module__.split('.')[0] == 'function' and len(obj.__module__.split('.')) == 2:
  87. rv.append(obj)
  88. return rv
  89. def common_off(self, device=None, key=None, data=None):
  90. logger.info("Switching \"common\" off.")
  91. for common in self.getmembers('common'):
  92. common.all_off()
  93. def gfw_off(self, device=None, key=None, data=None):
  94. logger.info("Switching \"ground floor west\" off.")
  95. for gfw in self.getmembers('gfw'):
  96. gfw.all_off()
  97. def ffw_off(self, device=None, key=None, data=None):
  98. logger.info("Switching \"first floor west\" off.")
  99. for ffw in self.getmembers('ffw'):
  100. ffw.all_off()
  101. def ffe_off(self, device=None, key=None, data=None):
  102. logger.info("Switching \"first floor east\" off.")
  103. for ffe in self.getmembers('ffe'):
  104. ffe.all_off()
  105. def stw_off(self, device=None, key=None, data=None):
  106. logger.info("Switching \"stairway\" off.")
  107. for stw in self.getmembers('stw'):
  108. stw.all_off()
  109. def all_off(self, device=None, key=None, data=None):
  110. self.common_off(device, key, data)
  111. self.gfw_off(device, key, data)
  112. self.ffw_off(device, key, data)
  113. self.ffe_off(device, key, data)
  114. self.stw_off(device, key, data)
  115. def devicelist(self):
  116. if self.__devices__ is None:
  117. self.__devices__ = []
  118. for name, obj in inspect.getmembers(self):
  119. if obj.__class__.__module__ == "devices":
  120. self.__devices__.append(obj)
  121. elif obj.__class__.__module__.split('.')[0] == 'function':
  122. for devicename, device in inspect.getmembers(obj):
  123. if device.__class__.__module__ == "devices":
  124. self.__devices__.append(device)
  125. return self.__devices__