diff --git a/src/utils/device-output.ts b/src/utils/device-output.ts index 0ee106b..25e545b 100644 --- a/src/utils/device-output.ts +++ b/src/utils/device-output.ts @@ -228,7 +228,10 @@ export function humanState(human: DeviceHumanStatus): string { export function humanFields(human: DeviceHumanStatus, now: number = Date.now()): Field[] { const fields: Field[] = [['state', humanState(human)]]; if (human.reason) fields.push(['reason', human.reason]); - if (human.since) fields.push(['asked', formatWhen(human.since, now)]); + // A person who took control unasked: the reason is " took control", + // and nobody asked for anything. + const tookControl = human.human_in_control && !!human.reason?.endsWith(' took control'); + if (human.since) fields.push([tookControl ? 'since' : 'asked', formatWhen(human.since, now)]); if (human.waiting && human.expires_at) { fields.push(['ends', `${formatWhen(human.expires_at, now)} unless they hand it back`]); } diff --git a/test/unit/device-command.test.ts b/test/unit/device-command.test.ts index 85bf4b1..a8fb123 100644 --- a/test/unit/device-command.test.ts +++ b/test/unit/device-command.test.ts @@ -793,6 +793,9 @@ describe('dcd device', () => { const labels = (h: typeof base | Record) => humanFields(h as typeof base, now).map(([label]) => label); expect(labels(base)).to.deep.equal(['state', 'reason', 'asked', 'ends']); + // Taken unasked: "since", not "asked". A request a person picked up stays "asked". + expect(labels({ ...base, human_in_control: true, reason: 'ann@x.com took control' })).to.deep.equal(['state', 'reason', 'since', 'ends']); + expect(labels({ ...base, human_in_control: true })).to.deep.equal(['state', 'reason', 'asked', 'ends']); const back = { ...base, waiting: false, reason: null, since: null, handed_back: true, note: 'Done', handed_back_at: '2026-10-19T10:00:00Z' }; expect(humanFields(back, now)).to.deep.include(['note', 'Done']); expect(humanFields(back, now)[0]).to.deep.equal(['state', 'handed back']);