Browse Source

warning mechanisms removed

tags/v1.3.0
Dirk Alders 1 year ago
parent
commit
d93c9548c8
5 changed files with 2 additions and 84 deletions
  1. 2
    27
      devices/base.py
  2. 0
    18
      devices/brennenstuhl.py
  3. 0
    11
      devices/shelly.py
  4. 0
    11
      devices/silvercrest.py
  5. 0
    17
      devices/tradfri.py

+ 2
- 27
devices/base.py View File

6
 import json
6
 import json
7
 import time
7
 import time
8
 
8
 
9
-BATTERY_WARN_LEVEL = 10
10
-
11
 
9
 
12
 def is_json(data):
10
 def is_json(data):
13
     try:
11
     try:
29
     RX_IGNORE_TOPICS = []
27
     RX_IGNORE_TOPICS = []
30
     RX_IGNORE_KEYS = []
28
     RX_IGNORE_KEYS = []
31
     RX_FILTER_DATA_KEYS = []
29
     RX_FILTER_DATA_KEYS = []
32
-    #
33
-    KEY_WARNING = '__WARNING__'
34
 
30
 
35
     def __init__(self, mqtt_client, topic):
31
     def __init__(self, mqtt_client, topic):
36
-        super().__init__(mqtt_client, topic, default_values=dict.fromkeys(self.RX_KEYS + [self.KEY_WARNING]))
32
+        super().__init__(mqtt_client, topic, default_values=dict.fromkeys(self.RX_KEYS))
37
         # data storage
33
         # data storage
38
         # initialisations
34
         # initialisations
39
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
35
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
44
     def set(self, key, data, block_callback=[]):
40
     def set(self, key, data, block_callback=[]):
45
         if key in self.RX_IGNORE_KEYS:
41
         if key in self.RX_IGNORE_KEYS:
46
             pass    # ignore these keys
42
             pass    # ignore these keys
47
-        elif key in self.RX_KEYS or key == self.KEY_WARNING:
43
+        elif key in self.RX_KEYS:
48
             return super().set(key, data, block_callback)
44
             return super().set(key, data, block_callback)
49
         else:
45
         else:
50
             self.logger.warning("Unexpected key %s", key)
46
             self.logger.warning("Unexpected key %s", key)
105
                     self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC] if len(self.TX_TOPIC) > 0 else [self.topic, key]), data)
101
                     self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC] if len(self.TX_TOPIC) > 0 else [self.topic, key]), data)
106
         else:
102
         else:
107
             self.logger.error("Unknown tx toptic. Set TX_TOPIC of class to a known value")
103
             self.logger.error("Unknown tx toptic. Set TX_TOPIC of class to a known value")
108
-
109
-
110
-class warning(dict):
111
-    TYPE_BATTERY_LOW = 1
112
-    TYPE_OVERTEMPERATURE = 2
113
-    #
114
-    KEY_ID = 'id'
115
-    KEY_TYPE = 'type'
116
-    KEY_TEXT = 'text'
117
-    KEY_TM = 'tm'
118
-
119
-    def __init__(self, identification, type, text, args):
120
-        super().__init__({
121
-            self.KEY_ID: identification,
122
-            self.KEY_TYPE: type,
123
-            self.KEY_TEXT: text % args,
124
-            self.KEY_TM: time.localtime(),
125
-        })
126
-
127
-    def __str__(self):
128
-        return time.asctime(self.get(self.KEY_TM)) + ": " + self[self.KEY_TEXT] + " - " + self[self.KEY_ID]

+ 0
- 18
devices/brennenstuhl.py View File

2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 #
3
 #
4
 from devices.base import base
4
 from devices.base import base
5
-from devices.base import BATTERY_WARN_LEVEL
6
-from devices.base import warning
7
 import json
5
 import json
8
 
6
 
9
 
7
 
53
         super().__init__(mqtt_client, topic)
51
         super().__init__(mqtt_client, topic)
54
         self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
52
         self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
55
                               self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
53
                               self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
56
-        #
57
-        self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
58
-        self.__battery_warning__ = False
59
 
54
 
60
     def __state_logging__(self, inst, key, data):
55
     def __state_logging__(self, inst, key, data):
61
         if key in [self.KEY_HEATING_SETPOINT, self.KEY_CHILD_LOCK, self.KEY_WINDOW_DETECTION, self.KEY_VALVE_DETECTION]:
56
         if key in [self.KEY_HEATING_SETPOINT, self.KEY_CHILD_LOCK, self.KEY_WINDOW_DETECTION, self.KEY_VALVE_DETECTION]:
62
             self.logger.info("State change of '%s' to '%s'", key, repr(data))
57
             self.logger.info("State change of '%s' to '%s'", key, repr(data))
63
 
58
 
