Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(home): stop a live house stealing the keyboard from the person using it

nirholas83b4656de768
diff --git a/src/home/scene-fallback.js b/src/home/scene-fallback.js
index 692a09a29..09155d946 100644
--- a/src/home/scene-fallback.js
+++ b/src/home/scene-fallback.js
@@ -48,8 +48,28 @@ export function createHomeFallback(container, options = {}) {
let stale = false;
let busy = new Set();
+ /**
+ * Rebuild the flat house, and put the keyboard back where it was.
+ *
+ * This list is the accessible route into a live house: a canvas is one opaque
+ * element, so for a screen-reader or keyboard user these rows ARE the house.
+ * And a live house never stops talking. Every state event on the stream (a
+ * light dimming, a sensor ticking, the demo integration's thermostat drifting)
+ * lands here and rebuilds every node, which used to drop the focused control
+ * on the floor mid-press: the person tabs to Unlock, the kitchen sensor
+ * reports, the button they were on is destroyed and their Enter goes to the
+ * document. Measured against a real Home Assistant, where it also made the
+ * no-mouse journey in tests/e2e/home-a11y.spec.js fail at random.
+ *
+ * The fix is to restore by identity rather than by node: `data-act-for` plus
+ * `data-act-service` name an action control, `data-entity-id` a device row and
+ * `data-room-id` a room, and each one's replacement is the same control by
+ * every measure a person cares about. Selection state (`scrollTop`) is left
+ * alone by the rebuild, so only focus needs carrying.
+ */
function render() {
if (!model) return;
+ const keep = focusKey(document.activeElement);
list.innerHTML = '';
for (const floor of model.floors) {
const section = document.createElement('section');
@@ -68,6 +88,31 @@ export function createHomeFallback(container, options = {}) {
section.appendChild(grid);
list.appendChild(section);
}
+ if (keep) restoreFocus(keep);
+ }
+
+ /**
+ * A selector that finds this element's replacement after a rebuild, or null
+ * when the element is not one of ours (the page's own chrome keeps its focus
+ * without help, because this only ever replaces what is inside `list`).
+ */
+ function focusKey(node) {
+ if (!(node instanceof HTMLElement) || !list.contains(node)) return null;
+ if (node.dataset.actFor) {
+ return `[data-act-for="${cssEscape(node.dataset.actFor)}"]` +
+ (node.dataset.actService ? `[data-act-service="${cssEscape(node.dataset.actService)}"]` : '');
+ }
+ if (node.dataset.entityId) return `[data-entity-id="${cssEscape(node.dataset.entityId)}"]`;
+ if (node.dataset.roomId) return `[data-room-id="${cssEscape(node.dataset.roomId)}"]`;
+ return null;
+ }
+
+ function restoreFocus(selector) {
+ const again = list.querySelector(selector);
+ // Not an error when it is gone: a device really can leave the house
+ // between two frames, and the reader is better off where the browser puts
+ // them than focused on something that is no longer there.
+ if (again instanceof HTMLElement) again.focus({ preventScroll: true });
}
function roomCard(room) {
diff --git a/tests/e2e/home-a11y.spec.js b/tests/e2e/home-a11y.spec.js
index 6e8b4e176..dc4c60f7a 100644
--- a/tests/e2e/home-a11y.spec.js
+++ b/tests/e2e/home-a11y.spec.js
@@ -336,11 +336,38 @@ test('a Fahrenheit house reads in Fahrenheit whatever the browser locale is', as
}
});
+/**
+ * Publish a locale to THIS page only, so the runtime can pick it.
+ *
+ * /i18n.js reads /locales/manifest.json as the allowlist for `?lang=`, and
+ * scripts/i18n-translate.mjs only lists a locale there once its catalog is
+ * complete, which is the right rule: a half-translated language in the picker
+ * renders as English with a foreign heading. It also means a locale with a
+ * translation backlog cannot be exercised at all, and the layout question this
+ * file asks (does the lane use logical properties) is not the same question as
+ * the catalog question.
+ *
+ * So the manifest ENTRY is the only thing faked. Everything else is the real
+ * runtime doing its real work: it reads `?lang=`, sets `lang` and `dir` on the
+ * document, fetches the committed public/locales/ar.json off disk and swaps the
+ * DOM from it. A hand-set `dir` attribute would prove none of that.
+ */
+async function publishLocale(page, code, dir) {
+ await page.route('**/locales/manifest.json', (route) =>
+ route.fulfill({
+ status: 200,
+ contentType: 'application/json',
+ body: JSON.stringify({ default: 'en', locales: [{ code: 'en', name: 'English', dir: 'ltr' }, { code, name: code, dir }] }),
+ }),
+ );
+}
+
test('an RTL locale lays the house out right to left without breaking it', async ({ page }) => {
await signIn(page, 'owner');
// A real RTL locale from public/locales, driven the way a visitor drives it,
// not a CSS override: the point is that the runtime sets dir and the layout
// answers, which a hand-set attribute would prove nothing about.
+ await publishLocale(page, 'ar', 'rtl');
await page.goto(`/smart-home/${homeId}?view=2d&lang=ar`, { waitUntil: 'domcontentloaded' });
await expect(page.locator('#hs-rooms')).not.toHaveAttribute('aria-busy', 'true', { timeout: 120_000 });
await expect(page.locator('html')).toHaveAttribute('dir', 'rtl', { timeout: 60_000 });
@@ -366,6 +393,7 @@ test("a user's own device names are never translated", async ({ page }) => {
await signIn(page, 'owner');
const light = await anyLight(instance);
+ await publishLocale(page, 'ar', 'rtl');
const seen = [];
for (const lang of ['en', 'ar']) {
await page.goto(`/smart-home/${homeId}?view=2d&lang=${lang}`, { waitUntil: 'domcontentloaded' });
@@ -376,6 +404,12 @@ test("a user's own device names are never translated", async ({ page }) => {
// The house's own words for its own things, byte for byte, in both locales.
expect(seen[1]).toBe(seen[0]);
expect(seen[0]).toBe(light.name);
+ // ...and the page really was in Arabic for the second read. Without this the
+ // assertion above is satisfied by a page that silently stayed in English,
+ // which is exactly what happens when the locale is not published.
+ await expect(page.locator('html')).toHaveAttribute('lang', 'ar');
+ const railHead = (await page.locator('.hs-rail-head').textContent()) || '';
+ expect(railHead.trim(), 'the shell around the names is translated').not.toBe('Rooms');
});
test('prefers-reduced-motion turns the scene\'s motion off, in 3D and in the flat house', async ({ page }) => {