123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
-
- import logging
- import inspect
-
- try:
- from config import APP_NAME as ROOT_LOGGER_NAME
- except ImportError:
- ROOT_LOGGER_NAME = 'root'
- logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
-
-
- class room(object):
- def __init__(self, mqtt_client):
- self.mqtt_client = mqtt_client
-
- def all_off(self, device=None, key=None, data=None):
- logger.info("Switching all off \"%s\"", type(self).__name__)
- for name, obj in inspect.getmembers(self):
- try:
- if obj.__module__ == 'devices':
- obj.all_off()
- except AttributeError:
- pass # not a module or has no method all_off
-
-
- class room_collection(object):
- ALLOWED_CLASSES = ("room", "room_collection")
-
- def __init__(self, mqtt_client):
- self.mqtt_client = mqtt_client
-
- def all_off(self, device=None, key=None, data=None):
- logger.info("Switching all off \"%s\"", type(self).__name__)
- for sub_name in dir(self):
- # attribute name is not private
- if not sub_name.startswith("__"):
- sub = getattr(self, sub_name)
- if sub.__class__.__bases__[0].__name__ in self.ALLOWED_CLASSES:
- sub.all_off()
|