feat: mute the TV while the box listens, if the brain turns that on
check / check (push) Waiting to run

whisper hears people better without the show behind them. The brain
sets a mute code (and an unmute code, if not the same) with
mute_while_listening on its ir capability, or turns it off; ir-server
keeps the setting in its state directory.

Mute is often a toggle, and the camera can't reliably tell whether the
sound is off, so the box senses nothing: the setting is the brain's
to turn on or off.

The button service holds a connection to ir-server's conversation
socket for each conversation: ir-server mutes when it opens and
unmutes, with the same codes, when it closes. The socket's group is
the button's alone, and the button still can't send any code.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-03 16:49:58 -06:00
1 parent 5191ee9931
commit f50c871521
10 files changed
+269 -22

No files matched your search

+36 -1
View File
@@ -1,7 +1,7 @@
// Tests for the ir capability, with a fake Pico: no serial port.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { Ir, parseHeard } from './ir.js';
import { Ir, Muting, parseHeard } from './ir.js';
test('listen sorts decoded codes from unparsed bursts', async () => {
const calls = [];
@@ -99,3 +99,38 @@ test('one at a time: a send waits for a listen to finish', async () => {
test('parseHeard of nothing', () => {
assert.deepEqual(parseHeard(''), { codes: [], unparsed: [] });
});
test('muting while listening: off until the brain sets it; a toggle sends one code twice', async () => {
const saves = [];
const sent = [];
const send = async (code) => { sent.push(code); return `sent ${code}`; };
const muting = new Muting(undefined, async (codes) => { saves.push(codes); });
const ir = new Ir(async () => '', muting);
assert.equal(await (await muting.start(send))(), 'muting is off');
assert.deepEqual(sent, []);
assert.match(await ir.muteWhileListening('raw 2390 620 590'), /again when it ends/);
assert.deepEqual(saves, [{ mute: 'raw 2390 620 590', unmute: 'raw 2390 620 590' }]);
const unmute = await muting.start(send);
assert.deepEqual(sent, ['raw 2390 620 590']);
await unmute();
assert.deepEqual(sent, ['raw 2390 620 590', 'raw 2390 620 590']);
});
test('muting with separate codes unmutes with the codes it muted with, even if the setting changes meanwhile', async () => {
const sent = [];
const send = async (code) => { sent.push(code); return `sent ${code}`; };
const muting = new Muting({ mute: 'samsung e0 e0 f0 0f', unmute: '20 DF 90 6F' }, async () => {});
const unmute = await muting.start(send);
assert.match(await muting.set(), /^off/);
await unmute();
assert.deepEqual(sent, ['samsung E0 E0 F0 0F', '20 DF 90 6F']);
assert.equal(muting.codes, undefined);
});
test('muting refuses a bad code, keeps the old setting, and a box without it says so', async () => {
const muting = new Muting({ mute: '20 DF 90 6F' }, async () => {});
await assert.rejects(async () => muting.set('mute please'), /code:/);
assert.deepEqual(muting.codes, { mute: '20 DF 90 6F', unmute: '20 DF 90 6F' });
assert.throws(() => new Ir(async () => '').muteWhileListening('20 DF 90 6F'), /no mute setting/);
});