This commit is contained in:
1 parent
83a26c9476
commit
0c8672789d
11 files changed
+111
-120
No files matched your search
+17
-17
@@ -107,7 +107,7 @@ class Controller:
|
||||
"""The AVR is always a plain player. Resolving it by player name
|
||||
matters: once it leads a group, HEOS also reports a *group* under
|
||||
the very same name."""
|
||||
target = self.cfg.TARGETS[self.cfg.HOST_KEY]
|
||||
target = self.cfg.ROOMS[self.cfg.HOST_ROOM]
|
||||
pid = self._player_pid(target["heos_name"])
|
||||
if pid is None:
|
||||
raise TargetError(f"No HEOS player named '{target['heos_name']}' (the AVR) was found")
|
||||
@@ -115,12 +115,12 @@ class Controller:
|
||||
|
||||
def member_pids(self, key: str) -> list:
|
||||
"""The pid of the one player that is this room, as a list."""
|
||||
if key not in self.cfg.TARGETS:
|
||||
if key not in self.cfg.ROOMS:
|
||||
raise TargetError(f"Unknown room '{key}'")
|
||||
if key == self.cfg.HOST_KEY:
|
||||
if key == self.cfg.HOST_ROOM:
|
||||
return [self._host_pid()]
|
||||
|
||||
name = self.cfg.TARGETS[key]["heos_name"]
|
||||
name = self.cfg.ROOMS[key]["heos_name"]
|
||||
pid = self._player_pid(name)
|
||||
if pid is None:
|
||||
raise TargetError(
|
||||
@@ -221,7 +221,7 @@ class Controller:
|
||||
|
||||
def joined_keys(self) -> list:
|
||||
joined, host_pids = [], self._host_group_pids()
|
||||
for key in self.cfg.ROOM_KEYS:
|
||||
for key in self.cfg.GUEST_ROOMS:
|
||||
try:
|
||||
if host_pids & set(self.member_pids(key)):
|
||||
joined.append(key)
|
||||
@@ -256,7 +256,7 @@ class Controller:
|
||||
with self._lock:
|
||||
self.scan()
|
||||
wanted = set(self.joined_keys()) | {key}
|
||||
self.group_targets(self.cfg.HOST_KEY, [k for k in self.cfg.ROOM_KEYS if k in wanted])
|
||||
self.group_targets(self.cfg.HOST_ROOM, [k for k in self.cfg.GUEST_ROOMS if k in wanted])
|
||||
self.scan()
|
||||
self._nudge_avr_input()
|
||||
return self.joined_keys()
|
||||
@@ -274,7 +274,7 @@ class Controller:
|
||||
try:
|
||||
current = self.avr_current_input()
|
||||
if current:
|
||||
self.play_heos_input(self.cfg.HOST_KEY, current["code"])
|
||||
self.play_heos_input(self.cfg.HOST_ROOM, current["code"])
|
||||
except HeosError:
|
||||
pass
|
||||
|
||||
@@ -292,12 +292,12 @@ class Controller:
|
||||
"""Make the AVR's group contain exactly these rooms and no others."""
|
||||
with self._lock:
|
||||
self.scan()
|
||||
wanted = [k for k in self.cfg.ROOM_KEYS if k in joined]
|
||||
wanted = [k for k in self.cfg.GUEST_ROOMS if k in joined]
|
||||
for key in list(self.joined_keys()):
|
||||
if key not in wanted:
|
||||
self.ungroup(key)
|
||||
if wanted:
|
||||
self.group_targets(self.cfg.HOST_KEY, wanted)
|
||||
self.group_targets(self.cfg.HOST_ROOM, wanted)
|
||||
self.scan()
|
||||
return self.joined_keys()
|
||||
|
||||
@@ -414,7 +414,7 @@ class Controller:
|
||||
"""{"code", "name"} pairs for the picker -- heos_inputs()'s shape,
|
||||
renamed to match what the UI and /api/avr/* already send and
|
||||
expect."""
|
||||
sources = self.heos_inputs(self.cfg.HOST_KEY)
|
||||
sources = self.heos_inputs(self.cfg.HOST_ROOM)
|
||||
return [{"code": s["input_id"], "name": s["name"]} for s in sources]
|
||||
|
||||
def avr_current_input(self):
|
||||
@@ -435,7 +435,7 @@ class Controller:
|
||||
return {"code": mid, "name": payload.get("station") or payload.get("song") or mid}
|
||||
|
||||
def avr_select_input(self, code: str) -> dict:
|
||||
self.play_heos_input(self.cfg.HOST_KEY, code)
|
||||
self.play_heos_input(self.cfg.HOST_ROOM, code)
|
||||
name = next((s["name"] for s in self.avr_inputs() if s["code"] == code), code)
|
||||
return {"code": code, "name": name}
|
||||
|
||||
@@ -476,7 +476,7 @@ class Controller:
|
||||
matched up as replies come back rather than asked for one at a
|
||||
time."""
|
||||
snapshot = {
|
||||
"host": {"key": self.cfg.HOST_KEY, "label": self.cfg.TARGETS[self.cfg.HOST_KEY]["label"]},
|
||||
"host": {"key": self.cfg.HOST_ROOM, "label": self.cfg.ROOMS[self.cfg.HOST_ROOM]["label"]},
|
||||
"rooms": [],
|
||||
"avr": {"connected": False, "input": None, "inputs": [], "volume": None},
|
||||
"heos_ok": True,
|
||||
@@ -491,7 +491,7 @@ class Controller:
|
||||
joined = set(self.joined_keys())
|
||||
|
||||
room_pids, room_errors = {}, {}
|
||||
for key in self.cfg.ROOM_KEYS:
|
||||
for key in self.cfg.GUEST_ROOMS:
|
||||
try:
|
||||
room_pids[key] = self.member_pids(key)[0]
|
||||
except TargetError as exc:
|
||||
@@ -526,10 +526,10 @@ class Controller:
|
||||
else:
|
||||
by_room.setdefault(key, {})[field] = result
|
||||
|
||||
for key in self.cfg.ROOM_KEYS:
|
||||
for key in self.cfg.GUEST_ROOMS:
|
||||
room = {
|
||||
"key": key,
|
||||
"label": self.cfg.TARGETS[key]["label"],
|
||||
"label": self.cfg.ROOMS[key]["label"],
|
||||
"available": True,
|
||||
"grouped": key in joined,
|
||||
"volume": None,
|
||||
@@ -574,10 +574,10 @@ class Controller:
|
||||
snapshot["heos_ok"] = False
|
||||
snapshot["errors"].append(str(exc))
|
||||
snapshot["rooms"] = [
|
||||
{"key": key, "label": self.cfg.TARGETS[key]["label"], "available": False,
|
||||
{"key": key, "label": self.cfg.ROOMS[key]["label"], "available": False,
|
||||
"grouped": False, "volume": None, "play_state": None, "spotify": False,
|
||||
"now_playing": None, "error": str(exc)}
|
||||
for key in self.cfg.ROOM_KEYS
|
||||
for key in self.cfg.GUEST_ROOMS
|
||||
]
|
||||
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user