Skip to content

Commit

Permalink
denon plugin: implement delay for initial value read
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Jun 1, 2024
1 parent fdc0d48 commit 58d9567
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 13 additions & 5 deletions denon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import sys
import threading
import time
import datetime
from lib.shtime import Shtime

if __name__ == '__main__':
builtins.SDP_standalone = True
Expand Down Expand Up @@ -63,7 +65,13 @@ def on_connect(self, by=None):
self.scheduler_add('resend', self._resend, cycle=self._sendretry_cycle)
self.logger.debug("Checking for custom input names.")
self.send_command('general.custom_inputnames')
self._read_initial_values(force=True)
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():
Expand Down Expand Up @@ -101,10 +109,10 @@ def _set_device_defaults(self):
# 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):
if data_dict.get('returnvalue') is not None:
self._sending.update({data_dict['command']: data_dict})
self._connection.send(data_dict)
def _send(self, data_dict, resend_info=None):
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:
Expand Down
8 changes: 8 additions & 0 deletions denon/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ parameters:
where no (suiting) answer got received.
'

delay_initial_read:
type: num
default: 0

description:
de: Warte nach Verbindungsaufbau mit dem Abfragen von Werten
en: Wait after connection with querying values

connect_cycle:
type: num
default: 3
Expand Down

0 comments on commit 58d9567

Please sign in to comment.