Skip to content

Commit

Permalink
Merge pull request #678 from Morg42/sdp-2
Browse files Browse the repository at this point in the history
sdp: fix order of connect initialization, fix struct generation
  • Loading branch information
Morg42 authored Oct 11, 2024
2 parents db90ac4 + c9471ad commit fdf6482
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion lib/model/sdp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
27 changes: 14 additions & 13 deletions lib/model/smartdeviceplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fdf6482

Please sign in to comment.