feat(box): the box's NixOS system as a module, and lib.mkBox from a few names
check / check (push) Canceled after 0s

The box within reach of the couch: a Raspberry Pi 3B with the AIY Voice
HAT, from the first household's configuration, made generic.

- box/body: the button service, in Python: press and talk, turns by
  voice, a press interrupts; the look signal
- box/*.js: the ir and look capabilities, behind gates, for the brain;
  the ask client, the box's side of a conversation
- box/module.nix: the services, each confined to the devices and
  addresses it needs; the private network as an option (a tailnet by
  default); the Pico found by its USB IDs, as /dev/pdtv26-ir
- box/voicehat.nix: the Voice HAT's device tree overlay and ALSA setup
- lib.mkBox: a box's whole system from its name, the home server's,
  the Wi-Fi network's, and who looks after it
- checks: box-js, box-py (doctests and pyflakes), and box-system (an
  example box's system evaluates)

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-02 16:18:17 -06:00
1 parent 2e7156dc36
commit 521998b666
35 files changed
+2165 -3

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
"""Showing that the box is looking: a tap (the look earcon) and a double-flash, while look-server looks.
look-server connects to the socket systemd gives the button service (pdtv26-button.socket) and waits for
"looking" before it grabs a frame: no indication, no look. The flashing lasts as long as the
connection.
"""
import asyncio
import logging
LONGEST_LOOK_S = 60 # a look takes seconds; don't flash forever for a stuck one
class LookSignal:
"""handle(reader, writer) serves one look; for asyncio.start_unix_server.
>>> class Light:
... def looking(self):
... import contextlib
... return contextlib.nullcontext(print("flashing"))
>>> async def play(name): print("play", name)
>>> class Reader:
... async def read(self): return b""
>>> class Writer:
... def write(self, data): print("sent", data)
... async def drain(self): pass
... def close(self): pass
>>> asyncio.run(LookSignal(Light(), play, lambda kind: print("note", kind)).handle(Reader(), Writer()))
flashing
play look
sent b'looking\\n'
note look
"""
def __init__(self, light, play, note):
self.__light, self.__play, self.__note = light, play, note
async def handle(self, reader, writer):
with self.__light.looking():
try:
await self.__play("look")
writer.write(b"looking\n")
await writer.drain()
await asyncio.wait_for(reader.read(), LONGEST_LOOK_S) # until look-server hangs up
except (OSError, asyncio.TimeoutError) as err:
logging.info(f"look: {err!r}")
finally:
writer.close()
logging.info("looked")
self.__note("look")