Quellcode durchsuchen

GUI-Logging improved

mod_update
Dirk Alders vor 4 Jahren
Ursprung
Commit
e1656eaa1a
1 geänderte Dateien mit 26 neuen und 8 gelöschten Zeilen
  1. 26
    8
      smarthome.py

+ 26
- 8
smarthome.py Datei anzeigen

@@ -22,7 +22,6 @@ try:
22 22
     from config import APP_NAME as ROOT_LOGGER_NAME
23 23
 except ImportError:
24 24
     ROOT_LOGGER_NAME = 'root'
25
-logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
26 25
 
27 26
 
28 27
 class WetationFrameProt(gui.Wetation):
@@ -108,6 +107,7 @@ class WetationFrameProt(gui.Wetation):
108 107
         self.ShowFullScreen(config.FULL_SCREEN)
109 108
 
110 109
         self.__init_communication__()
110
+        time.sleep(3.5)   # Wait for established connections before starting the tasks
111 111
 
112 112
         self.__task_1s__ = task.periodic(1, self.__task_1s_callback__)
113 113
         self.__task_10s__ = task.periodic(10, self.__task_10s_callback__)
@@ -117,19 +117,23 @@ class WetationFrameProt(gui.Wetation):
117 117
         #
118 118
         # Start TCP-Clients
119 119
         for prot_id in self.ALL_PROT_IDS:
120
-            logger.debug('Initiating communication channel for prot_id %d', prot_id)
120
+            cn = self.PROT_NAMES[prot_id]
121
+            logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
122
+            logger.info('Initiating communication channel')
121 123
             c_tcp = tcp_socket.tcp_client_stp(self.PROT_IPS[prot_id], self.PROT_PORTS[prot_id], rx_log_lvl=logging.DEBUG)
122
-            self.__prot__[prot_id] = self.PROT_CLASSES[prot_id](c_tcp, secret=self.PROT_SECRETS[prot_id], auto_auth=True, channel_name=self.PROT_NAMES[prot_id])
124
+            self.__prot__[prot_id] = self.PROT_CLASSES[prot_id](c_tcp, secret=self.PROT_SECRETS[prot_id], auto_auth=True, channel_name=cn)
123 125
             #
124 126
             self.__prot__[prot_id].register_callback(None, None, self.__prot_resp_callbacks__, prot_id)
125 127
 
126 128
     def __initiate_data_request__(self, rt, request_msgs):
127 129
         for prot_id in request_msgs:
130
+            cn = self.PROT_NAMES[prot_id]
131
+            logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
128 132
             for request_msg in request_msgs.get(prot_id, []):
129 133
                 service_id = request_msg['service_id']
130 134
                 data_id = request_msg['data_id']
131 135
                 if self.__prot__[prot_id].connection_established():
132
-                    logger.debug('Sending data request for prot_id %d, service_id %d and data_id %d', prot_id, service_id, data_id)
136
+                    logger.debug('Sending data request for service_id %d and data_id %d', service_id, data_id)
133 137
                     self.__prot__[prot_id].send(service_id, data_id, None)
134 138
                 else:
135 139
                     wx.CallAfter(self.__no_data__, prot_id, service_id + 1, data_id)
@@ -147,12 +151,16 @@ class WetationFrameProt(gui.Wetation):
147 151
     def __task_60s_callback__(self, rt):
148 152
         # reconnect prots if needed
149 153
         for prot_id in self.ALL_PROT_IDS:
154
+            cn = self.PROT_NAMES[prot_id]
155
+            logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
150 156
             if not self.__prot__[prot_id].connected():
151
-                logger.debug("Trying to reconnect prot_id %d", prot_id)
157
+                logger.warning("Trying to reconnect prot_id %d", prot_id)
152 158
                 self.__prot__[prot_id].reconnect()
153 159
 
154 160
     def __validate_response_data__(self, prot_id, service_id, data_id, data):
155 161
         rv = False
162
+        cn = self.PROT_NAMES[prot_id]
163
+        logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
156 164
         if prot_id == self.PROT_ID_GARAGE:
