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.

rooms.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import logging
  5. import inspect
  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. class room(object):
  12. def __init__(self, mqtt_client):
  13. self.mqtt_client = mqtt_client
  14. def all_off(self, device=None, key=None, data=None):
  15. logger.info("Switching all off \"%s\"", type(self).__name__)
  16. for name, obj in inspect.getmembers(self):
  17. try:
  18. if obj.__module__ == 'devices':
  19. obj.all_off()
  20. except AttributeError:
  21. pass # not a module or has no method all_off
  22. class room_collection(object):
  23. ALLOWED_CLASSES = ("room", "room_collection")
  24. def __init__(self, mqtt_client):
  25. self.mqtt_client = mqtt_client
  26. def all_off(self, device=None, key=None, data=None):
  27. logger.info("Switching all off \"%s\"", type(self).__name__)
  28. for sub_name in dir(self):
  29. # attribute name is not private
  30. if not sub_name.startswith("__"):
  31. sub = getattr(self, sub_name)
  32. if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES:
  33. sub.all_off()