From 116cecc4717243ac78437e7fe40d414f5de410a2 Mon Sep 17 00:00:00 2001 From: Morg42 <43153739+Morg42@users.noreply.github.com> Date: Wed, 15 May 2024 09:26:44 +0200 Subject: [PATCH] sdp: clean up conn/proto initialization --- lib/model/sdp/connection.py | 2 +- lib/model/sdp/protocol.py | 46 ++++++++++++------------------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/lib/model/sdp/connection.py b/lib/model/sdp/connection.py index 6a5851ac1..ab584d3ff 100644 --- a/lib/model/sdp/connection.py +++ b/lib/model/sdp/connection.py @@ -70,7 +70,7 @@ def __init__(self, data_received_callback, name=None, **kwargs): self.dummy = None self._send_lock = None self.use_send_lock = False - self._params = None + self._params = {} if not hasattr(self, 'logger'): self.logger = logging.getLogger(__name__) diff --git a/lib/model/sdp/protocol.py b/lib/model/sdp/protocol.py index 66a6470ce..7e6d7d33b 100644 --- a/lib/model/sdp/protocol.py +++ b/lib/model/sdp/protocol.py @@ -64,23 +64,13 @@ class SDPProtocol(SDPConnection): def __init__(self, data_received_callback, name=None, **kwargs): - self.logger = logging.getLogger(__name__) - - if SDP_standalone: - self.logger = logging.getLogger('__main__') + # init super, get logger + super().__init__(data_received_callback, name, **kwargs) self.logger.debug(f'protocol initializing from {self.__class__.__name__} with arguments {kwargs}') - # set class properties - self._is_connected = False - self._data_received_callback = data_received_callback - # make sure we have a basic set of parameters - self._params = {PLUGIN_ATTR_CB_ON_DISCONNECT: None, - PLUGIN_ATTR_CB_ON_CONNECT: None, - PLUGIN_ATTR_MSG_TIMEOUT: 3, - PLUGIN_ATTR_MSG_REPEAT: 3, - PLUGIN_ATTR_CONNECTION: SDPConnection} + self._params.update({PLUGIN_ATTR_CONNECTION: SDPConnection}) self._params.update(kwargs) # check if some of the arguments are usable @@ -146,8 +136,20 @@ def data_received_callback(by, message, command=None) """ def __init__(self, data_received_callback, name=None, **kwargs): + # init super, get logger super().__init__(data_received_callback, name, **kwargs) + # make sure we have a basic set of parameters for the TCP connection + self._params.update({PLUGIN_ATTR_NET_PORT: 9090, + PLUGIN_ATTR_MSG_REPEAT: 3, + PLUGIN_ATTR_MSG_TIMEOUT: 5, + PLUGIN_ATTR_CONNECTION: CONN_NET_TCP_CLI, + JSON_MOVE_KEYS: []}) + self._params.update(kwargs) + + # check if some of the arguments are usable + self._set_connection_params() + # set class properties self._shutdown_active = False @@ -158,24 +160,6 @@ def __init__(self, data_received_callback, name=None, **kwargs): self._receive_buffer = b'' - # make sure we have a basic set of parameters for the TCP connection - self._params = {PLUGIN_ATTR_NET_HOST: '', - PLUGIN_ATTR_NET_PORT: 9090, - PLUGIN_ATTR_CONN_AUTO_CONN: True, - PLUGIN_ATTR_CONN_RETRIES: 1, - PLUGIN_ATTR_CONN_CYCLE: 3, - PLUGIN_ATTR_CONN_TIMEOUT: 3, - PLUGIN_ATTR_MSG_REPEAT: 3, - PLUGIN_ATTR_MSG_TIMEOUT: 5, - PLUGIN_ATTR_CB_ON_DISCONNECT: None, - PLUGIN_ATTR_CB_ON_CONNECT: None, - PLUGIN_ATTR_CONNECTION: CONN_NET_TCP_CLI, - JSON_MOVE_KEYS: []} - self._params.update(kwargs) - - # check if some of the arguments are usable - self._set_connection_params() - # self._message_archive[str message_id] = [time() sendtime, str method, str params or None, int repeat] self._message_archive = {}