+28
-1
@@ -346,6 +346,31 @@ class Controller:
|
||||
self._fresh()
|
||||
self.heos.command("player/set_play_state", pid=self.playback_pid(key), state=state)
|
||||
|
||||
def get_play_state(self, key: str) -> str:
|
||||
""""play", "pause" or "stop" for whatever this room is doing."""
|
||||
with self._lock:
|
||||
self._fresh()
|
||||
reply = self.heos.command("player/get_play_state", pid=self.playback_pid(key))
|
||||
return parse_message(reply["heos"]["message"]).get("state", "stop")
|
||||
|
||||
def toggle_play(self, key: str, state: str = None) -> str:
|
||||
"""Start or stop a room. With no state, flips whatever it is doing
|
||||
now -- read from the speakers rather than trusted from the phone,
|
||||
whose copy can be a few seconds old.
|
||||
|
||||
A room that is grouped shares the AVR's transport, so this stops the
|
||||
whole group. That is HEOS's doing, not ours: a group has one thing
|
||||
playing, by definition.
|
||||
"""
|
||||
with self._lock:
|
||||
self._fresh()
|
||||
if state is None:
|
||||
state = "pause" if self.get_play_state(key) == "play" else "play"
|
||||
self.heos.command(
|
||||
"player/set_play_state", pid=self.playback_pid(key), state=state
|
||||
)
|
||||
return state
|
||||
|
||||
def skip(self, key: str, direction: str):
|
||||
with self._lock:
|
||||
self._fresh()
|
||||
@@ -388,11 +413,13 @@ class Controller:
|
||||
"available": True,
|
||||
"grouped": key in joined,
|
||||
"volume": None,
|
||||
"play_state": None,
|
||||
"error": None,
|
||||
}
|
||||
try:
|
||||
scope, obj_id = self._volume_handles(key)[0]
|
||||
room["volume"] = self._read_volume(scope, obj_id)
|
||||
room["play_state"] = self.get_play_state(key)
|
||||
except (TargetError, HeosError, KeyError) as exc:
|
||||
room["available"] = False
|
||||
room["error"] = str(exc)
|
||||
@@ -402,7 +429,7 @@ class Controller:
|
||||
snapshot["errors"].append(str(exc))
|
||||
snapshot["rooms"] = [
|
||||
{"key": key, "label": self.cfg.TARGETS[key]["label"], "available": False,
|
||||
"grouped": False, "volume": None, "error": str(exc)}
|
||||
"grouped": False, "volume": None, "play_state": None, "error": str(exc)}
|
||||
for key in self.cfg.ROOM_KEYS
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user