Smarthome Functionen
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

__init__.py 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, videv_warnings
  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. class all_functions(room_collection):
  19. def __init__(self, mqtt_client, pd, vd):
  20. super().__init__(mqtt_client, pd, vd)
  21. #
  22. # Rooms
  23. #
  24. # stairway
  25. self.stw = stairway(self.mqtt_client, pd, vd)
  26. # ground floor west
  27. self.gfw = ground_floor_west(self.mqtt_client, pd, vd)
  28. # first floor west
  29. self.ffw = first_floor_west(self.mqtt_client, pd, vd)
  30. # first floor east
  31. self.ffe = first_floor_east(self.mqtt_client, pd, vd)
  32. #
  33. # Interactions
  34. #
  35. # cross_room_interactions
  36. self.init_cross_room_interactions()
  37. # Off Buttons
  38. self.init_off_functionality()
  39. # Warnings
  40. videv_warning = videv_warnings(self.mqtt_client, config.TOPIC_WARNINGS)
  41. for device in self.all_devices():
  42. device.add_callback(devices.base.base.KEY_WARNING, None, videv_warning.warningcollector)
  43. def init_cross_room_interactions(self):
  44. # shelly dirk input 1
  45. self.last_gfw_dirk_input_1 = None
  46. self.gfw.dirk.main_light_shelly.add_callback(self.gfw.dirk.main_light_shelly.KEY_INPUT_1, None, self.gfw_dirk_input_1)
  47. # tradfri button ffe_sleep right click
  48. self.ffe.sleep.button_tradfri.add_callback(self.ffe.sleep.button_tradfri.KEY_ACTION,
  49. self.ffe.sleep.button_tradfri.ACTION_RIGHT,
  50. self.ffe.floor.main_light_shelly.toggle_output_0_mcb)
  51. def init_off_functionality(self):
  52. # ALL OFF - Virtual device
  53. self.videv_all_off = all_off(self.mqtt_client, config.TOPIC_ALL_OFF_VIDEV, self)
  54. # ALL OFF - Long push stairway
  55. self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0,
  56. True, self.stw.stairway.main_light_shelly.flash_0_mcb)
  57. self.stw.stairway.main_light_shelly.add_callback(self.stw.stairway.main_light_shelly.KEY_LONGPUSH_0, True, self.all_off)
  58. # FFE ALL OFF - Long push ffe_floor
  59. self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0,
  60. True, self.ffe.floor.main_light_shelly.flash_0_mcb)
  61. self.ffe.floor.main_light_shelly.add_callback(self.ffe.floor.main_light_shelly.KEY_LONGPUSH_0, True, self.ffe.all_off)
  62. # FFE ALL OFF - Long push input device
  63. self.ffe.sleep.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG, self.ffe.all_off)
  64. def gfw_dirk_input_1(self, device, key, data):
  65. if self.last_gfw_dirk_input_1 is not None:
  66. if self.last_gfw_dirk_input_1 != data:
  67. self.gfw.floor.main_light_shelly.toggle_output_0_mcb(device, key, data)
  68. self.last_gfw_dirk_input_1 = data