157 165
             if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
158 166
                 rv = isinstance(data, numbers.Number)
@@ -198,9 +206,11 @@ class WetationFrameProt(gui.Wetation):
198 206
             return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
199 207
 
200 208
     def __no_data__(self, prot_id, service_id, data_id):
209
+        cn = self.PROT_NAMES[prot_id]
210
+        logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
201 211
         if prot_id == self.PROT_ID_GARAGE:
202 212
             if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
203
-                logger.debug('Resetting GUI for prot_id %d, service_id=%d, data_id=%d', prot_id, service_id, data_id)
213
+                logger.warning('Resetting GUI elements for %s', cn)
204 214
                 self.heading_garage.Show(False)
205 215
                 self.gate_oc.Show(False)
206 216
                 self.gate_open.Show(False)
@@ -212,7 +222,7 @@ class WetationFrameProt(gui.Wetation):
212 222
                 return
213 223
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
214 224
             if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
215
-                logger.debug('Resetting GUI for prot_id %d, service_id=%d, data_id=%d', prot_id, service_id, data_id)
225
+                logger.warning('Resetting GUI elements for %s', cn)
216 226
                 txt_pressure = '- hPa'
217 227
                 if prot_id == self.PROT_ID_IN:
218 228
                     self.in_pressure.SetLabel(txt_pressure)
@@ -221,7 +231,7 @@ class WetationFrameProt(gui.Wetation):
221 231
                 self.Layout()
222 232
                 return
223 233
             elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
224
-                logger.debug('Resetting GUI for prot_id %d, service_id=%d, data_id=%d', prot_id, service_id, data_id)
234
+                logger.warning('Resetting GUI elements for %s', cn)
225 235
                 txt_temperature = '-.- °C'
226 236
                 txt_humidity = '-.- %'
227 237
                 if prot_id == self.PROT_ID_IN:
@@ -235,8 +245,11 @@ class WetationFrameProt(gui.Wetation):
235 245
         logger.warning("Unknown response with no valid data for prot_id %d, service_id=%d, data_id=%d", prot_id, service_id, data_id)
236 246
 
237 247
     def __data__(self, prot_id, service_id, data_id, data):
248
+        cn = self.PROT_NAMES[prot_id]
249
+        logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
238 250
         if prot_id == self.PROT_ID_GARAGE:
239 251
             if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
252
+                logger.debug('Setting %s position to %3d', cn, int(data * 100))
240 253
                 self.heading_garage.Show(True)
241 254
                 self.gate_oc.Show(True)
242 255
                 self.gate_open.Show(True)
@@ -250,6 +263,7 @@ class WetationFrameProt(gui.Wetation):
250 263
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
251 264
             if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
252 265
                 data = helpers.continues_statistic_multivalue(**data)
266
+                logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean)
253 267
                 #
254 268
                 # Current environmental data
255 269
                 if prot_id == self.PROT_ID_IN:
@@ -262,6 +276,8 @@ class WetationFrameProt(gui.Wetation):
262 276
                 #
263 277
                 # Current environmental data
264 278
                 temp = data[dht_22.KEY_TEMPERATURE].mean
279
+                logger.debug('Setting %s temperature to %4.1f °C', cn, temp)
280
+                logger.debug('Setting %s humidity to %3.1f %%', cn, data[dht_22.KEY_HUMIDITY].mean)
265 281
                 if prot_id == self.PROT_ID_IN:
266 282
                     if self.__max_temp_in__ is None or temp > self.__max_temp_in__:
267 283
                         self.__max_temp_in__ = temp
@@ -295,6 +311,8 @@ class WetationFrameProt(gui.Wetation):
295 311
         self.Layout()
296 312
 
297 313
     def gate_oc_evt(self, event):
314
+        cn = self.PROT_NAMES[self.PROT_ID_GARAGE]
315
+        logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
298 316
         r = wx.MessageDialog(
299 317
             self,
300 318
             "Soll das Garagentor betätigt werden?",

Laden…
Abbrechen
Speichern