-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundtouch_manual.py
49 lines (41 loc) · 1.54 KB
/
soundtouch_manual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from libsoundtouch import soundtouch_device
from libsoundtouch.utils import Source, Type
from prettytable import PrettyTable
import re
devices = ['DEVICE_IP', # Device 1
'DEVICE_IP', # Device 2
'DEVICE_IP', # Device 3
'DEVICE_IP'] # Device 4
def discoverDevices():
x = PrettyTable()
x.field_names = ["DEVICE NAME", "DEVICE ID", "DEVICE IP", "DEVICE MAC", "DEVICE STATUS", "ZONE STATUS", "DEVICE TYPE"]
x.align["DEVICE NAME"] = "l"
x.align["DEVICE ID"] = "l"
x.align["DEVICE IP"] = "l"
x.align["DEVICE MAC"] = "l"
x.align["DEVICE STATUS"] = "l"
x.align["ZONE STATUS"] = "l"
x.align["DEVICE TYPE"] = "l"
for device in devices:
device = soundtouch_device(device)
status = device.status()
zone_status = device.zone_status()
mac = re.sub(r'(.{2})(?!$)', r'\1:', device.config.mac_address)
if zone_status:
if zone_status.is_master:
zone_status = 'Master'
else:
zone_status = 'Slave'
x.add_row([device.config.name, device.config.device_id, device.config.device_ip, mac , status.source, zone_status, device.config.type])
print(x)
def findMaster():
for device in devices:
device = soundtouch_device(device)
status = device.status()
zone_status = device.zone_status()
if zone_status:
if zone_status.is_master:
master = device.config.name
print (str(master) + " is Master")
discoverDevices()
findMaster()