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:
2026-09-14 21:39:31 +02:00
co-authored by Claude Opus 5
parent 4affd18b3b
commit 1a1fcc84d6
9 changed files with 198 additions and 33 deletions
+48 -1
View File
@@ -12,7 +12,7 @@ from types import SimpleNamespace
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from controller import Controller # noqa: E402
from controller import Controller, stepped_level # noqa: E402
from tests.fakes import FakeAvr, FakeHeos # noqa: E402
PAIR = {3, 4} # the two Home 200s
@@ -33,6 +33,7 @@ def build(tmpdir):
"living_room_group": {"label": "Living Room", "heos_name": "Denon Home 200 L"},
},
AVR_INPUT_CODES=[],
VOLUME_STEP=5,
MEMBERS_FILE=str(Path(tmpdir) / "members.json"),
)
return Controller(cfg), heos, avr
@@ -126,6 +127,23 @@ class PanelTest(unittest.TestCase):
self.panel.set_volume("home400", 1)
self.assertEqual(self.panel.nudge_volume("home400", -9), 0)
# -- volume in whole steps -------------------------------------------
def test_a_tap_lands_on_the_next_multiple(self):
self.panel.set_volume("home400", 23)
self.assertEqual(self.panel.step_volume("home400", 1), 25)
self.panel.set_volume("home400", 23)
self.assertEqual(self.panel.step_volume("home400", -1), 20)
def test_a_level_already_on_a_multiple_moves_a_whole_step(self):
self.panel.set_volume("home400", 25)
self.assertEqual(self.panel.step_volume("home400", 1), 30)
self.panel.set_volume("home400", 25)
self.assertEqual(self.panel.step_volume("home400", -1), 20)
def test_a_burst_of_taps_snaps_once_then_moves_whole_steps(self):
self.panel.set_volume("living_room_group", 23)
self.assertEqual(self.panel.step_volume("living_room_group", 3), 35)
# -- the AVR ---------------------------------------------------------
def test_renamed_inputs_and_selection(self):
deadline = time.time() + 5
@@ -140,6 +158,13 @@ class PanelTest(unittest.TestCase):
{"code": "SAT/CBL", "name": "TV Box"}],
)
self.assertEqual(self.panel.avr.current_input(), {"code": "MPLAY", "name": "Apple TV"})
# "Old DVD" is deleted in the AVR's setup menu, so the picker skips
# it -- but it keeps its name, in case the AVR is sitting on it.
self.assertNotIn("DVD", [s["code"] for s in self.panel.avr.inputs()])
self.assertIn({"code": "DVD", "name": "Old DVD"}, self.panel.avr.all_inputs())
self.assertEqual(self.panel.avr.name_for("DVD"), "Old DVD")
self.assertEqual(self.panel.avr.select_input("GAME"), {"code": "GAME", "name": "PlayStation"})
self.assertEqual(self.avr.input, "GAME")
@@ -162,5 +187,27 @@ class PanelTest(unittest.TestCase):
self.assertTrue(all(r["available"] is False for r in state["rooms"]))
class StepArithmeticTest(unittest.TestCase):
"""The rule on its own -- no speakers involved."""
def test_up_from_between_multiples(self):
self.assertEqual([stepped_level(23, n, 5) for n in (1, 2, 3)], [25, 30, 35])
def test_down_from_between_multiples(self):
self.assertEqual([stepped_level(23, -n, 5) for n in (1, 2, 3)], [20, 15, 10])
def test_from_a_multiple(self):
self.assertEqual(stepped_level(25, 1, 5), 30)
self.assertEqual(stepped_level(25, -1, 5), 20)
def test_clamped_to_the_ends(self):
self.assertEqual(stepped_level(98, 1, 5), 100)
self.assertEqual(stepped_level(2, -1, 5), 0)
self.assertEqual(stepped_level(0, -1, 5), 0)
def test_no_taps_changes_nothing(self):
self.assertEqual(stepped_level(23, 0, 5), 23)
if __name__ == "__main__":
unittest.main()