-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrouping.py
38 lines (34 loc) · 1.4 KB
/
grouping.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
import time
import soco
from soco import SoCo
import logging
import logging.handlers
log_file_name = 'logs/MyLog'
# use very short interval for this example, typical 'when' would be 'midnight' and no explicit interval
handler = logging.handlers.TimedRotatingFileHandler(log_file_name, when="D", backupCount=5)
handler.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
logger = logging.getLogger() # or pass string to give it a name
logger.addHandler(handler)
logger.setLevel(logging.INFO)
while True:
try:
#devices = {device.player_name: device for device in soco.discover()}
#print(devices)
primary = SoCo('192.168.68.70') #devices['Kitchen']
#logger.info(devices)
logger.info(primary.all_groups)
#print(primary.volume)
biggestGroup = max(len(group.members) for group in primary.all_groups)
logger.info(f'Biggest Group = {biggestGroup}')
secondary = SoCo('192.168.68.71') #devices['Dining Room']
if (secondary.volume != primary.volume):
secondary.volume = primary.volume
logger.info("Changing secondary volume to match primary")
if biggestGroup < 2:
logger.info(f'joining groups')
secondary.join(primary)
time.sleep(1)
primary.play()
except Exception as err:
logger.exception(f'{type(err).__name__} trying to reconnect...')
time.sleep(30)