mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-25 15:06:21 +02:00
wait for server response
This commit is contained in:
parent
934bf4e03f
commit
881d2f71bd
1 changed files with 22 additions and 37 deletions
|
@ -5,46 +5,31 @@ import threading
|
|||
import time
|
||||
|
||||
telnet = telnetlib.Telnet(sys.argv[1], 1705)
|
||||
requestId = 1
|
||||
|
||||
class ReaderThread(threading.Thread):
|
||||
def __init__(self, tn, stop_event):
|
||||
super(ReaderThread, self).__init__()
|
||||
self.tn = tn
|
||||
self.stop_event = stop_event
|
||||
|
||||
def run(self):
|
||||
while (not self.stop_event.is_set()):
|
||||
response = self.tn.read_until("\r\n", 2)
|
||||
if response:
|
||||
print("received: " + response)
|
||||
jresponse = json.loads(response)
|
||||
print(json.dumps(jresponse, indent=2))
|
||||
print("\r\n")
|
||||
|
||||
|
||||
def doRequest( str, id ):
|
||||
print("send: " + str)
|
||||
telnet.write(str)
|
||||
response = telnet.read_until("\r\n", 2)
|
||||
def doRequest( j, requestId ):
|
||||
print("send: " + j)
|
||||
telnet.write(j + "\r\n")
|
||||
while (True):
|
||||
response = telnet.read_until("\r\n", 2)
|
||||
jResponse = json.loads(response)
|
||||
if 'id' in jResponse:
|
||||
if jResponse['id'] == requestId:
|
||||
print("recv: " + response)
|
||||
return;
|
||||
return;
|
||||
|
||||
def setVolume(client, volume):
|
||||
global requestId
|
||||
doRequest(json.dumps({'jsonrpc': '2.0', 'method': 'Client.SetVolume', 'params': {'client': client, 'volume': volume}, 'id': requestId}), requestId)
|
||||
requestId = requestId + 1
|
||||
|
||||
t_stop= threading.Event()
|
||||
#t = ReaderThread(telnet, t_stop)
|
||||
#t.start()
|
||||
|
||||
volume = sys.argv[2]
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"System.GetStatus\", \"id\": 1}\r\n", 1)
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": " + volume + "}, \"id\": 2}\r\n", 2)
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"80:1f:02:ed:fd:e0\", \"volume\": " + volume + "}, \"id\": 3}\r\n", 3)
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"74:da:38:00:85:e2\", \"volume\": " + volume + "}, \"id\": 4}\r\n", 4)
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"80:1f:02:ff:79:6e\", \"volume\": " + volume + "}, \"id\": 5}\r\n", 5)
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"bc:5f:f4:ca:cd:64\", \"volume\": " + volume + "}, \"id\": 6}\r\n", 6)
|
||||
|
||||
time.sleep(1)
|
||||
#s = raw_input("")
|
||||
#print(s)
|
||||
#t_stop.set();
|
||||
#t.join()
|
||||
volume = int(sys.argv[2])
|
||||
doRequest(json.dumps({'jsonrpc': '2.0', 'method': 'System.GetStatus', 'id': 1}), 1)
|
||||
setVolume("00:21:6a:7d:74:fc", volume)
|
||||
setVolume("80:1f:02:ed:fd:e0", volume)
|
||||
setVolume("74:da:38:00:85:e2", volume)
|
||||
setVolume("80:1f:02:ff:79:6e", volume)
|
||||
setVolume("bc:5f:f4:ca:cd:64", volume)
|
||||
telnet.close
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue