Skip to content

Commit

Permalink
denon plugin: revert resend changes as it is now included as a protoc…
Browse files Browse the repository at this point in the history
…ol on a global level
  • Loading branch information
onkelandy committed Aug 11, 2024
1 parent 45c1352 commit 83dd11f
Showing 1 changed file with 0 additions and 70 deletions.
70 changes: 0 additions & 70 deletions denon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import sys
import threading
import time
import datetime
from lib.shtime import Shtime

if __name__ == '__main__':
builtins.SDP_standalone = True
Expand Down Expand Up @@ -60,37 +58,12 @@ class denon(SmartDevicePlugin):
PLUGIN_VERSION = '1.0.1'

def on_connect(self, by=None):
self.logger.debug(f"Connected.. Cycle for retry: {self._sendretry_cycle}")
if self._send_retries >= 1:
self.scheduler_add('resend', self._resend, cycle=self._sendretry_cycle)
self.logger.debug("Checking for custom input names.")
self.send_command('general.custom_inputnames')
if self.scheduler_get('read_initial_values'):
return
elif self._initial_value_read_delay > 0:
self.logger.dbghigh(f"On connect reading initial values after {self._initial_value_read_delay} seconds.")
self.scheduler_add('read_initial_values', self._read_initial_values, value={'force': True}, next=self.shtime.now() + datetime.timedelta(seconds=self._initial_value_read_delay))
else:
self._read_initial_values(True)

def _on_suspend(self):
for scheduler in self.scheduler_get_all():
self.scheduler_remove(scheduler)

def _on_resume(self):
if self.scheduler_get('resend'):
self.scheduler_remove('resend')
self.logger.debug(f"Resuming.. Cycle for retry: {self._sendretry_cycle}")
if self._send_retries >= 1:
self.scheduler_add('resend', self._resend, cycle=self._sendretry_cycle)

def _set_device_defaults(self):
self._use_callbacks = True
self._custom_inputnames = {}
self._sending = {}
self._sending_lock = threading.Lock()
self._send_retries = self.get_parameter_value('send_retries')
self._sendretry_cycle = int(self.get_parameter_value('sendretry_cycle'))

# set our own preferences concerning connections
if PLUGIN_ATTR_NET_HOST in self._parameters and self._parameters[PLUGIN_ATTR_NET_HOST]:
Expand All @@ -105,38 +78,6 @@ def _set_device_defaults(self):
b = b.decode('unicode-escape').encode()
self._parameters[PLUGIN_ATTR_CONN_TERMINATOR] = b

# we need to receive data via callback, as the "reply" can be unrelated to
# the sent command. Getting it as return value would assign it to the wrong
# command and discard it... so break the "return result"-chain and don't
# return anything
def _send(self, data_dict, resend_info=None):
if resend_info is None:
resend_info = {}
if resend_info.get('returnvalue') is not None:
self._sending.update({resend_info.get('command'): resend_info})
return self._connection.send(data_dict)

def _resend(self):
if not self.alive or self.suspended:
return
self._sending_lock.acquire(True, 2)
_remove_commands = []
for command in list(self._sending.keys()):
_retry = self._sending[command].get("retry") or 0
_sent = True
if _retry is not None and _retry < self._send_retries:
self.logger.debug(f'Re-sending {command}, retry {_retry}.')
_sent = self.send_command(command, self._sending[command].get("returnvalue"), return_result=True, retry=_retry + 1)
elif _retry is not None and _retry >= self._send_retries:
_sent = False
if _sent is False:
_remove_commands.append(command)
self.logger.info(f"Giving up re-sending {command} after {_retry} retries.")
for command in _remove_commands:
self._sending.pop(command)
if self._sending_lock.locked():
self._sending_lock.release()

def _transform_send_data(self, data=None, **kwargs):
if isinstance(data, dict):
data['limit_response'] = self._parameters[PLUGIN_ATTR_CONN_TERMINATOR]
Expand Down Expand Up @@ -206,17 +147,6 @@ def on_data_received(self, by, data, command=None):
self.logger.warning(f'received data "{data}" for command {command}, error {e} occurred while converting. Discarding data.')
else:
self.logger.debug(f'received data "{data}" for command {command} converted to value {value}.')
if command in self._sending:
self._sending_lock.acquire(True, 2)
_retry = self._sending[command].get("retry") or 0
_compare = self._sending[command].get('returnvalue')
if self._sending[command].get('returntype')(value) == _compare:
self._sending.pop(command)
self.logger.debug(f'Correct answer for {command}, removing from send. Sending {self._sending}')
elif _retry is not None and _retry <= self._send_retries:
self.logger.debug(f'Should send again {self._sending}...')
if self._sending_lock.locked():
self._sending_lock.release()
self._dispatch_callback(command, value, by)

self._process_additional_data(base_command, data, value, custom, by)
Expand Down

0 comments on commit 83dd11f

Please sign in to comment.