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 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. from devdi import topic as props
  6. from devices import group
  7. from function.db import get_radiator_data, set_radiator_data
  8. from function.helpers import day_event
  9. from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
  10. from function.rooms import room, room_collection
  11. from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate
  12. import logging
  13. try:
  14. from config import APP_NAME as ROOT_LOGGER_NAME
  15. except ImportError:
  16. ROOT_LOGGER_NAME = 'root'
  17. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  18. loc = props.LOC_FFE
  19. class first_floor_east(room_collection):
  20. def __init__(self, mqtt_client, pd, vd):
  21. super().__init__(mqtt_client, pd, vd)
  22. self.dining = first_floor_east_dining(mqtt_client, pd, vd)
  23. self.floor = first_floor_east_floor(mqtt_client, pd, vd)
  24. self.kitchen = first_floor_east_kitchen(mqtt_client, pd, vd)
  25. self.livingroom = first_floor_east_living(mqtt_client, pd, vd)
  26. self.sleep = first_floor_east_sleep(mqtt_client, pd, vd)
  27. class first_floor_east_floor(room):
  28. def __init__(self, mqtt_client, pd, vd):
  29. roo = props.ROO_FLO
  30. #
  31. # Device initialisation
  32. #
  33. # http://shelly1l-3C6105E4E629
  34. # main light
  35. self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  36. super().__init__(mqtt_client, pd, vd)
  37. #
  38. # Virtual Device Interface
  39. #
  40. # main light
  41. self.main_light = videv_switching(
  42. mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
  43. self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
  44. )
  45. class first_floor_east_kitchen(room):
  46. def __init__(self, mqtt_client, pd, vd):
  47. roo = props.ROO_KIT
  48. #
  49. # Device initialisation
  50. #
  51. # http://shelly1l-8CAAB5616C01
  52. # main light
  53. self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  54. # http://shelly1-e89f6d85a466
  55. # circulation pump
  56. self.circulation_pump_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR)
  57. # heating function
  58. self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
  59. super().__init__(mqtt_client, pd, vd)
  60. #
  61. # Functionality initialisation
  62. #
  63. # circulation pump
  64. self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, self.circulation_pump_shelly.KEY_OUTPUT_0, 10*60)
  65. self.circulation_pump_shelly.add_callback(self.circulation_pump_shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
  66. # heating function
  67. self.heating_function = heating_function(
  68. self.heating_valve,
  69. config.DEFAULT_TEMPERATURE,
  70. **get_radiator_data(self.heating_valve.topic)
  71. )
  72. self.heating_function.add_callback(None, None, set_radiator_data, True)
  73. #
  74. # Virtual Device Interface
  75. #
  76. # main light
  77. self.main_light_videv = videv_switching(
  78. mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
  79. self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
  80. )
  81. # circulation pump
  82. self.circulation_pump_videv = videv_switching_timer(
  83. mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
  84. self.circulation_pump_shelly, self.circulation_pump_shelly.KEY_OUTPUT_0,
  85. self.circulation_pump, timer_on_activation.KEY_TIMER
  86. )
  87. # heating function
  88. self.heating_function_videv = videv_heating(
  89. mqtt_client, config.TOPIC_FFE_KITCHEN_HEATING_VALVE_VIDEV,
  90. self.heating_function
  91. )
  92. class first_floor_east_dining(room):
  93. def __init__(self, mqtt_client, pd, vd):
  94. roo = props.ROO_DIN
  95. #
  96. # Device initialisation
  97. #
  98. self.day_events = day_event((6, 0), (22, 0), 30, -30)
  99. # http://shelly1l-84CCA8ADD055
  100. # main light
  101. self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  102. # floor lamp
  103. self.floorlamp_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL)
  104. # heating function
  105. self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
  106. # garland
  107. if config.CHRISTMAS:
  108. self.garland_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_GAR)
  109. super().__init__(mqtt_client, pd, vd)
  110. #
  111. # Functionality initialisation
  112. #
  113. self.day_events.add_callback(None, True, self.__day_events__, True)
  114. # main light
  115. self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
  116. # heating function
  117. self.heating_function = heating_function(
  118. self.heating_valve,
  119. config.DEFAULT_TEMPERATURE,
  120. **get_radiator_data(self.heating_valve.topic)
  121. )
  122. self.heating_function.add_callback(None, None, set_radiator_data, True)
  123. #
  124. # Virtual Device Interface
  125. #
  126. # main light
  127. self.main_light_videv = videv_switching(
  128. mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
  129. self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0
  130. )
  131. # floor lamp
  132. self.floorlamp_videv = videv_switching(
  133. mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
  134. self.floorlamp_powerplug, self.floorlamp_powerplug.KEY_OUTPUT_0
  135. )
  136. # heating function
  137. self.heating_function_videv = videv_heating(
  138. mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV,
  139. self.heating_function
  140. )
  141. # garland
  142. if config.CHRISTMAS:
  143. self.garland_videv = videv_switching(
  144. mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
  145. self.garland_powerplug, self.garland_powerplug.KEY_OUTPUT_0
  146. )
  147. def __day_events__(self, device, key, data):
  148. if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
  149. if config.CHRISTMAS:
  150. self.garland_powerplug.set_output_0(True)
  151. elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
  152. if config.CHRISTMAS:
  153. self.garland_powerplug.set_output_0(False)
  154. class first_floor_east_sleep(room):
  155. def __init__(self, mqtt_client, pd, vd):
  156. roo = props.ROO_SLP
  157. #
  158. # Device initialisation
  159. #
  160. # http://shelly1l-E8DB84A254C7
  161. # main light
  162. self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  163. self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
  164. # bed light
  165. self.bed_light_di_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLD)
  166. self.bed_light_ma_powerplug = pd.get(props.STG_ZFE, loc, roo, props.FUN_BLM)
  167. # heating function
  168. self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
  169. # button
  170. self.button_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_INP)
  171. # wardrobe light
  172. self.wardrobe_light = pd.get(props.STG_ZFE, loc, roo, props.FUN_WLI)
  173. super().__init__(mqtt_client, pd, vd)
  174. #
  175. # Functionality initialisation
  176. #
  177. # button / brightness function
  178. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  179. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0)
  180. self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0)
  181. # button / main light
  182. self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_TOGGLE,
  183. self.main_light_shelly.toggle_output_0_mcb)
  184. # button / bed light
  185. self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT,
  186. self.bed_light_di_tradfri.toggle_output_0_mcb)
  187. self.button_tradfri.add_callback(self.button_tradfri.KEY_ACTION, self.button_tradfri.ACTION_LEFT_LONG,
  188. self.bed_light_ma_powerplug.toggle_output_0_mcb)
  189. # heating function
  190. self.heating_function = heating_function(
  191. self.heating_valve,
  192. config.DEFAULT_TEMPERATURE,
  193. **get_radiator_data(self.heating_valve.topic)
  194. )
  195. self.heating_function.add_callback(None, None, set_radiator_data, True)
  196. #
  197. # Virtual Device Interface
  198. #
  199. # main light
  200. self.main_light_videv = videv_switch_brightness_color_temp(
  201. mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
  202. self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
  203. self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
  204. self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
  205. )
  206. # bed light
  207. self.bed_light_di_videv = videv_switch_brightness(
  208. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
  209. self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_OUTPUT_0,
  210. self.bed_light_di_tradfri, self.bed_light_di_tradfri.KEY_BRIGHTNESS,
  211. )
  212. self.bed_light_ma_videv = videv_switching(
  213. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
  214. self.bed_light_ma_powerplug, self.bed_light_ma_powerplug.KEY_OUTPUT_0
  215. )
  216. # heating function
  217. self.heating_function_videv = videv_heating(
  218. mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV,
  219. self.heating_function
  220. )
  221. # button
  222. self.brightness_functions_device_videv = videv_multistate(
  223. mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  224. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
  225. )
  226. self.wardrobe_light_videv = videv_switch_brightness(
  227. mqtt_client, config.TOPIC_FFE_SLEEP_WARDROBE_LIGHT_VIDEV,
  228. self.wardrobe_light, self.wardrobe_light.KEY_OUTPUT_0,
  229. self.wardrobe_light, self.wardrobe_light.KEY_BRIGHTNESS,
  230. )
  231. class first_floor_east_living(room):
  232. def __init__(self, mqtt_client, pd, vd):
  233. roo = props.ROO_LIV
  234. #
  235. # Device initialisation
  236. #
  237. # http://shelly1l-3C6105E3F910
  238. # main light
  239. self.main_light_shelly = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  240. self.main_light_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
  241. # floor lamp
  242. self.floorlamp_tradfri = pd.get(props.STG_ZFE, loc, roo, props.FUN_FLL)
  243. # heating function
  244. self.heating_valve = pd.get(props.STG_ZFE, loc, roo, props.FUN_HEA)
  245. # xmas tree
  246. if config.CHRISTMAS:
  247. self.powerplug_xmas_tree = pd.get(props.STG_ZFE, loc, roo, props.FUN_XTR)
  248. self.powerplug_xmas_star = pd.get(props.STG_ZFE, loc, roo, props.FUN_XST)
  249. super().__init__(mqtt_client, pd, vd)
  250. #
  251. # Functionality initialisation
  252. #
  253. # floor lamp synchronisation with main_light
  254. self.main_light_shelly.add_callback(self.main_light_shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
  255. # heating function
  256. self.heating_function = heating_function(
  257. self.heating_valve,
  258. config.DEFAULT_TEMPERATURE,
  259. **get_radiator_data(self.heating_valve.topic)
  260. )
  261. self.heating_function.add_callback(None, None, set_radiator_data, True)
  262. #
  263. # Virtual Device Interface
  264. #
  265. # main light
  266. self.main_light_videv = videv_switch_brightness_color_temp(
  267. mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
  268. self.main_light_shelly, self.main_light_shelly.KEY_OUTPUT_0,
  269. self.main_light_tradfri, self.main_light_tradfri.KEY_BRIGHTNESS,
  270. self.main_light_tradfri, self.main_light_tradfri.KEY_COLOR_TEMP
  271. )
  272. # floor lamp
  273. self.floorlamp_videv = videv_switch_brightness_color_temp(
  274. mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
  275. self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_OUTPUT_0,
  276. self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_BRIGHTNESS,
  277. self.floorlamp_tradfri, self.floorlamp_tradfri.KEY_COLOR_TEMP
  278. )
  279. # heating function
  280. self.heating_function_videv = videv_heating(
  281. mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV,
  282. self.heating_function
  283. )
  284. # xmas tree
  285. if config.CHRISTMAS:
  286. self.xmas_tree_videv = videv_switching(
  287. mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
  288. self.powerplug_xmas_tree, self.powerplug_xmas_tree.KEY_OUTPUT_0
  289. )