Skip to content

Commit

Permalink
smartdeviceplugin: minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Aug 2, 2024
1 parent d0a947c commit fa946d9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/model/smartdeviceplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,17 @@ def __init__(self, sh, logger=None, **kwargs):
#resend
self._parameters[PLUGIN_ATTR_SEND_RETRIES] = self.get_parameter_value(PLUGIN_ATTR_SEND_RETRIES)
self._parameters[PLUGIN_ATTR_SEND_RETRIES_CYCLE] = self.get_parameter_value(PLUGIN_ATTR_SEND_RETRIES_CYCLE)
# Set protocol to resend if send_retries is > 0
if self._parameters.get(PLUGIN_ATTR_SEND_RETRIES, 0) > 0 and not self._parameters.get[PLUGIN_ATTR_PROTOCOL]:
self._parameters[PLUGIN_ATTR_PROTOCOL] = 'resend'

resend = self._parameters.get(PLUGIN_ATTR_SEND_RETRIES, 0) or 0
protocol = self._parameters.get(PLUGIN_ATTR_PROTOCOL)
if resend > 0:
# Set protocol to resend if send_retries is > 0 and protocol is not defined
if not protocol:
self._parameters[PLUGIN_ATTR_PROTOCOL] = 'resend'
# if send_retries is set and protocl is not set to resend, log info that protocol is overruling the parameter
elif protocol != 'resend':
self.logger.info(f'send_retries is set to {resend}, however, protocol is overruled to {protocol}')

# init parameters in standalone mode
if SDP_standalone:
self._parameters = kwargs
Expand Down Expand Up @@ -735,7 +743,8 @@ def send_command(self, command, value=None, return_result=False, **kwargs):
read_cmd = self._transform_send_data(self._commands.get_send_data(command, None))
if reply_pattern is None:
resend_info = {'command': command, 'returnvalue': None, 'read_cmd': read_cmd}
elif not any(x in reply_pattern for x in ['(', '{']):
# if no reply_pattern has lookup or capture group, put it in resend_info
elif '(' not in reply_pattern and '{' not in reply_pattern:
resend_info = {'command': command, 'returnvalue': reply_pattern, 'read_cmd': read_cmd}
else:
resend_info = {'command': command, 'returnvalue': value, 'read_cmd': read_cmd}
Expand Down

0 comments on commit fa946d9

Please sign in to comment.