Smarthome Functionen
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ground_floor_west.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. from function.modules import brightness_choose_n_action
  7. import logging
  8. from function.rooms import room_shelly, room_shelly_tradfri_light, room_shelly_silvercrest_light
  9. import task
  10. try:
  11. from config import APP_NAME as ROOT_LOGGER_NAME
  12. except ImportError:
  13. ROOT_LOGGER_NAME = 'root'
  14. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  15. class ground_floor_west_floor(room_shelly_silvercrest_light):
  16. # http://shelly1l-84CCA8AD1148
  17. def __init__(self, mqtt_client):
  18. super().__init__(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI_SWITCH,
  19. config.TOPIC_GFW_FLOOR_MAIN_LIGHT_A_ZIGBEE, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI_BR_CT)
  20. #
  21. # Callback initialisation
  22. #
  23. self.main_light_tradfri_2 = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_B_ZIGBEE)
  24. self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.main_light_tradfri_2.set_brightness_mcb)
  25. self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.main_light_tradfri_2.set_color_temp_mcb)
  26. def send_init_message_main_light(self):
  27. super().send_init_message_main_light()
  28. self.main_light_tradfri_2.mqtt_client.send(self.main_light_tradfri_2.topic + "/get", '{"state": ""}')
  29. class ground_floor_west_marion(room_shelly):
  30. # http://shelly1l-E8DB84A1E067
  31. def __init__(self, mqtt_client):
  32. super().__init__(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI_SWITCH)
  33. class ground_floor_west_dirk(room_shelly_tradfri_light):
  34. STATE_ACTIVE_DEVICE_MAIN_LIGHT = 0
  35. STATE_ACTIVE_DEVICE_DESK_LIGHT = 1
  36. STATE_ACTIVE_DEVICE_AMPLIFIER = 2
  37. STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
  38. #
  39. LED_ACTIVE_DEVICE_MAIN_LIGHT = devices.nodered_gui_leds.KEY_LED_0
  40. LED_ACTIVE_DEVICE_DESK_LIGHT = devices.nodered_gui_leds.KEY_LED_1
  41. LED_ACTIVE_DEVICE_AMPLIFIER = devices.nodered_gui_leds.KEY_LED_2
  42. #
  43. KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0
  44. KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2
  45. KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1
  46. KEY_POWERPLUG_PC_DOCK = devices.my_powerplug.KEY_OUTPUT_3
  47. #
  48. AUDIO_SOURCE_PC = 0
  49. AUDIO_SOURCE_CD = 1
  50. AUDIO_SOURCE_RASPI = 2
  51. # http://shelly1l-3C6105E44F27
  52. def __init__(self, mqtt_client):
  53. super().__init__(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI_SWITCH,
  54. config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI_BR_CT)
  55. #
  56. self.powerplug_common = devices.my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
  57. self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
  58. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
  59. #
  60. self.gui_switch_desk_light = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI_SWITCH)
  61. self.gui_br_cr_desk_light = devices.nodered_gui_brightness_color_temp(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI_BR_CT)
  62. #
  63. self.gui_switch_amplifier = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI_SWITCH)
  64. self.gui_switch_cd_player = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI_SWITCH)
  65. self.gui_switch_pc_dock = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI_SWITCH)
  66. #
  67. self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
  68. #
  69. self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
  70. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  71. self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
  72. self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
  73. #
  74. self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
  75. self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
  76. #
  77. self.delayed_task = task.delayed(1.0, self.send_audio_source)
  78. #
  79. # Callback initialisation
  80. #
  81. # main light
  82. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  83. self.main_light_shelly.toggle_output_0_mcb)
  84. # desk light
  85. # switch
  86. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT,
  87. self.powerplug_common.toggle_output_1_mcb)
  88. self.gui_switch_desk_light.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_1_mcb)
  89. self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_switch_desk_light.set_state_mcb)
  90. # brightness and color temp
  91. self.gui_br_cr_desk_light.add_callback(devices.nodered_gui_brightness_color_temp.KEY_BRIGHTNESS,
  92. None, self.desk_light_tradfri.set_brightness_mcb)
  93. self.gui_br_cr_desk_light.add_callback(devices.nodered_gui_brightness_color_temp.KEY_COLOR_TEMP,
  94. None, self.desk_light_tradfri.set_color_temp_mcb)
  95. self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_br_cr_desk_light.set_enable_mcb)
  96. self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_br_cr_desk_light.set_brightness_mcb)
  97. self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_br_cr_desk_light.set_color_temp_mcb)
  98. # amplifier
  99. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  100. self.powerplug_common.toggle_output_0_mcb)
  101. self.gui_switch_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
  102. self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_switch_amplifier.set_state_mcb)
  103. # amplifier auto on
  104. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.cd_amplifier_synchronisation, True)
  105. self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
  106. self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.raspi_amplifier_synchronisation, True)
  107. # audio source
  108. self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
  109. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
  110. self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
  111. self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
  112. self.audio_source = self.AUDIO_SOURCE_PC
  113. # cd player
  114. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG,
  115. self.powerplug_common.toggle_output_2_mcb)
  116. self.gui_switch_cd_player.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_2_mcb)
  117. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.gui_switch_cd_player.set_state_mcb)
  118. # pc dock
  119. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  120. self.powerplug_common.toggle_output_3_mcb)
  121. self.gui_switch_pc_dock.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_3_mcb)
  122. self.powerplug_common.add_callback(self.KEY_POWERPLUG_PC_DOCK, None, self.gui_switch_pc_dock.set_state_mcb)
  123. def all_off(self, device=None, key=None, data=None):
  124. super().all_off(device, key, data)
  125. self.powerplug_common.set_output_all(False)
  126. def cd_amplifier_synchronisation(self, device, key, data):
  127. logger.info("Syncing \"%s\" amplifier with cd player: %s", type(self).__name__, data)
  128. self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
  129. def raspi_amplifier_synchronisation(self, device, key, data):
  130. logger.info("Syncing \"%s\" amplifier with raspi player: %s", type(self).__name__, data)
  131. self.powerplug_common.set_output(self.KEY_POWERPLUG_AMPLIFIER, data)
  132. def audio_source_selector(self, device, key, data):
  133. if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
  134. # switch on of cd player
  135. self.audio_source = self.AUDIO_SOURCE_CD
  136. elif device in [self.spotify_state, self.mpd_state]:
  137. # switch on raspi-source
  138. self.audio_source = self.AUDIO_SOURCE_RASPI
  139. elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
  140. # switch on of amplifier -> select source and reset stored source value
  141. self.delayed_task.run()
  142. def send_audio_source(self):
  143. if self.audio_source == self.AUDIO_SOURCE_PC:
  144. logger.info("Sending IR command to change audio source to pc")
  145. self.remote_amplifier.set_line3()
  146. elif self.audio_source == self.AUDIO_SOURCE_CD:
  147. logger.info("Sending IR command to change audio source to cd")
  148. self.remote_amplifier.set_cd()
  149. elif self.audio_source == self.AUDIO_SOURCE_RASPI:
  150. logger.info("Sending IR command to change audio source to raspi")
  151. self.remote_amplifier.set_line1()
  152. self.audio_source = self.AUDIO_SOURCE_PC