Keep a sleep between polls to the Snapcast servers
This commit is contained in:
parent
2d2db499be
commit
55f1a33d90
1 changed files with 10 additions and 3 deletions
|
@ -31,10 +31,11 @@ class MusicSnapcastBackend(Backend):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_DEFAULT_SNAPCAST_PORT = 1705
|
_DEFAULT_SNAPCAST_PORT = 1705
|
||||||
|
_DEFAULT_POLL_SECONDS = 5 # Poll servers each 5 seconds
|
||||||
_SOCKET_EOL = '\r\n'.encode()
|
_SOCKET_EOL = '\r\n'.encode()
|
||||||
|
|
||||||
def __init__(self, hosts=['localhost'], ports=[_DEFAULT_SNAPCAST_PORT],
|
def __init__(self, hosts=['localhost'], ports=[_DEFAULT_SNAPCAST_PORT],
|
||||||
*args, **kwargs):
|
poll_seconds=_DEFAULT_POLL_SECONDS, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
:param hosts: List of Snapcast server names or IPs to monitor (default:
|
:param hosts: List of Snapcast server names or IPs to monitor (default:
|
||||||
`['localhost']`
|
`['localhost']`
|
||||||
|
@ -43,12 +44,17 @@ class MusicSnapcastBackend(Backend):
|
||||||
:param ports: List of control ports for the configured Snapcast servers
|
:param ports: List of control ports for the configured Snapcast servers
|
||||||
(default: `[1705]`)
|
(default: `[1705]`)
|
||||||
:type ports: list[int]
|
:type ports: list[int]
|
||||||
|
|
||||||
|
:param poll_seconds: How often the backend will poll remote servers for
|
||||||
|
status updated (default: 5 seconds)
|
||||||
|
:type poll_seconds: float
|
||||||
"""
|
"""
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
self.hosts = hosts[:]
|
self.hosts = hosts[:]
|
||||||
self.ports = ports[:]
|
self.ports = ports[:]
|
||||||
|
self.poll_seconds = poll_seconds
|
||||||
self._socks = {}
|
self._socks = {}
|
||||||
self._threads = {}
|
self._threads = {}
|
||||||
self._statuses = {}
|
self._statuses = {}
|
||||||
|
@ -142,7 +148,7 @@ class MusicSnapcastBackend(Backend):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._disconnect(host, port)
|
self._disconnect(host, port)
|
||||||
time.sleep(5)
|
time.sleep(self.poll_seconds)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -168,9 +174,10 @@ class MusicSnapcastBackend(Backend):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._disconnect(host, port)
|
self._disconnect(host, port)
|
||||||
time.sleep(5)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
finally:
|
||||||
|
time.sleep(self.poll_seconds)
|
||||||
|
|
||||||
return _thread
|
return _thread
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue