Smarthome Functionen
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import config
  2. from __simulation__.devices import shelly, silvercrest_powerplug, tradfri_light, tradfri_button, silvercrest_motion_sensor, my_powerplug, remote, brennenstuhl_radiator_valve
  3. from __simulation__.devices import gui_light, gui_led_array, gui_radiator_valve
  4. import inspect
  5. class base(object):
  6. def getmembers(self, prefix=''):
  7. rv = []
  8. for name, obj in inspect.getmembers(self):
  9. if prefix:
  10. full_name = prefix + '.' + name
  11. else:
  12. full_name = name
  13. if not name.startswith('_'):
  14. try:
  15. if obj.__module__.endswith('devices'):
  16. rv.append(full_name)
  17. else:
  18. rv.extend(obj.getmembers(full_name))
  19. except AttributeError:
  20. pass
  21. return rv
  22. def getobjbyname(self, name):
  23. obj = self
  24. for subname in name.split('.'):
  25. obj = getattr(obj, subname)
  26. return obj
  27. def command(self, full_command):
  28. try:
  29. parameter = " " + full_command.split(' ')[1]
  30. except IndexError:
  31. parameter = ""
  32. command = full_command.split(' ')[0].split('.')[-1] + parameter
  33. device_name = '.'.join(full_command.split(' ')[0].split('.')[:-1])
  34. self.getobjbyname(device_name).command(command)
  35. class gfw_floor(base):
  36. def __init__(self, mqtt_client):
  37. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI, True, True, True)
  38. self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  39. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  40. self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_1_ZIGBEE, True, True, True, False)
  41. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_on, "on")
  42. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
  43. self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_2_ZIGBEE, True, True, True, False)
  44. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, "on")
  45. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
  46. class gfw_marion(base):
  47. def __init__(self, mqtt_client):
  48. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI, True, False, False)
  49. self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  50. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  51. class gfw_dirk(base):
  52. def __init__(self, mqtt_client):
  53. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI, True, True, True)
  54. self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  55. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  56. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True)
  57. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  58. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  59. #
  60. self.powerplug = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
  61. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
  62. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_1, "Desk_Light")
  63. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_2, "CD_Player")
  64. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_3, "PC_Dock")
  65. self.gui_amplifier = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI, True, False, False)
  66. self.gui_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI, True, True, True)
  67. self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
  68. self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_on, True)
  69. self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_off, False)
  70. self.gui_cd_player = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI, True, False, False)
  71. self.gui_pc_dock = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI, True, False, False)
  72. #
  73. self.remote = remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
  74. #
  75. self.input_device = tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
  76. self.led_array = gui_led_array(mqtt_client, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
  77. self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
  78. self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Desk Light")
  79. self.led_array.add_channel_name(gui_led_array.KEY_LED_2, "Amplifier")
  80. class gfw(base):
  81. def __init__(self, mqtt_client):
  82. self.floor = gfw_floor(mqtt_client)
  83. self.marion = gfw_marion(mqtt_client)
  84. self.dirk = gfw_dirk(mqtt_client)
  85. class ffw_julian(base):
  86. def __init__(self, mqtt_client):
  87. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, True, True, True)
  88. self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  89. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  90. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True)
  91. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  92. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  93. class ffw_livingroom(base):
  94. def __init__(self, mqtt_client):
  95. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, True, False, False)
  96. self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  97. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  98. class ffw(base):
  99. def __init__(self, mqtt_client):
  100. self.julian = ffw_julian(mqtt_client)
  101. self.livingroom = ffw_livingroom(mqtt_client)
  102. class ffe_floor(base):
  103. def __init__(self, mqtt_client):
  104. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI, True, False, False)
  105. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  106. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  107. class ffe_kitchen(base):
  108. def __init__(self, mqtt_client):
  109. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI, True, False, False)
  110. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  111. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  112. #
  113. self.gui_circulation_pump = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI, True, False, False)
  114. self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY,
  115. input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60)
  116. self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump")
  117. class ffe_diningroom(base):
  118. def __init__(self, mqtt_client):
  119. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI, True, False, False)
  120. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  121. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  122. self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI, True, False, False)
  123. self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  124. self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
  125. if config.CHRISTMAS:
  126. self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  127. self.garland.add_channel_name(silvercrest_powerplug, "Garland")
  128. class ffe_sleep(base):
  129. def __init__(self, mqtt_client):
  130. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, True, True, True)
  131. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  132. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  133. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
  134. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  135. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  136. #
  137. self.gui_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI, True, True, False)
  138. self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
  139. #
  140. self.input_device = tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  141. self.led_array = gui_led_array(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
  142. self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
  143. self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Bed Light Dirk")
  144. #
  145. self.radiator_valve = brennenstuhl_radiator_valve(mqtt_client, config.TOPIC_FFE_SLEEP_RADIATOR_VALVE_ZIGBEE)
  146. self.gui_radiator_valve = gui_radiator_valve(mqtt_client, config.TOPIC_FFE_SLEEP_RADIATOR_VALVE_GUI)
  147. class ffe_livingroom(base):
  148. def __init__(self, mqtt_client):
  149. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
  150. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  151. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  152. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
  153. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  154. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  155. for i in range(1, 7):
  156. setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True))
  157. self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI, True, True, True)
  158. if config.CHRISTMAS:
  159. self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  160. self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree")
  161. self.gui_xmas_tree = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
  162. self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  163. self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star")
  164. class ffe(base):
  165. def __init__(self, mqtt_client):
  166. self.floor = ffe_floor(mqtt_client)
  167. self.kitchen = ffe_kitchen(mqtt_client)
  168. self.diningroom = ffe_diningroom(mqtt_client)
  169. self.sleep = ffe_sleep(mqtt_client)
  170. self.livingroom = ffe_livingroom(mqtt_client)
  171. class stairway(base):
  172. def __init__(self, mqtt_client):
  173. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI, True, False, False)
  174. self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 0, "Motion Ground Floor")
  175. self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 1, "Motion First Floor")
  176. self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  177. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  178. self.motion_sensor_gf = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
  179. self.motion_sensor_ff = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
  180. class house(base):
  181. def __init__(self, mqtt_client):
  182. self.gfw = gfw(mqtt_client)
  183. self.ffw = ffw(mqtt_client)
  184. self.ffe = ffe(mqtt_client)
  185. self.stairway = stairway(mqtt_client)