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.

__init__.py 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. from function.stairway import stairway
  7. from function.ground_floor_west import ground_floor_west
  8. from function.first_floor_west import first_floor_west
  9. from function.first_floor_east import first_floor_east
  10. from function.rooms import room_collection
  11. from function.videv import all_off
  12. import inspect
  13. import logging
  14. try:
  15. from config import APP_NAME as ROOT_LOGGER_NAME
  16. except ImportError:
  17. ROOT_LOGGER_NAME = 'root'
  18. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  19. # TODO: implement garland (incl. day events like sunset, sunrise, ...)
  20. # TODO: implement warning message
  21. class all_functions(room_collection):
  22. def __init__(self, mqtt_client):
  23. super().__init__(mqtt_client)
  24. #
  25. # Rooms
  26. #
  27. # stairway
  28. self.stw = stairway(self.mqtt_client)
  29. # ground floor west
  30. self.gfw = ground_floor_west(self.mqtt_client)
  31. # first floor west
  32. self.ffw = first_floor_west(self.mqtt_client)
  33. # first floor east
  34. self.ffe = first_floor_east(self.mqtt_client)
  35. #
  36. # Interactions
  37. #
  38. # cross_room_interactions
  39. self.init_cross_room_interactions()
  40. # Off Buttons
  41. self.init_off_functionality()
  42. def init_cross_room_interactions(self):
  43. # shelly dirk input 1
  44. self.last_gfw_dirk_input_1 = None
  45. self.gfw.dirk.main_light_shelly.add_callback(devices.shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
  46. # tradfri button ffe_sleep right click
  47. self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION,
  48. devices.tradfri_button.ACTION_RIGHT, self.ffe.floor.main_light_shelly.toggle_output_0_mcb)
  49. def init_off_functionality(self):
  50. # ALL OFF - Virtual device
  51. self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
  52. # ALL OFF - Long push stairway
  53. self.stw.stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.stw.stairway.main_light_shelly.flash_0_mcb)
  54. self.stw.stairway.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.all_off)
  55. # FFE ALL OFF - Long push ffe_floor
  56. self.ffe.floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe.floor.main_light_shelly.flash_0_mcb)
  57. self.ffe.floor.main_light_shelly.add_callback(devices.shelly.KEY_LONGPUSH_0, True, self.ffe.all_off)
  58. # FFE ALL OFF - Long push input device
  59. self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
  60. def gfw_dirk_input_1(self, device, key, data):
  61. if self.last_gfw_dirk_input_1 is not None:
  62. if self.last_gfw_dirk_input_1 != data:
  63. self.gfw.floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
  64. self.last_gfw_dirk_input_1 = data