Browse Source

GUI-Logging improved

mod_update
Dirk Alders 4 years ago
parent
commit
e1656eaa1a
1 changed files with 26 additions and 8 deletions
  1. 26
    8
      smarthome.py

+ 26
- 8
smarthome.py View File

22
     from config import APP_NAME as ROOT_LOGGER_NAME
22
     from config import APP_NAME as ROOT_LOGGER_NAME
23
 except ImportError:
23
 except ImportError:
24
     ROOT_LOGGER_NAME = 'root'
24
     ROOT_LOGGER_NAME = 'root'
25
-logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
26
 
25
 
27
 
26
 
28
 class WetationFrameProt(gui.Wetation):
27
 class WetationFrameProt(gui.Wetation):
108
         self.ShowFullScreen(config.FULL_SCREEN)
107
         self.ShowFullScreen(config.FULL_SCREEN)
109
 
108
 
110
         self.__init_communication__()
109
         self.__init_communication__()
110
+        time.sleep(3.5)   # Wait for established connections before starting the tasks
111
 
111
 
112
         self.__task_1s__ = task.periodic(1, self.__task_1s_callback__)
112
         self.__task_1s__ = task.periodic(1, self.__task_1s_callback__)
113
         self.__task_10s__ = task.periodic(10, self.__task_10s_callback__)
113
         self.__task_10s__ = task.periodic(10, self.__task_10s_callback__)
117
         #
117
         #
118
         # Start TCP-Clients
118
         # Start TCP-Clients
119
         for prot_id in self.ALL_PROT_IDS:
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
             c_tcp = tcp_socket.tcp_client_stp(self.PROT_IPS[prot_id], self.PROT_PORTS[prot_id], rx_log_lvl=logging.DEBUG)
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
             self.__prot__[prot_id].register_callback(None, None, self.__prot_resp_callbacks__, prot_id)
126
             self.__prot__[prot_id].register_callback(None, None, self.__prot_resp_callbacks__, prot_id)
125
 
127
 
126
     def __initiate_data_request__(self, rt, request_msgs):
128
     def __initiate_data_request__(self, rt, request_msgs):
127
         for prot_id in request_msgs:
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
             for request_msg in request_msgs.get(prot_id, []):
132
             for request_msg in request_msgs.get(prot_id, []):
129
                 service_id = request_msg['service_id']
133
                 service_id = request_msg['service_id']
130
                 data_id = request_msg['data_id']
134
                 data_id = request_msg['data_id']
131
                 if self.__prot__[prot_id].connection_established():
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
                     self.__prot__[prot_id].send(service_id, data_id, None)
137
                     self.__prot__[prot_id].send(service_id, data_id, None)
134
                 else:
138
                 else:
135
                     wx.CallAfter(self.__no_data__, prot_id, service_id + 1, data_id)
139
                     wx.CallAfter(self.__no_data__, prot_id, service_id + 1, data_id)
147
     def __task_60s_callback__(self, rt):
151
     def __task_60s_callback__(self, rt):
148
         # reconnect prots if needed
152
         # reconnect prots if needed
149
         for prot_id in self.ALL_PROT_IDS:
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
             if not self.__prot__[prot_id].connected():
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
                 self.__prot__[prot_id].reconnect()
158
                 self.__prot__[prot_id].reconnect()
153
 
159
 
154
     def __validate_response_data__(self, prot_id, service_id, data_id, data):
160
     def __validate_response_data__(self, prot_id, service_id, data_id, data):
155
         rv = False
161
         rv = False
162
+        cn = self.PROT_NAMES[prot_id]
163
+        logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
156
         if prot_id == self.PROT_ID_GARAGE:
164
         if prot_id == self.PROT_ID_GARAGE:
157
             if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
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
                 rv = isinstance(data, numbers.Number)
166
                 rv = isinstance(data, numbers.Number)
198
             return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
206
             return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
199
 
207
 
200
     def __no_data__(self, prot_id, service_id, data_id):
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
         if prot_id == self.PROT_ID_GARAGE:
211
         if prot_id == self.PROT_ID_GARAGE:
202
             if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
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
                 self.heading_garage.Show(False)
214
                 self.heading_garage.Show(False)
205
                 self.gate_oc.Show(False)
215
                 self.gate_oc.Show(False)
206
                 self.gate_open.Show(False)
216
                 self.gate_open.Show(False)
212
                 return
222
                 return
213
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
223
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
214
             if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
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
                 txt_pressure = '- hPa'
226
                 txt_pressure = '- hPa'
217
                 if prot_id == self.PROT_ID_IN:
227
                 if prot_id == self.PROT_ID_IN:
218
                     self.in_pressure.SetLabel(txt_pressure)
228
                     self.in_pressure.SetLabel(txt_pressure)
221
                 self.Layout()
231
                 self.Layout()
222
                 return
232
                 return
223
             elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
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
                 txt_temperature = '-.- °C'
235
                 txt_temperature = '-.- °C'
226
                 txt_humidity = '-.- %'
236
                 txt_humidity = '-.- %'
227
                 if prot_id == self.PROT_ID_IN:
237
                 if prot_id == self.PROT_ID_IN:
235
         logger.warning("Unknown response with no valid data for prot_id %d, service_id=%d, data_id=%d", prot_id, service_id, data_id)
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
     def __data__(self, prot_id, service_id, data_id, data):
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
         if prot_id == self.PROT_ID_GARAGE:
250
         if prot_id == self.PROT_ID_GARAGE:
239
             if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
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
                 self.heading_garage.Show(True)
253
                 self.heading_garage.Show(True)
241
                 self.gate_oc.Show(True)
254
                 self.gate_oc.Show(True)
242
                 self.gate_open.Show(True)
255
                 self.gate_open.Show(True)
250
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
263
         elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
251
             if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
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
                 data = helpers.continues_statistic_multivalue(**data)
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
                 # Current environmental data
268
                 # Current environmental data
255
                 if prot_id == self.PROT_ID_IN:
269
                 if prot_id == self.PROT_ID_IN:
262
                 #
276
                 #
263
                 # Current environmental data
277
                 # Current environmental data
264
                 temp = data[dht_22.KEY_TEMPERATURE].mean
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
                 if prot_id == self.PROT_ID_IN:
281
                 if prot_id == self.PROT_ID_IN:
266
                     if self.__max_temp_in__ is None or temp > self.__max_temp_in__:
282
                     if self.__max_temp_in__ is None or temp > self.__max_temp_in__:
267
                         self.__max_temp_in__ = temp
283
                         self.__max_temp_in__ = temp
295
         self.Layout()
311
         self.Layout()
296
 
312
 
297
     def gate_oc_evt(self, event):
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
         r = wx.MessageDialog(
316
         r = wx.MessageDialog(
299
             self,
317
             self,
300
             "Soll das Garagentor betätigt werden?",
318
             "Soll das Garagentor betätigt werden?",

Loading…
Cancel
Save