64
-    #
65
-    # WARNING CALL
66
-    #
67
-    def __warning__(self, client, key, data):
68
-        if data <= BATTERY_WARN_LEVEL:
69
-            if not self.__battery_warning__:
70
-                self.__battery_warning__ = True
71
-                w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
72
-                self.logger.warning(w)
73
-                self.set(self.KEY_WARNING, w)
74
-        else:
75
-            self.__battery_warning__ = False
76
-
77
     #
59
     #
78
     # RX
60
     # RX
79
     #
61
     #

+ 0
- 11
devices/shelly.py View File

2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 #
3
 #
4
 from devices.base import base
4
 from devices.base import base
5
-from devices.base import warning
6
 import logging
5
 import logging
7
 import task
6
 import task
8
 
7
 
69
         self.delayed_flash_task = task.delayed(0.3, self.flash_task)
68
         self.delayed_flash_task = task.delayed(0.3, self.flash_task)
70
         self.delayed_off_task = task.delayed(0.3, self.off_task)
69
         self.delayed_off_task = task.delayed(0.3, self.off_task)
71
         #
70
         #
72
-        self.add_callback(self.KEY_OVERTEMPERATURE, True, self.__warning__, True)
73
-        #
74
         self.all_off_requested = False
71
         self.all_off_requested = False
75
 
72
 
76
     def __state_logging__(self, inst, key, data):
73
     def __state_logging__(self, inst, key, data):
93
     def flash_active(self):
90
     def flash_active(self):
94
         return self.output_key_delayed is not None
91
         return self.output_key_delayed is not None
95
 
92
 
96
-    #
97
-    # WARNING CALL
98
-    #
99
-    def __warning__(self, client, key, data):
100
-        w = warning(self.topic, warning.TYPE_OVERTEMPERATURE, "Temperature to high (%.1f°C)", self.get(self.KEY_TEMPERATURE) or math.nan)
101
-        self.logger.warning(w)
102
-        self.set(self.KEY_WARNING, w)
103
-
104
     #
93
     #
105
     # RX
94
     # RX
106
     #
95
     #

+ 0
- 11
devices/silvercrest.py View File

2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 #
3
 #
4
 from devices.base import base
4
 from devices.base import base
5
-from devices.base import warning
6
 import logging
5
 import logging
7
 
6
 
8
 
7
 
89
 
88
 
90
     def __init__(self, mqtt_client, topic):
89
     def __init__(self, mqtt_client, topic):
91
         super().__init__(mqtt_client, topic)
90
         super().__init__(mqtt_client, topic)
92
-        #
93
-        self.add_callback(self.KEY_BATTERY_LOW, True, self.__warning__, True)
94
 
91
 
95
     def __state_logging__(self, inst, key, data):
92
     def __state_logging__(self, inst, key, data):
96
         if key in [self.KEY_OCCUPANCY, self.KEY_UNMOUNTED]:
93
         if key in [self.KEY_OCCUPANCY, self.KEY_UNMOUNTED]:
97
             self.logger.info("State change of '%s' to '%s'", key, repr(data))
94
             self.logger.info("State change of '%s' to '%s'", key, repr(data))
98
 
95
 
99
-    #
100
-    # WARNING CALL
101
-    #
102
-    def __warning__(self, client, key, data):
103
-        w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", self.get(self.KEY_BATTERY) or math.nan)
104
-        self.logger.warning(w)
105
-        self.set(self.KEY_WARNING, w)
106
-
107
     #
96
     #
108
     # RX
97
     # RX
109
     #
98
     #

+ 0
- 17
devices/tradfri.py View File

2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 #
3
 #
4
 from devices.base import base
4
 from devices.base import base
5
-from devices.base import BATTERY_WARN_LEVEL
6
-from devices.base import warning
7
 import logging
5
 import logging
8
 
6
 
9
 
7
 
180
 
178
 
181
     def __init__(self, mqtt_client, topic):
179
     def __init__(self, mqtt_client, topic):
182
         super().__init__(mqtt_client, topic)
180
         super().__init__(mqtt_client, topic)
183
-        #
184
-        self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
185
-        self.__battery_warning__ = False
186
 
181
 
187
     def __state_logging__(self, inst, key, data):
182
     def __state_logging__(self, inst, key, data):
188
         if key in [self.KEY_ACTION]:
183
         if key in [self.KEY_ACTION]:
189
             self.logger.info("Input '%s' with '%s'", key, repr(data))
184
             self.logger.info("Input '%s' with '%s'", key, repr(data))
190
 
185
 
191
-    #
192
-    # WARNING CALL
193
-    #
194
-    def __warning__(self, client, key, data):
195
-        if data <= BATTERY_WARN_LEVEL:
196
-            if not self.__battery_warning__:
197
-                w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
198
-                self.logger.warning(w)
199
-                self.set(self.KEY_WARNING, w)
200
-        else:
201
-            self.__battery_warning__ = False
202
-
203
     #
186
     #
204
     # RX
187
     # RX
205
     #
188
     #

Loading…
Cancel
Save