GUI-Logging improved

This commit is contained in:
Dirk Alders 2020-12-25 22:02:42 +01:00
parent dbb835d5c2
commit e1656eaa1a

View File

@ -22,7 +22,6 @@ try:
from config import APP_NAME as ROOT_LOGGER_NAME from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError: except ImportError:
ROOT_LOGGER_NAME = 'root' ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
class WetationFrameProt(gui.Wetation): class WetationFrameProt(gui.Wetation):
@ -108,6 +107,7 @@ class WetationFrameProt(gui.Wetation):
self.ShowFullScreen(config.FULL_SCREEN) self.ShowFullScreen(config.FULL_SCREEN)
self.__init_communication__() self.__init_communication__()
time.sleep(3.5) # Wait for established connections before starting the tasks
self.__task_1s__ = task.periodic(1, self.__task_1s_callback__) self.__task_1s__ = task.periodic(1, self.__task_1s_callback__)
self.__task_10s__ = task.periodic(10, self.__task_10s_callback__) self.__task_10s__ = task.periodic(10, self.__task_10s_callback__)
@ -117,19 +117,23 @@ class WetationFrameProt(gui.Wetation):
# #
# Start TCP-Clients # Start TCP-Clients
for prot_id in self.ALL_PROT_IDS: for prot_id in self.ALL_PROT_IDS:
logger.debug('Initiating communication channel for prot_id %d', prot_id) cn = self.PROT_NAMES[prot_id]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
logger.info('Initiating communication channel')
c_tcp = tcp_socket.tcp_client_stp(self.PROT_IPS[prot_id], self.PROT_PORTS[prot_id], rx_log_lvl=logging.DEBUG) c_tcp = tcp_socket.tcp_client_stp(self.PROT_IPS[prot_id], self.PROT_PORTS[prot_id], rx_log_lvl=logging.DEBUG)
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]) self.__prot__[prot_id] = self.PROT_CLASSES[prot_id](c_tcp, secret=self.PROT_SECRETS[prot_id], auto_auth=True, channel_name=cn)
# #
self.__prot__[prot_id].register_callback(None, None, self.__prot_resp_callbacks__, prot_id) self.__prot__[prot_id].register_callback(None, None, self.__prot_resp_callbacks__, prot_id)
def __initiate_data_request__(self, rt, request_msgs): def __initiate_data_request__(self, rt, request_msgs):
for prot_id in request_msgs: for prot_id in request_msgs:
cn = self.PROT_NAMES[prot_id]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
for request_msg in request_msgs.get(prot_id, []): for request_msg in request_msgs.get(prot_id, []):
service_id = request_msg['service_id'] service_id = request_msg['service_id']
data_id = request_msg['data_id'] data_id = request_msg['data_id']
if self.__prot__[prot_id].connection_established(): if self.__prot__[prot_id].connection_established():
logger.debug('Sending data request for prot_id %d, service_id %d and data_id %d', prot_id, service_id, data_id) logger.debug('Sending data request for service_id %d and data_id %d', service_id, data_id)
self.__prot__[prot_id].send(service_id, data_id, None) self.__prot__[prot_id].send(service_id, data_id, None)
else: else:
wx.CallAfter(self.__no_data__, prot_id, service_id + 1, data_id) wx.CallAfter(self.__no_data__, prot_id, service_id + 1, data_id)
@ -147,12 +151,16 @@ class WetationFrameProt(gui.Wetation):
def __task_60s_callback__(self, rt): def __task_60s_callback__(self, rt):
# reconnect prots if needed # reconnect prots if needed
for prot_id in self.ALL_PROT_IDS: for prot_id in self.ALL_PROT_IDS:
cn = self.PROT_NAMES[prot_id]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
if not self.__prot__[prot_id].connected(): if not self.__prot__[prot_id].connected():
logger.debug("Trying to reconnect prot_id %d", prot_id) logger.warning("Trying to reconnect prot_id %d", prot_id)
self.__prot__[prot_id].reconnect() self.__prot__[prot_id].reconnect()
def __validate_response_data__(self, prot_id, service_id, data_id, data): def __validate_response_data__(self, prot_id, service_id, data_id, data):
rv = False rv = False
cn = self.PROT_NAMES[prot_id]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
if prot_id == self.PROT_ID_GARAGE: if prot_id == self.PROT_ID_GARAGE:
if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION: if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
rv = isinstance(data, numbers.Number) rv = isinstance(data, numbers.Number)
@ -198,9 +206,11 @@ class WetationFrameProt(gui.Wetation):
return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None
def __no_data__(self, prot_id, service_id, data_id): def __no_data__(self, prot_id, service_id, data_id):
cn = self.PROT_NAMES[prot_id]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
if prot_id == self.PROT_ID_GARAGE: if prot_id == self.PROT_ID_GARAGE:
if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION: if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
logger.debug('Resetting GUI for prot_id %d, service_id=%d, data_id=%d', prot_id, service_id, data_id) logger.warning('Resetting GUI elements for %s', cn)
self.heading_garage.Show(False) self.heading_garage.Show(False)
self.gate_oc.Show(False) self.gate_oc.Show(False)
self.gate_open.Show(False) self.gate_open.Show(False)
@ -212,7 +222,7 @@ class WetationFrameProt(gui.Wetation):
return return
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]: elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP: if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
logger.debug('Resetting GUI for prot_id %d, service_id=%d, data_id=%d', prot_id, service_id, data_id) logger.warning('Resetting GUI elements for %s', cn)
txt_pressure = '- hPa' txt_pressure = '- hPa'
if prot_id == self.PROT_ID_IN: if prot_id == self.PROT_ID_IN:
self.in_pressure.SetLabel(txt_pressure) self.in_pressure.SetLabel(txt_pressure)
@ -221,7 +231,7 @@ class WetationFrameProt(gui.Wetation):
self.Layout() self.Layout()
return return
elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT: elif service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_DHT:
logger.debug('Resetting GUI for prot_id %d, service_id=%d, data_id=%d', prot_id, service_id, data_id) logger.warning('Resetting GUI elements for %s', cn)
txt_temperature = '-.- °C' txt_temperature = '-.- °C'
txt_humidity = '-.- %' txt_humidity = '-.- %'
if prot_id == self.PROT_ID_IN: if prot_id == self.PROT_ID_IN:
@ -235,8 +245,11 @@ class WetationFrameProt(gui.Wetation):
logger.warning("Unknown response with no valid data for prot_id %d, service_id=%d, data_id=%d", prot_id, service_id, data_id) logger.warning("Unknown response with no valid data for prot_id %d, service_id=%d, data_id=%d", prot_id, service_id, data_id)
def __data__(self, prot_id, service_id, data_id, data): def __data__(self, prot_id, service_id, data_id, data):
cn = self.PROT_NAMES[prot_id]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
if prot_id == self.PROT_ID_GARAGE: if prot_id == self.PROT_ID_GARAGE:
if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION: if service_id == garage_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == garage_protocol.my_base_protocol_tcp.GATE_POSITION:
logger.debug('Setting %s position to %3d', cn, int(data * 100))
self.heading_garage.Show(True) self.heading_garage.Show(True)
self.gate_oc.Show(True) self.gate_oc.Show(True)
self.gate_open.Show(True) self.gate_open.Show(True)
@ -250,6 +263,7 @@ class WetationFrameProt(gui.Wetation):
elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]: elif prot_id in [self.PROT_ID_IN, self.PROT_ID_OUT]:
if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP: if service_id == wetation_protocol.my_base_protocol_tcp.SID_READ_RESPONSE and data_id == wetation_protocol.my_base_protocol_tcp.ENVDATA_STATISTIC_BMP:
data = helpers.continues_statistic_multivalue(**data) data = helpers.continues_statistic_multivalue(**data)
logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean)
# #
# Current environmental data # Current environmental data
if prot_id == self.PROT_ID_IN: if prot_id == self.PROT_ID_IN:
@ -262,6 +276,8 @@ class WetationFrameProt(gui.Wetation):
# #
# Current environmental data # Current environmental data
temp = data[dht_22.KEY_TEMPERATURE].mean temp = data[dht_22.KEY_TEMPERATURE].mean
logger.debug('Setting %s temperature to %4.1f °C', cn, temp)
logger.debug('Setting %s humidity to %3.1f %%', cn, data[dht_22.KEY_HUMIDITY].mean)
if prot_id == self.PROT_ID_IN: if prot_id == self.PROT_ID_IN:
if self.__max_temp_in__ is None or temp > self.__max_temp_in__: if self.__max_temp_in__ is None or temp > self.__max_temp_in__:
self.__max_temp_in__ = temp self.__max_temp_in__ = temp
@ -295,6 +311,8 @@ class WetationFrameProt(gui.Wetation):
self.Layout() self.Layout()
def gate_oc_evt(self, event): def gate_oc_evt(self, event):
cn = self.PROT_NAMES[self.PROT_ID_GARAGE]
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__ + '.' + cn)
r = wx.MessageDialog( r = wx.MessageDialog(
self, self,
"Soll das Garagentor betätigt werden?", "Soll das Garagentor betätigt werden?",