diff --git a/smarthome.py b/smarthome.py index c9b6608..885afd7 100644 --- a/smarthome.py +++ b/smarthome.py @@ -22,7 +22,6 @@ try: from config import APP_NAME as ROOT_LOGGER_NAME except ImportError: ROOT_LOGGER_NAME = 'root' -logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__) class WetationFrameProt(gui.Wetation): @@ -108,6 +107,7 @@ class WetationFrameProt(gui.Wetation): self.ShowFullScreen(config.FULL_SCREEN) 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_10s__ = task.periodic(10, self.__task_10s_callback__) @@ -117,19 +117,23 @@ class WetationFrameProt(gui.Wetation): # # Start TCP-Clients 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) - 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) def __initiate_data_request__(self, rt, 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, []): service_id = request_msg['service_id'] data_id = request_msg['data_id'] 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) else: 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): # reconnect prots if needed 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(): - 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() def __validate_response_data__(self, prot_id, service_id, data_id, data): 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 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) @@ -198,9 +206,11 @@ class WetationFrameProt(gui.Wetation): return wetation_protocol.my_base_protocol_tcp.STATUS_SERVICE_OR_DATA_UNKNOWN, None 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 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.gate_oc.Show(False) self.gate_open.Show(False) @@ -212,7 +222,7 @@ class WetationFrameProt(gui.Wetation): return 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: - 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' if prot_id == self.PROT_ID_IN: self.in_pressure.SetLabel(txt_pressure) @@ -221,7 +231,7 @@ class WetationFrameProt(gui.Wetation): self.Layout() 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: - 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_humidity = '-.- %' 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) 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 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.gate_oc.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]: 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) + logger.debug('Setting %s pressure to %4d hPa', cn, data[bmp_180.KEY_PRESSURE].mean) # # Current environmental data if prot_id == self.PROT_ID_IN: @@ -262,6 +276,8 @@ class WetationFrameProt(gui.Wetation): # # Current environmental data 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 self.__max_temp_in__ is None or temp > self.__max_temp_in__: self.__max_temp_in__ = temp @@ -295,6 +311,8 @@ class WetationFrameProt(gui.Wetation): self.Layout() 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( self, "Soll das Garagentor betätigt werden?",