Smarthome Functionen
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

rooms.py 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. import config
  2. from __simulation__.devices import shelly, silvercrest_powerplug, tradfri_light, tradfri_button, silvercrest_motion_sensor, my_powerplug, remote, brennenstuhl_heating_valve
  3. from __simulation__.devices import gui_light, gui_led_array, gui_heating_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_ZIGBEE % 1, 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_ZIGBEE % 2, 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. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
  52. self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_GUI)
  53. class gfw_dirk(base):
  54. def __init__(self, mqtt_client):
  55. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI, True, True, True)
  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, "on")
  60. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  61. #
  62. self.powerplug = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
  63. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
  64. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_1, "Desk_Light")
  65. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_2, "CD_Player")
  66. self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_3, "PC_Dock")
  67. self.gui_amplifier = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI, True, False, False)
  68. self.gui_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI, True, True, True)
  69. self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
  70. self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_on, True)
  71. self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_off, False)
  72. self.gui_cd_player = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI, True, False, False)
  73. self.gui_pc_dock = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI, True, False, False)
  74. #
  75. self.remote = remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
  76. #
  77. self.input_device = tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
  78. self.led_array = gui_led_array(mqtt_client, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
  79. self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
  80. self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Desk Light")
  81. self.led_array.add_channel_name(gui_led_array.KEY_LED_2, "Amplifier")
  82. #
  83. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
  84. self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_GUI)
  85. class gfw(base):
  86. def __init__(self, mqtt_client):
  87. self.floor = gfw_floor(mqtt_client)
  88. self.marion = gfw_marion(mqtt_client)
  89. self.dirk = gfw_dirk(mqtt_client)
  90. class ffw_julian(base):
  91. def __init__(self, mqtt_client):
  92. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, True, True, True)
  93. self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  94. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  95. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True)
  96. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  97. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  98. class ffw_livingroom(base):
  99. def __init__(self, mqtt_client):
  100. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
  101. self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  102. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  103. class ffw_sleep(base):
  104. def __init__(self, mqtt_client):
  105. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_GUI, True, True, False)
  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. class ffw_bath(base):
  109. def __init__(self, mqtt_client):
  110. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)
  111. self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_GUI)
  112. class ffw(base):
  113. def __init__(self, mqtt_client):
  114. self.julian = ffw_julian(mqtt_client)
  115. self.livingroom = ffw_livingroom(mqtt_client)
  116. self.sleep = ffw_sleep(mqtt_client)
  117. self.bath = ffw_bath(mqtt_client)
  118. class ffe_floor(base):
  119. def __init__(self, mqtt_client):
  120. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI, True, False, False)
  121. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  122. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  123. class ffe_kitchen(base):
  124. def __init__(self, mqtt_client):
  125. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI, True, False, False)
  126. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_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.gui_circulation_pump = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI, True, False, False)
  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. class ffe_diningroom(base):
  134. def __init__(self, mqtt_client):
  135. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI, True, False, False)
  136. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  137. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  138. self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI, True, False, False)
  139. self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  140. self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
  141. if config.CHRISTMAS:
  142. self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  143. self.garland.add_channel_name(silvercrest_powerplug, "Garland")
  144. class ffe_sleep(base):
  145. def __init__(self, mqtt_client):
  146. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, True, True, True)
  147. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  148. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  149. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
  150. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  151. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  152. #
  153. self.gui_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI, True, True, False)
  154. self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
  155. self.gui_bed_light_ma = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_GUI, True, False, False)
  156. self.bed_light_ma_powerplug = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  157. #
  158. self.input_device = tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  159. self.led_array = gui_led_array(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
  160. self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
  161. self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Bed Light Dirk")
  162. #
  163. self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
  164. self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_GUI)
  165. class ffe_livingroom(base):
  166. def __init__(self, mqtt_client):
  167. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
  168. self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
  169. self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
  170. self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
  171. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
  172. self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
  173. for i in range(1, 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. self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI, True, True, True)
  176. if config.CHRISTMAS:
  177. self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  178. self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree")
  179. self.gui_xmas_tree = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
  180. self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  181. self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star")
  182. class ffe(base):
  183. def __init__(self, mqtt_client):
  184. self.floor = ffe_floor(mqtt_client)
  185. self.kitchen = ffe_kitchen(mqtt_client)
  186. self.diningroom = ffe_diningroom(mqtt_client)
  187. self.sleep = ffe_sleep(mqtt_client)
  188. self.livingroom = ffe_livingroom(mqtt_client)
  189. class stairway(base):
  190. def __init__(self, mqtt_client):
  191. self.gui_main_light = gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI, True, False, False)
  192. self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 0, "Motion Ground Floor")
  193. self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 1, "Motion First Floor")
  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. self.motion_sensor_gf = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
  197. self.motion_sensor_ff = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
  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)