Test Smart Brain implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rooms.py 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import config
  2. from simulation.devices import shelly, silvercrest_powerplug, tradfri_light, my_powerplug, brennenstuhl_heating_valve
  3. from simulation.devices import videv_light, videv_heating, videv_warnings
  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.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  38. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  39. self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1, True, True, True, False)
  40. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee_1.power_on)
  41. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee_1.power_off)
  42. self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2, True, True, True, False)
  43. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee_2.power_on)
  44. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee_2.power_off)
  45. #
  46. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV, True, True, True)
  47. class gfw_marion(base):
  48. def __init__(self, mqtt_client):
  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. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
  52. #
  53. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV, True, False, False)
  54. self.videv_heating = videv_heating(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_VIDEV)
  55. class gfw_dirk(base):
  56. def __init__(self, mqtt_client):
  57. self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  58. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  59. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True)
  60. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on)
  61. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off)
  62. self.amplifier = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 0)
  63. self.amplifier.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
  64. self.desk_light = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 1)
  65. self.desk_light.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Desk Light")
  66. self.cd_player = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 2)
  67. self.cd_player.add_channel_name(my_powerplug.KEY_OUTPUT_0, "CD_Player")
  68. self.pc_dock = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 3)
  69. self.pc_dock.add_channel_name(my_powerplug.KEY_OUTPUT_0, "PC_Dock")
  70. self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
  71. self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, True, self.desk_light_zigbee.power_on)
  72. self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, False, self.desk_light_zigbee.power_off)
  73. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
  74. #
  75. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV, True, True, True)
  76. self.videv_amplifier = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV, True, False, False)
  77. self.videv_desk_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV, True, True, True)
  78. self.videv_cd_player = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV, True, False, False)
  79. self.videv_pc_dock = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV, True, False, False)
  80. self.videv_heating = videv_heating(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV)
  81. class gfw(base):
  82. def __init__(self, mqtt_client):
  83. self.floor = gfw_floor(mqtt_client)
  84. self.marion = gfw_marion(mqtt_client)
  85. self.dirk = gfw_dirk(mqtt_client)
  86. class ffw_julian(base):
  87. def __init__(self, mqtt_client):
  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, True, self.main_light_zigbee.power_on)
  92. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off)
  93. #
  94. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV, True, True, True)
  95. class ffw_livingroom(base):
  96. def __init__(self, mqtt_client):
  97. self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  98. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  99. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
  100. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on)
  101. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off)
  102. #
  103. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True)
  104. class ffw_sleep(base):
  105. def __init__(self, mqtt_client):
  106. self.main_light = shelly(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  107. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  108. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
  109. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on)
  110. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off)
  111. #
  112. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV, True, True, False)
  113. class ffw_bath(base):
  114. def __init__(self, mqtt_client):
  115. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)
  116. #
  117. self.videv_heating = videv_heating(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_VIDEV)
  118. class ffw(base):
  119. def __init__(self, mqtt_client):
  120. self.julian = ffw_julian(mqtt_client)
  121. self.livingroom = ffw_livingroom(mqtt_client)
  122. self.sleep = ffw_sleep(mqtt_client)
  123. self.bath = ffw_bath(mqtt_client)
  124. class ffe_floor(base):
  125. def __init__(self, mqtt_client):
  126. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  127. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  128. #
  129. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, True, False, False)
  130. class ffe_kitchen(base):
  131. def __init__(self, mqtt_client):
  132. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  133. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  134. self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY,
  135. input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60)
  136. self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump")
  137. #
  138. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV, True, False, False)
  139. self.videv_circulation_pump = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV, True, False, False, True)
  140. class ffe_diningroom(base):
  141. def __init__(self, mqtt_client):
  142. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  143. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  144. self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  145. self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
  146. if config.CHRISTMAS:
  147. self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  148. self.garland.add_channel_name(silvercrest_powerplug, "Garland")
  149. #
  150. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, True, False, False)
  151. self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV, True, False, False)
  152. if config.CHRISTMAS:
  153. self.videv_garland = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV, True, False, False)
  154. class ffe_sleep(base):
  155. def __init__(self, mqtt_client):
  156. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  157. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  158. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
  159. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on)
  160. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off)
  161. self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
  162. self.bed_light_ma = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  163. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
  164. #
  165. self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False)
  166. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV, True, True, True)
  167. self.videv_bed_light_di = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, True, True, False)
  168. self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False)
  169. self.videv_heating = videv_heating(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV)
  170. class ffe_livingroom(base):
  171. def __init__(self, mqtt_client):
  172. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  173. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  174. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
  175. self.main_light.add_callback(shelly.KEY_OUTPUT_0, True, self.main_light_zigbee.power_on)
  176. self.main_light.add_callback(shelly.KEY_OUTPUT_0, False, self.main_light_zigbee.power_off)
  177. for i in range(1, 7):
  178. setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True))
  179. if config.CHRISTMAS:
  180. self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  181. self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree")
  182. self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  183. self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star")
  184. #
  185. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True)
  186. self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV, True, True, True)
  187. if config.CHRISTMAS:
  188. self.videv_xmas_tree = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV)
  189. class ffe(base):
  190. def __init__(self, mqtt_client):
  191. self.floor = ffe_floor(mqtt_client)
  192. self.kitchen = ffe_kitchen(mqtt_client)
  193. self.diningroom = ffe_diningroom(mqtt_client)
  194. self.sleep = ffe_sleep(mqtt_client)
  195. self.livingroom = ffe_livingroom(mqtt_client)
  196. class stairway(base):
  197. def __init__(self, mqtt_client):
  198. self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  199. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  200. #
  201. self.videv_main_light = videv_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV, True, False, False, True)
  202. class house(base):
  203. def __init__(self, mqtt_client):
  204. self.gfw = gfw(mqtt_client)
  205. self.ffw = ffw(mqtt_client)
  206. self.ffe = ffe(mqtt_client)
  207. self.stairway = stairway(mqtt_client)
  208. self.warnings = videv_warnings(mqtt_client, config.TOPIC_WARNINGS)