Smarthome Functionen
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

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