Smarthome Functionen
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

first_floor_east.py 11KB

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