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

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