Преглед изворни кода

all off improved

tags/v1.0.0
Dirk Alders пре 1 година
родитељ
комит
d4c5411d47
2 измењених фајлова са 11 додато и 32 уклоњено
  1. 4
    22
      function/__init__.py
  2. 7
    10
      function/rooms.py

+ 4
- 22
function/__init__.py Прегледај датотеку

@@ -98,11 +98,6 @@ class all_functions(object):
98 98
                 rv.append(obj)
99 99
         return rv
100 100
 
101
-    def common_off(self, device=None, key=None, data=None):
102
-        logger.info("Switching \"common\" off.")
103
-        for common in self.getmembers('common'):
104
-            common.all_off()
105
-
106 101
     def gfw_off(self, device=None, key=None, data=None):
107 102
         logger.info("Switching \"ground floor west\" off.")
108 103
         for gfw in self.getmembers('gfw'):
@@ -124,20 +119,7 @@ class all_functions(object):
124 119
             stw.all_off()
125 120
 
126 121
     def all_off(self, device=None, key=None, data=None):
127
-        self.common_off(device, key, data)
128
-        self.gfw_off(device, key, data)
129
-        self.ffw_off(device, key, data)
130
-        self.ffe_off(device, key, data)
131
-        self.stw_off(device, key, data)
132
-
133
-    def devicelist(self):
134
-        if self.__devices__ is None:
135
-            self.__devices__ = []
136
-            for name, obj in inspect.getmembers(self):
137
-                if obj.__class__.__module__ == "devices":
138
-                    self.__devices__.append(obj)
139
-                elif obj.__class__.__module__.split('.')[0] == 'function':
140
-                    for devicename, device in inspect.getmembers(obj):
141
-                        if device.__class__.__module__ == "devices":
142
-                            self.__devices__.append(device)
143
-        return self.__devices__
122
+        for name, obj in inspect.getmembers(self):
123
+            parent_name = obj.__class__.__base__.__name__
124
+            if parent_name == "room":
125
+                obj.all_off()

+ 7
- 10
function/rooms.py Прегледај датотеку

@@ -3,7 +3,7 @@
3 3
 #
4 4
 
5 5
 import logging
6
-import task
6
+import inspect
7 7
 
8 8
 try:
9 9
     from config import APP_NAME as ROOT_LOGGER_NAME
@@ -11,11 +11,6 @@ except ImportError:
11 11
     ROOT_LOGGER_NAME = 'root'
12 12
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
13 13
 
14
-# TODO: all_off: getattr and identify switchable devices switch those off (default method of device)
15
-#        - all devices are as attributes in the room class
16
-#        - implement a all_off blacklist to be initialised while __init__
17
-# TODO: implement all off and user feedback method (all off save)
18
-
19 14
 
20 15
 class room(object):
21 16
     def __init__(self, mqtt_client):
@@ -23,7 +18,9 @@ class room(object):
23 18
 
24 19
     def all_off(self, device=None, key=None, data=None):
25 20
         logger.info("Switching all off \"%s\"", type(self).__name__)
26
-        try:
27
-            self.main_light_shelly.all_off()
28
-        except AttributeError:
29
-            logger.exception("Device self.main_light does not exist!")
21
+        for name, obj in inspect.getmembers(self):
22
+            try:
23
+                if obj.__module__ == 'devices':
24
+                    obj.all_off()
25
+            except AttributeError:
26
+                pass    # not a module or has no method all_off

Loading…
Откажи
Сачувај