diff --git a/lib/model/sdp/connection.py b/lib/model/sdp/connection.py index d1a3ee5c8d..55f9c3f115 100644 --- a/lib/model/sdp/connection.py +++ b/lib/model/sdp/connection.py @@ -732,9 +732,10 @@ def _open(self): if self._is_connected: self._connection_attempts = 0 + self._setup_listener() + # only call on_connect callback after listener is set up if self._params[PLUGIN_ATTR_CB_ON_CONNECT]: self._params[PLUGIN_ATTR_CB_ON_CONNECT](self) - self._setup_listener() return True else: self.logger.debug(f'sleeping {self._params[PLUGIN_ATTR_CONN_CYCLE]} seconds before next connection attempt') diff --git a/lib/model/smartdeviceplugin.py b/lib/model/smartdeviceplugin.py index 20f145a59b..81f89f7080 100644 --- a/lib/model/smartdeviceplugin.py +++ b/lib/model/smartdeviceplugin.py @@ -208,7 +208,7 @@ def __init__(self, sh, logger=None, **kwargs): # possibly initialize additional (overwrite _set_device_defaults) self._set_device_defaults() - # save modified value for passing to SDPCommands + # save modified value for ing to SDPCommands self._parameters['custom_patterns'] = self._custom_patterns # set/update plugin configuration @@ -338,13 +338,6 @@ def resume(self, by=None): if self._suspend_item is not None: self._suspend_item(False, self.get_fullname()) self.connect() - if self._connection.connected(): - if self._resume_initial_read: - # make sure to read again on resume (if configured) - self._initial_value_read_done = False - self.read_initial_values() - if not SDP_standalone: - self._create_cyclic_scheduler() # call user-defined resume actions self.on_resume() @@ -787,8 +780,8 @@ def send_command(self, command, value=None, return_result=False, **kwargs): elif isinstance(reply_pattern, list): return_list = [] for r in reply_pattern: - if '(' not in r and '{' not in r: - return_list.append(r) + if '(' not in r and '{' not in r: + return_list.append(r) reply_pattern = return_list if return_list else value resend_info = {'command': resend_command, 'returnvalue': reply_pattern, 'read_cmd': read_cmd} # if reply pattern does not expect a specific value, use value as expected reply @@ -1039,7 +1032,13 @@ def _send(self, data_dict, **kwargs): def on_connect(self, by=None): """ callback if connection is made. """ - pass + if self._connection.connected(): + if self._resume_initial_read: + # make sure to read again on resume (if configured) + self._initial_value_read_done = False + self.read_initial_values() + if not SDP_standalone: + self._create_cyclic_scheduler() def on_disconnect(self, by=None): """ callback if connection is broken. """ @@ -1221,7 +1220,7 @@ def _read_cyclic_values(self): self._cyclic_update_active = False # reconnect - if not self._parameters.get(PLUGIN_ATTR_CONN_AUTO_RECONN, False): + if self._parameters.get(PLUGIN_ATTR_CONN_AUTO_RECONN, False): time.sleep(1) self.connect() else: @@ -1674,7 +1673,9 @@ def create_item(self, node, node_name, parent, path, indent, gpath, gpathlist, c rg_list = [rg_list] for entry in rg_list: grps.append(entry.get('name')) - item[ITEM_ATTR_GROUP + '@instance'] = grps + # only create read_groups if they actually exist + if grps: + item[ITEM_ATTR_GROUP + '@instance'] = grps # item attributes if ia_node: