Smarthome Functionen
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ground_floor_west.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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, heating_function, switched_light
  7. from function.rooms import room
  8. from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate, videv_audio_player
  9. import logging
  10. import task
  11. try:
  12. from config import APP_NAME as ROOT_LOGGER_NAME
  13. except ImportError:
  14. ROOT_LOGGER_NAME = 'root'
  15. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  16. class ground_floor_west_floor(room):
  17. def __init__(self, mqtt_client):
  18. #
  19. # Device initialisation
  20. #
  21. # http://shelly1l-84CCA8AD1148
  22. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY)
  23. self.main_light_tradfri = devices.group(
  24. devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1),
  25. devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2)
  26. )
  27. super().__init__(mqtt_client)
  28. #
  29. # Functionality initialisation
  30. #
  31. # Request silvercrest data of lead light after power on
  32. switched_light(self.main_light_shelly, devices.shelly.KEY_OUTPUT_0, self.main_light_tradfri)
  33. #
  34. # Virtual Device Interface
  35. #
  36. self.main_light_videv = videv_switch_brightness_color_temp(
  37. mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV,
  38. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  39. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  40. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  41. )
  42. class ground_floor_west_marion(room):
  43. def __init__(self, mqtt_client):
  44. #
  45. # Device initialisation
  46. #
  47. # http://shelly1l-E8DB84A1E067
  48. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY)
  49. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
  50. super().__init__(mqtt_client)
  51. #
  52. # Functionality initialisation
  53. #
  54. # heating function
  55. self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_MARION)
  56. #
  57. # Virtual Device Interface
  58. #
  59. self.main_light_videv = videv_switching(
  60. mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV,
  61. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  62. )
  63. self.heating_function_videv = videv_heating(
  64. mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_VIDEV,
  65. self.heating_function
  66. )
  67. class ground_floor_west_dirk(room):
  68. STATE_ACTIVE_DEVICE_MAIN_LIGHT = 0
  69. STATE_ACTIVE_DEVICE_DESK_LIGHT = 1
  70. STATE_ACTIVE_DEVICE_AMPLIFIER = 2
  71. STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
  72. #
  73. KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0
  74. KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2
  75. KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1
  76. KEY_POWERPLUG_PC_DOCK = devices.my_powerplug.KEY_OUTPUT_3
  77. #
  78. AUDIO_SOURCE_PC = 0
  79. AUDIO_SOURCE_CD = 1
  80. AUDIO_SOURCE_RASPI = 2
  81. def __init__(self, mqtt_client):
  82. #
  83. # Device initialisation
  84. #
  85. # http://shelly1l-3C6105E44F27
  86. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY)
  87. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)
  88. self.powerplug_common = devices.my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
  89. self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
  90. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
  91. self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
  92. self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
  93. self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
  94. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
  95. super().__init__(mqtt_client)
  96. #
  97. # Functionality initialisation
  98. #
  99. # Button - Brightness functionality
  100. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  101. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  102. self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
  103. self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
  104. # Button - Main light
  105. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  106. self.main_light_shelly.toggle_output_0_mcb)
  107. # Button - Desk light
  108. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT,
  109. self.powerplug_common.toggle_output_1_mcb)
  110. # Button - Amplifier
  111. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  112. self.powerplug_common.toggle_output_0_mcb)
  113. # Button - 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. # Button - PC dock
  117. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  118. self.powerplug_common.toggle_output_3_mcb)
  119. # Mediaplayer - Amplifier auto on
  120. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
  121. self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
  122. self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
  123. # Mediaplayer - Audio source selection
  124. self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
  125. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
  126. self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
  127. self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
  128. self.audio_source = self.AUDIO_SOURCE_PC
  129. # heating function
  130. self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_DIRK)
  131. #
  132. # Virtual Device Interface
  133. #
  134. self.main_light_videv = videv_switch_brightness_color_temp(
  135. mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV,
  136. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  137. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  138. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  139. )
  140. self.desk_light_videv = videv_switch_brightness_color_temp(
  141. mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV,
  142. self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT,
  143. self.desk_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  144. self.desk_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  145. )
  146. self.amplifier_videv = videv_switching(
  147. mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV,
  148. self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER
  149. )
  150. self.cd_player_videv = videv_switching(
  151. mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV,
  152. self.powerplug_common, self.KEY_POWERPLUG_CD_PLAYER
  153. )
  154. self.pc_dock_videv = videv_switching(
  155. mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV,
  156. self.powerplug_common, self.KEY_POWERPLUG_PC_DOCK
  157. )
  158. self.heating_function_videv = videv_heating(
  159. mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV,
  160. self.heating_function
  161. )
  162. self.brightness_functions_device_videv = videv_multistate(
  163. mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  164. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 3
  165. )
  166. self.audio_player_videv = videv_audio_player(
  167. mqtt_client, config.TOPIC_GFW_DIRK_AUDIO_PLAYER_VIDEV,
  168. self.spotify_state, self.mpd_state
  169. )
  170. #
  171. # Other stuff
  172. #
  173. self.delayed_task_remote = task.delayed(1.0, self.send_audio_source)
  174. def audio_source_selector(self, device, key, data):
  175. if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
  176. # switch on of cd player
  177. self.audio_source = self.AUDIO_SOURCE_CD
  178. elif device in [self.spotify_state, self.mpd_state]:
  179. # switch on raspi-source
  180. self.audio_source = self.AUDIO_SOURCE_RASPI
  181. elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
  182. # switch on of amplifier -> select source and reset stored source value
  183. self.delayed_task_remote.run()
  184. def send_audio_source(self):
  185. if self.audio_source == self.AUDIO_SOURCE_PC:
  186. logger.info("Sending IR command to change audio source to pc")
  187. self.remote_amplifier.set_line3()
  188. elif self.audio_source == self.AUDIO_SOURCE_CD:
  189. logger.info("Sending IR command to change audio source to cd")
  190. self.remote_amplifier.set_cd()
  191. elif self.audio_source == self.AUDIO_SOURCE_RASPI:
  192. logger.info("Sending IR command to change audio source to raspi")
  193. self.remote_amplifier.set_line1()
  194. self.audio_source = self.AUDIO_SOURCE_PC