Browse Source

all off improved

tags/v1.0.0
Dirk Alders 1 year ago
parent
commit
d4c5411d47
2 changed files with 11 additions and 32 deletions
  1. 4
    22
      function/__init__.py
  2. 7
    10
      function/rooms.py

+ 4
- 22
function/__init__.py View File

98
                 rv.append(obj)
98
                 rv.append(obj)
99
         return rv
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
     def gfw_off(self, device=None, key=None, data=None):
101
     def gfw_off(self, device=None, key=None, data=None):
107
         logger.info("Switching \"ground floor west\" off.")
102
         logger.info("Switching \"ground floor west\" off.")
108
         for gfw in self.getmembers('gfw'):
103
         for gfw in self.getmembers('gfw'):
124
             stw.all_off()
119
             stw.all_off()
125
 
120
 
126
     def all_off(self, device=None, key=None, data=None):
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 View File

3
 #
3
 #
4
 
4
 
5
 import logging
5
 import logging
6
-import task
6
+import inspect
7
 
7
 
8
 try:
8
 try:
9
     from config import APP_NAME as ROOT_LOGGER_NAME
9
     from config import APP_NAME as ROOT_LOGGER_NAME
11
     ROOT_LOGGER_NAME = 'root'
11
     ROOT_LOGGER_NAME = 'root'
12
 logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
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
 class room(object):
15
 class room(object):
21
     def __init__(self, mqtt_client):
16
     def __init__(self, mqtt_client):
23
 
18
 
24
     def all_off(self, device=None, key=None, data=None):
19
     def all_off(self, device=None, key=None, data=None):
25
         logger.info("Switching all off \"%s\"", type(self).__name__)
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…
Cancel
Save