Smarthome Functionen
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

rooms.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import logging
  5. import task
  6. try:
  7. from config import APP_NAME as ROOT_LOGGER_NAME
  8. except ImportError:
  9. ROOT_LOGGER_NAME = 'root'
  10. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  11. # TODO: all_off: getattr and identify switchable devices switch those off (default method of device)
  12. # - all devices are as attributes in the room class
  13. # - implement a all_off blacklist to be initialised while __init__
  14. # TODO: implement all off and user feedback method (all off save)
  15. class room(object):
  16. def __init__(self, mqtt_client):
  17. self.mqtt_client = mqtt_client
  18. #
  19. self.block_all_off = False
  20. self.last_flash_data = None
  21. try:
  22. self.delayed_task = task.delayed(.25, self.main_light_shelly.toggle_output_0_mcb, None, None, None)
  23. except AttributeError:
  24. logger.exception("Device self.main_light does not exist!")
  25. self.delayed_task = task.delayed(.25, self.__delayed_task_dummy__, None, None, None)
  26. def __delayed_task_dummy__(self, device, key, data):
  27. logger.exception("Device self.main_light does not exist!")
  28. def all_off(self, device=None, key=None, data=None):
  29. if not self.block_all_off:
  30. logger.info("Switching all off \"%s\"", type(self).__name__)
  31. try:
  32. self.main_light_shelly.set_output_0(False)
  33. self.main_light_shelly.set_output_1(False)
  34. except AttributeError:
  35. logger.exception("Device self.main_light does not exist!")
  36. self.block_all_off = False
  37. def all_off_feedback(self, device=None, key=None, data=None):
  38. logger.info("Flashing \"%s\" main light", type(self).__name__)
  39. if self.main_light_shelly.output_0 is False:
  40. try:
  41. self.main_light_shelly.set_output_0(True)
  42. except AttributeError:
  43. logger.exception("Device self.main_light does not exist!")
  44. self.block_all_off = True
  45. self.delayed_task.run()
  46. def flash_main_light(self, device, key, data):
  47. if self.last_flash_data != data and data is True:
  48. logger.info("Flashing \"%s\" main light", type(self).__name__)
  49. try:
  50. self.main_light_shelly.toggle_output_0_mcb(device, key, data)
  51. except AttributeError:
  52. logger.exception("Device self.main_light does not exist!")
  53. self.delayed_task.run()
  54. self.last_flash_data = data