Snap volume to whole steps, and hide deleted AVR sources
A tap now moves to the next multiple of VOLUME_STEP rather than adding it, so 23 goes to 25 and 25 goes to 30 and the levels stay round. The panel counts taps and lets the speakers do the rounding from whatever level they are actually at, since the phone's copy can be seconds old; the same rule is mirrored in JS so the optimistic number never has to correct itself when the reply lands. The input picker also asks the AVR which sources are still switched on (SSSOD ?) and leaves out the ones deleted in its setup menu. Sources it does not mention are kept, so a model that ignores the command shows its whole list rather than nothing; deleted sources also keep their names, in case the AVR is sitting on one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,25 @@ from heos import HeosClient, HeosError, parse_message
|
||||
MEMBERS_FILE = Path(__file__).with_name("members.json")
|
||||
|
||||
|
||||
def stepped_level(current: int, steps: int, size: int) -> int:
|
||||
"""Where the volume lands after `steps` taps of +/-.
|
||||
|
||||
A tap moves to the next multiple of `size` rather than adding `size`,
|
||||
so a level of 23 with a step of 5 goes 23 -> 25 -> 30 on the way up
|
||||
and 23 -> 20 -> 15 on the way down. Levels that are already on a
|
||||
multiple simply move a whole step.
|
||||
"""
|
||||
if steps > 0:
|
||||
landing = (current // size + steps) * size
|
||||
elif steps < 0:
|
||||
aligned = current // size * size
|
||||
first = current - size if aligned == current else aligned
|
||||
landing = first - (-steps - 1) * size
|
||||
else:
|
||||
return current
|
||||
return max(0, min(100, landing))
|
||||
|
||||
|
||||
class TargetError(ValueError):
|
||||
"""We cannot find that room on the network right now."""
|
||||
|
||||
@@ -218,6 +237,25 @@ class Controller:
|
||||
)
|
||||
return level
|
||||
|
||||
def step_volume(self, key: str, steps: int) -> int:
|
||||
"""Move by whole taps, landing on multiples of VOLUME_STEP.
|
||||
|
||||
Counted in taps rather than points so the speakers' own level is
|
||||
what gets rounded, even when the phone's copy of it is a few
|
||||
seconds stale.
|
||||
"""
|
||||
with self._lock:
|
||||
self._fresh()
|
||||
handles = self._volume_handles(key)
|
||||
level = stepped_level(
|
||||
self._read_volume(*handles[0]), int(steps), self.cfg.VOLUME_STEP
|
||||
)
|
||||
for scope, obj_id in handles:
|
||||
self.heos.command(
|
||||
f"{scope}/set_volume", **{self._id_param(scope): obj_id}, level=level
|
||||
)
|
||||
return level
|
||||
|
||||
def toggle_mute(self, key: str):
|
||||
with self._lock:
|
||||
self._fresh()
|
||||
|
||||
Reference in New Issue
Block a user