mirror of
https://github.com/Matysh/houseplan-card
synced 2026-07-31 16:38:31 +00:00
Owner's spec (2026-07-29), agreed points: one 'Run' action covering the three runnable domains of HA (a script is the idiomatic 'action' — with automations alone people would build trigger-less dummies); the confirm checkbox guards BOTH toggle and run; covers and valves join the card-wide toggle so curtains work natively. - marker.tap_action gains 'run'; marker.tap_target (schema-bounded to automation./script./scene. ids); marker.tap_confirm. - the dialog: a searchable picker over the three domains (friendly name + kind), save refuses a run action without a target, a vanished target gets a warning hint; the checkbox shows for any actionable tap (explicit or effective-default toggle). - the tap: automation.trigger / script.turn_on / scene.turn_on, started/ error toasts; with confirm on — our own dialog (not window.confirm, it must work on a wall tablet), Esc/backdrop/Cancel = no call. The guard covers the controls-toggle path too. - 'run' is explicit-only by construction: it needs a per-marker target, so it can never arrive as a card-wide default. - covers: the old test pinned 'garage stays shut' — that intent survives as COVER_GUARDED_CLASSES (garage/door/gate stay out of the CARD-WIDE toggle; an explicit per-device toggle remains the owner's conscious choice). Locks/alarms stay forbidden everywhere, run included is not affected — we do not inspect automation contents, same trust as HA's own Run button. Tests: unit resolveTapAction/runServiceFor + cover guard, backend schema parity picks 'run' automatically + tap_target bounds, smoke_tap_run with 11 assertions (picker, search, save guard, confirm cancel/ok, per-domain services, missing target). smoke_tap_ctx: 4 options now. Inventory: 148 / 52 / 43 / 72.
77 lines
4.6 KiB
JavaScript
77 lines
4.6 KiB
JavaScript
// ТЗ 2026-07-29: действие по нажатию «Запустить автоматизацию/скрипт/сцену»
|
|
// с пикером и поиском + чекбокс «Спрашивать подтверждение» для toggle/run.
|
|
import { launch, checkAll, finish } from './serve.mjs';
|
|
const { page, browser } = await launch();
|
|
const out = await page.evaluate(async () => {
|
|
const o = {};
|
|
const c = window.__card;
|
|
const sr = () => c.shadowRoot || c.renderRoot;
|
|
const calls = [];
|
|
c.hass = { ...c.hass,
|
|
states: { ...c.hass.states,
|
|
'automation.evening': { state: 'on', attributes: { friendly_name: 'Вечерний свет' } },
|
|
'script.curtains': { state: 'off', attributes: { friendly_name: 'Шторы' } },
|
|
'scene.movie': { state: '', attributes: { friendly_name: 'Кино' } } },
|
|
callService: async (dom, svc, data) => { calls.push([dom, svc, data]); return {}; } };
|
|
|
|
// --- диалог: выбор run + пикер с поиском --------------------------------
|
|
const d = c._devices.find((x) => x.space === 'f1' && x.bindingKind === 'device');
|
|
c._setMode('devices'); await c.updateComplete;
|
|
c._openMarkerDialog(d); await c.updateComplete;
|
|
c._markerDialog = { ...c._markerDialog, tapAction: 'run' }; await c.updateComplete;
|
|
o.pickerShown = !!sr().querySelector('.dialog .candlist');
|
|
c._markerDialog = { ...c._markerDialog, runFilter: 'штор' }; await c.updateComplete;
|
|
const cands = [...sr().querySelectorAll('.dialog .cand')].map((x) => x.textContent);
|
|
o.searchWorks = cands.length >= 1 && cands.some((t) => t.includes('Шторы'));
|
|
// сохранение без цели блокируется
|
|
await c._saveMarker(); await c.updateComplete;
|
|
o.saveBlockedWithoutTarget = !!c._markerDialog;
|
|
// выбираем цель + подтверждение, сохраняем
|
|
c._markerDialog = { ...c._markerDialog, tapTarget: 'script.curtains', tapConfirm: true };
|
|
await c.updateComplete;
|
|
o.confirmCheckboxShown = [...sr().querySelectorAll('.dialog .srcrow')].length >= 2;
|
|
await c._saveMarker(); await c.updateComplete;
|
|
const saved = (c._serverCfg.markers || []).find((m) => m.binding === 'device:' + d.bindingRef);
|
|
o.markerSaved = saved?.tap_action === 'run' && saved?.tap_target === 'script.curtains' && saved?.tap_confirm === true;
|
|
|
|
// --- тап: подтверждение → отмена → вызова нет ---------------------------
|
|
c._setMode('view'); c._regSignature = ''; c._maybeRebuildDevices();
|
|
c.requestUpdate(); await c.updateComplete;
|
|
const dev = c._devices.find((x) => x.id === (saved?.id ?? d.id)) || c._devices.find((x) => x.bindingRef === d.bindingRef);
|
|
c._clickDevice({ stopPropagation() {} }, dev); await c.updateComplete;
|
|
o.confirmDialogShown = !!c._tapConfirm && c._tapConfirm.text.includes('Шторы');
|
|
c._tapConfirm = null; await c.updateComplete;
|
|
o.cancelNoCall = calls.length === 0;
|
|
|
|
// --- тап: подтвердили → script.turn_on ----------------------------------
|
|
c._clickDevice({ stopPropagation() {} }, dev); await c.updateComplete;
|
|
const conf = c._tapConfirm; c._tapConfirm = null; conf.exec();
|
|
await new Promise((r) => setTimeout(r, 10));
|
|
o.runCalled = calls.length === 1 && calls[0][0] === 'script' && calls[0][1] === 'turn_on'
|
|
&& calls[0][2].entity_id === 'script.curtains';
|
|
|
|
// --- без подтверждения: сразу вызов; автоматизация → trigger ------------
|
|
c._serverCfg.markers = c._serverCfg.markers.map((m) =>
|
|
m.id === (saved?.id ?? d.id) ? { ...m, tap_target: 'automation.evening', tap_confirm: null } : m);
|
|
c._cfgEpoch++; c._regSignature = ''; c._maybeRebuildDevices(); await c.updateComplete;
|
|
const dev2 = c._devices.find((x) => x.bindingRef === d.bindingRef);
|
|
calls.length = 0;
|
|
c._clickDevice({ stopPropagation() {} }, dev2); await c.updateComplete;
|
|
await new Promise((r) => setTimeout(r, 10));
|
|
o.automationTriggered = calls.length === 1 && calls[0][0] === 'automation' && calls[0][1] === 'trigger';
|
|
o.noConfirmWhenOff = !c._tapConfirm;
|
|
|
|
// --- цель удалена → тост, вызова нет ------------------------------------
|
|
const states2 = { ...c.hass.states }; delete states2['automation.evening'];
|
|
c.hass = { ...c.hass, states: states2 };
|
|
calls.length = 0;
|
|
c._clickDevice({ stopPropagation() {} }, dev2); await c.updateComplete;
|
|
o.missingTargetSafe = calls.length === 0 && !!c._toast;
|
|
|
|
// очистка
|
|
c._serverCfg.markers = c._serverCfg.markers.filter((m) => m.id !== (saved?.id ?? d.id));
|
|
c._cfgEpoch++; c._regSignature = ''; c._maybeRebuildDevices();
|
|
return o;
|
|
});
|
|
await finish(browser, checkAll(out));
|