mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-23 21:17:03 +02:00
added reader thread
This commit is contained in:
parent
2c0cbf0f1e
commit
6e3a569057
1 changed files with 32 additions and 6 deletions
|
@ -1,17 +1,40 @@
|
|||
import sys
|
||||
import telnetlib
|
||||
import json
|
||||
import threading
|
||||
import time
|
||||
|
||||
HOST = "localhost"
|
||||
|
||||
tn = telnetlib.Telnet(HOST, 1705)
|
||||
telnet = telnetlib.Telnet(HOST, 1705)
|
||||
|
||||
|
||||
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", 1)
|
||||
if response:
|
||||
jresponse = json.loads(response)
|
||||
print(json.dumps(jresponse, indent=2))
|
||||
print("\r\n")
|
||||
|
||||
|
||||
def doRequest( str ):
|
||||
tn.write(str)
|
||||
response = json.loads(tn.read_until("\r\n"))
|
||||
print(json.dumps(response, indent=2))
|
||||
print(str)
|
||||
telnet.write(str)
|
||||
time.sleep(1)
|
||||
return;
|
||||
|
||||
|
||||
t_stop= threading.Event()
|
||||
t = ReaderThread(telnet, t_stop)
|
||||
t.start()
|
||||
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"System.GetStatus\", \"id\": 2}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"System.GetStatus\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\"}, \"id\": 2}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetVolume\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"volume\": 83}, \"id\": 2}\r\n")
|
||||
|
@ -19,5 +42,8 @@ doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetLatency\", \"params\":
|
|||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetName\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"name\": \"living room\"}, \"id\": 2}\r\n")
|
||||
doRequest("{\"jsonrpc\": \"2.0\", \"method\": \"Client.SetMute\", \"params\": {\"client\": \"00:21:6a:7d:74:fc\", \"mute\": false}, \"id\": 2}\r\n")
|
||||
|
||||
|
||||
tn.close
|
||||
s = raw_input("")
|
||||
print(s)
|
||||
t_stop.set();
|
||||
t.join()
|
||||
telnet.close
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue