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

first_floor_east.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. from function.helpers import day_event
  7. from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
  8. from function.rooms import room, room_collection
  9. from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate
  10. import logging
  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 first_floor_east(room_collection):
  17. def __init__(self, mqtt_client):
  18. super().__init__(mqtt_client)
  19. self.dining = first_floor_east_dining(mqtt_client)
  20. self.floor = first_floor_east_floor(mqtt_client)
  21. self.kitchen = first_floor_east_kitchen(mqtt_client)
  22. self.livingroom = first_floor_east_living(mqtt_client)
  23. self.sleep = first_floor_east_sleep(mqtt_client)
  24. class first_floor_east_floor(room):
  25. def __init__(self, mqtt_client):
  26. #
  27. # Device initialisation
  28. #
  29. # http://shelly1l-3C6105E4E629
  30. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)
  31. super().__init__(mqtt_client)
  32. #
  33. # Virtual Device Interface
  34. #
  35. self.main_light = videv_switching(
  36. mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
  37. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  38. )
  39. class first_floor_east_kitchen(room):
  40. def __init__(self, mqtt_client):
  41. #
  42. # Device initialisation
  43. #
  44. # http://shelly1l-8CAAB5616C01
  45. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)
  46. # http://shelly1-e89f6d85a466/
  47. self.circulation_pump_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)
  48. super().__init__(mqtt_client)
  49. #
  50. # Functionality initialisation
  51. #
  52. self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
  53. self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
  54. #
  55. # Virtual Device Interface
  56. #
  57. self.main_light_videv = videv_switching(
  58. mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
  59. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  60. )
  61. self.circulation_pump_videv = videv_switching_timer(
  62. mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
  63. self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0,
  64. self.circulation_pump, timer_on_activation.KEY_TIMER
  65. )
  66. class first_floor_east_dining(room):
  67. def __init__(self, mqtt_client):
  68. #
  69. # Device initialisation
  70. #
  71. self.day_events = day_event((6, 0), (22, 0), 30, -30)
  72. # http://shelly1l-84CCA8ADD055
  73. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)
  74. self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  75. if config.CHRISTMAS:
  76. self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  77. super().__init__(mqtt_client)
  78. #
  79. # Functionality initialisation
  80. #
  81. self.day_events.add_callback(None, True, self.__day_events__, True)
  82. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
  83. #
  84. # Virtual Device Interface
  85. #
  86. self.main_light_videv = videv_switching(
  87. mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
  88. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  89. )
  90. self.floorlamp_videv = videv_switching(
  91. mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
  92. self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  93. )
  94. if config.CHRISTMAS:
  95. self.garland_videv = videv_switching(
  96. mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
  97. self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  98. )
  99. def __day_events__(self, device, key, data):
  100. if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
  101. if config.CHRISTMAS:
  102. self.garland_powerplug.set_output_0(True)
  103. elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
  104. if config.CHRISTMAS:
  105. self.garland_powerplug.set_output_0(False)
  106. class first_floor_east_sleep(room):
  107. def __init__(self, mqtt_client):
  108. #
  109. # Device initialisation
  110. #
  111. # http://shelly1l-E8DB84A254C7
  112. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)
  113. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
  114. self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
  115. self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  116. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
  117. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  118. super().__init__(mqtt_client)
  119. #
  120. # Functionality initialisation
  121. #
  122. # button / brightness function
  123. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  124. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  125. self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
  126. # button / main light
  127. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  128. self.main_light_shelly.toggle_output_0_mcb)
  129. # button / bed light
  130. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  131. self.bed_light_di_tradfri.toggle_output_0_mcb)
  132. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  133. self.bed_light_ma_powerplug.toggle_output_0_mcb)
  134. # heating function
  135. self.heating_function = heating_function(self.heating_valve)
  136. #
  137. # Virtual Device Interface
  138. #
  139. self.main_light_videv = videv_switch_brightness_color_temp(
  140. mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
  141. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  142. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  143. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  144. )
  145. self.bed_light_di_videv = videv_switch_brightness(
  146. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
  147. self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  148. self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  149. )
  150. self.bed_light_ma_videv = videv_switching(
  151. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
  152. self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  153. )
  154. self.heating_function_videv = videv_heating(
  155. mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV,
  156. self.heating_function
  157. )
  158. self.brightness_functions_device_videv = videv_multistate(
  159. mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  160. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
  161. )
  162. class first_floor_east_living(room):
  163. def __init__(self, mqtt_client):
  164. #
  165. # Device initialisation
  166. #
  167. # http://shelly1l-3C6105E3F910
  168. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)
  169. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
  170. self.floorlamp_tradfri = devices.group(
  171. *[devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i) for i in range(1, 7)])
  172. if config.CHRISTMAS:
  173. self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  174. self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  175. super().__init__(mqtt_client)
  176. #
  177. # Functionality initialisation
  178. #
  179. # floor lamp synchronisation with main_light
  180. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
  181. #
  182. # Virtual Device Interface
  183. #
  184. self.main_light_videv = videv_switch_brightness_color_temp(
  185. mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
  186. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  187. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  188. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  189. )
  190. self.floorlamp_videv = videv_switch_brightness_color_temp(
  191. mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
  192. self.floorlamp_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  193. self.floorlamp_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  194. self.floorlamp_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  195. )
  196. if config.CHRISTMAS:
  197. self.xmas_tree_videv = videv_switching(
  198. mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
  199. self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
  200. )