[HOME] 3D-карта: добавлены _selectRoom/_highlightZone (фикс ошибки конфигурации); зоны выровнены по стенам и переименованы; план без дублей подписей
lint / hygiene (push) Failing after 24s

This commit is contained in:
root committed 2026-11-02 13:15:43 +03:00
1 parent 186bd3c037
commit 97dd3cecb4
5 files changed
+655 -311

No files matched your search

+32
View File
@@ -358,6 +358,38 @@ class House3dCard extends HTMLElement {
if (this._config.entity) this._toggle(); if (this._config.entity) this._toggle();
} }
_highlightZone(zone) {
const zones = this._zones || {};
for (const id of Object.keys(zones)) {
const mesh = zones[id];
if (!mesh || !mesh.material) continue;
const mats = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
for (const m of mats) {
if (!m || !m.emissive) continue;
if (id === zone) {
m.emissive.setHex(0x2f7fe0);
m.emissiveIntensity = 0.45;
} else {
m.emissive.setHex(0x000000);
m.emissiveIntensity = 0;
}
m.needsUpdate = true;
}
}
}
_selectRoom(zone) {
this._room = this._room === zone ? null : zone;
if (this._roomNameEl) {
this._roomNameEl.textContent = this._room
? (ROOM_NAMES[this._room] || this._room.replace("zone_", ""))
: "обзор";
}
this._highlightZone(this._room);
document.dispatchEvent(new CustomEvent("house3d-room", { detail: { room: this._room } }));
}
async _toggle() { async _toggle() {
const _c0 = performance.now(); const _c0 = performance.now();
this._pending = true; this._pending = true;
+290
View File
@@ -0,0 +1,290 @@
{
"terrasa": [
[
180,
173
],
[
283,
173
],
[
283,
524
],
[
180,
524
]
],
"kitchen": [
[
291,
173
],
[
425,
173
],
[
425,
294
],
[
441,
294
],
[
441,
348
],
[
441,
524
],
[
291,
524
]
],
"postirochnaia": [
[
425,
114
],
[
499,
114
],
[
499,
229
],
[
425,
229
]
],
"sanuzel": [
[
499,
173
],
[
499,
229
],
[
425,
229
],
[
425,
294
],
[
479,
294
],
[
558,
294
],
[
558,
173
]
],
"tualet": [
[
558,
229
],
[
609,
229
],
[
609,
294
],
[
558,
294
]
],
"garderob": [
[
558,
173
],
[
558,
229
],
[
656,
229
],
[
656,
173
]
],
"kladovaia": [
[
609,
229
],
[
656,
229
],
[
656,
294
],
[
609,
294
]
],
"koridor": [
[
441,
294
],
[
441,
348
],
[
684,
348
],
[
684,
294
]
],
"prihozhaya": [
[
441,
348
],
[
516,
348
],
[
516,
442
],
[
441,
442
]
],
"kabinet": [
[
656,
173
],
[
656,
294
],
[
684,
294
],
[
684,
348
],
[
787,
348
],
[
787,
173
],
[
656,
173
]
],
"danina_komnata": [
[
516,
348
],
[
633,
348
],
[
633,
524
],
[
516,
524
]
],
"spalnia": [
[
633,
348
],
[
787,
348
],
[
787,
524
],
[
633,
524
]
],
"kryltso": [
[
441,
524
],
[
441,
593
],
[
516,
593
],
[
516,
524
]
],
"tambur": [
[
441,
442
],
[
516,
442
],
[
516,
524
],
[
441,
524
]
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 355 KiB

+32 -17
View File
@@ -2,23 +2,39 @@
const PLAN_W = 916, PLAN_H = 768; const PLAN_W = 916, PLAN_H = 768;
/* стартовые контуры (в пикселях подложки), сняты ориентировочно */ /* стартовые контуры (в пикселях подложки), сняты ориентировочно */
const START = { const START = {
terrasa: [[180,173],[283,173],[283,529],[180,529]], terrasa: [[180,173],[283,173],[283,524],[180,524]],
kitchen: [[291,172],[424,172],[424,296],[439,296],[439,349],[439,522],[291,524]], kitchen: [[291,173],[425,173],[425,294],[441,294],[441,348],[441,524],[291,524]],
postirochnaia: [[426,113],[497,115],[497,221],[426,221]], postirochnaia: [[425,114],[499,114],[499,229],[425,229]],
sanuzel: [[501,170],[501,223],[426,225],[426,294],[479,296],[557,294],[557,172]], sanuzel: [[499,173],[499,229],[425,229],[425,294],[479,294],[558,294],[558,173]],
tualet: [[557,236],[608,236],[608,294],[557,292]], tualet: [[558,229],[609,229],[609,294],[558,294]],
garderob: [[559,171],[559,231],[654,233],[654,173]], garderob: [[558,173],[558,229],[656,229],[656,173]],
kladovaia: [[610,235],[654,235],[654,293],[608,293]], kladovaia: [[609,229],[656,229],[656,294],[609,294]],
koridor: [[439,294],[439,349],[685,347],[683,296]], koridor: [[441,294],[441,348],[684,348],[684,294]],
prihozhaya: [[439,349],[515,349],[512,442],[441,440]], prihozhaya: [[441,348],[516,348],[516,442],[441,442]],
kabinet: [[657,176],[654,294],[683,294],[685,345],[787,347],[787,176],[657,174]], tambur: [[441,442],[516,442],[516,524],[441,524]],
danina_komnata: [[515,351],[632,351],[630,520],[517,522]], kabinet: [[656,173],[656,294],[684,294],[684,348],[787,348],[787,173],[656,173]],
spalnia: [[637,349],[787,345],[787,524],[637,524]], danina_komnata: [[516,348],[633,348],[633,524],[516,524]],
kryltso: [[439,529],[441,593],[521,593],[521,529]], spalnia: [[633,348],[787,348],[787,524],[633,524]],
tambur: [[444,445],[512,442],[515,524],[441,524]], kryltso: [[441,524],[441,593],[516,593],[516,524]],
}; };
const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"]; const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"];
const SENSOR_HINT = /temperature|humidity|co2|illuminance/; const SENSOR_HINT = /temperature|humidity|co2|illuminance/;
const ROOM_TITLES = {
"terrasa": "Терраса",
"kitchen": "Кухня-гостиная",
"postirochnaia": "Тех.пом.",
"sanuzel": "СУ",
"tualet": "СУ 2",
"garderob": "Гардеробная",
"kladovaia": "Кладовая",
"koridor": "Холл",
"prihozhaya": "Прихожая",
"tambur": "Тамбур",
"kabinet": "Кабинет",
"danina_komnata": "Данина комната",
"spalnia": "Спальня",
"kryltso": "Крыльцо"
};
const STORE = "house3d_room_px"; const STORE = "house3d_room_px";
class RoomsCard extends HTMLElement { class RoomsCard extends HTMLElement {
@@ -125,9 +141,8 @@ class RoomsCard extends HTMLElement {
const sel = r.id === areaId; const sel = r.id === areaId;
shapes += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}" shapes += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}"
points="${poly.map(([x, y]) => `${x},${y}`).join(" ")}"><title>${r.name}</title></polygon>`; points="${poly.map(([x, y]) => `${x},${y}`).join(" ")}"><title>${r.name}</title></polygon>`;
const cx = poly.reduce((s, p) => s + p[0], 0) / poly.length; // на подложке уже есть подписи — свои не рисуем, только подсказку
const cy = poly.reduce((s, p) => s + p[1], 0) / poly.length;
labels += `<text class="lbl" x="${cx}" y="${cy}" text-anchor="middle">${r.name}</text>`;
} }
if (this._tmp.length) { if (this._tmp.length) {
tmp = `<polyline class="tmp" points="${this._tmp.map(([x, y]) => `${x},${y}`).join(" ")}"/>`; tmp = `<polyline class="tmp" points="${this._tmp.map(([x, y]) => `${x},${y}`).join(" ")}"/>`;
+301 -294
View File
@@ -1,294 +1,301 @@
/* Панель для настенного планшета (Galaxy Tab S5e, 2560×1600, горизонтально). /* Панель для настенного планшета (Galaxy Tab S5e, 2560×1600, горизонтально).
* Принципы: без прокрутки, тач-цели ≥ 64px, цвет только для состояния, * Принципы: без прокрутки, тач-цели ≥ 64px, цвет только для состояния,
* слева — план дома как селектор комнаты, справа — крупные органы управления. * слева — план дома как селектор комнаты, справа — крупные органы управления.
*/ */
const ZONES = { const ZONES = {
terrasa: [[180,173],[283,173],[283,529],[180,529]], terrasa: [[180,173],[283,173],[283,524],[180,524]],
kitchen: [[291,172],[424,172],[424,296],[439,296],[439,349],[439,522],[291,524]], kitchen: [[291,173],[425,173],[425,294],[441,294],[441,348],[441,524],[291,524]],
postirochnaia: [[426,113],[497,115],[497,221],[426,221]], postirochnaia: [[425,114],[499,114],[499,229],[425,229]],
sanuzel: [[501,170],[501,223],[426,225],[426,294],[479,296],[557,294],[557,172]], sanuzel: [[499,173],[499,229],[425,229],[425,294],[479,294],[558,294],[558,173]],
tualet: [[557,236],[608,236],[608,294],[557,292]], tualet: [[558,229],[609,229],[609,294],[558,294]],
garderob: [[559,171],[559,231],[654,233],[654,173]], garderob: [[558,173],[558,229],[656,229],[656,173]],
kladovaia: [[610,235],[654,235],[654,293],[608,293]], kladovaia: [[609,229],[656,229],[656,294],[609,294]],
koridor: [[439,294],[439,349],[685,347],[683,296]], koridor: [[441,294],[441,348],[684,348],[684,294]],
prihozhaya: [[439,349],[515,349],[512,442],[441,440]], prihozhaya: [[441,348],[516,348],[516,442],[441,442]],
kabinet: [[657,176],[654,294],[683,294],[685,345],[787,347],[787,176],[657,174]], tambur: [[441,442],[516,442],[516,524],[441,524]],
danina_komnata: [[515,351],[632,351],[630,520],[517,522]], kabinet: [[656,173],[656,294],[684,294],[684,348],[787,348],[787,173],[656,173]],
spalnia: [[637,349],[787,345],[787,524],[637,524]], danina_komnata: [[516,348],[633,348],[633,524],[516,524]],
kryltso: [[439,529],[441,593],[521,593],[521,529]], spalnia: [[633,348],[787,348],[787,524],[633,524]],
tambur: [[444,445],[512,442],[515,524],[441,524]], kryltso: [[441,524],[441,593],[516,593],[516,524]],
}; };
const ROOM_NAMES = { const ROOM_NAMES = {
kitchen: "Кухня-гостиная", koridor: "Холл", spalnia: "Спальня", terrasa: "Терраса",
danina_komnata: "Комната Дани", kabinet: "Кабинет", sanuzel: "Санузел", kitchen: "Кухня-гостиная",
tualet: "Туалет", garderob: "Гардеробная", kladovaia: "Постирочная", postirochnaia: "Тех.пом.",
tambur: "Тамбур", prihozhaya: "Прихожая", postirochnaia: "Серверная", sanuzel: "СУ",
terrasa: "Терраса", kryltso: "Крыльцо", tualet: "СУ 2",
}; garderob: "Гардеробная",
const ROOM_ORDER = ["kitchen", "koridor", "spalnia", "danina_komnata", "kabinet", kladovaia: "Кладовая",
"sanuzel", "tualet", "garderob", "kladovaia", "tambur", "prihozhaya", koridor: "Холл",
"postirochnaia", "terrasa", "kryltso"]; prihozhaya: "Прихожая",
tambur: "Тамбур",
class TabletCard extends HTMLElement { kabinet: "Кабинет",
constructor() { danina_komnata: "Данина комната",
super(); spalnia: "Спальня",
this._areas = []; kryltso: "Крыльцо",
this._ent2area = {}; };
this._selected = "kitchen"; const ROOM_ORDER = ["terrasa", "kitchen", "postirochnaia", "sanuzel", "tualet", "garderob", "kladovaia", "koridor", "prihozhaya", "tambur", "kabinet", "danina_komnata", "spalnia", "kryltso"];
this._loaded = false;
this._busy = false; class TabletCard extends HTMLElement {
this.attachShadow({ mode: "open" }); constructor() {
} super();
this._areas = [];
setConfig(config) { this._config = config || {}; } this._ent2area = {};
this._selected = "kitchen";
set hass(hass) { this._loaded = false;
this._hass = hass; this._busy = false;
if (!this._loaded) { this._loaded = true; this._load(); } this.attachShadow({ mode: "open" });
else if (!this._busy) this._render(); }
}
setConfig(config) { this._config = config || {}; }
async _load() {
try { set hass(hass) {
const [areas, devices, entities] = await Promise.all([ this._hass = hass;
this._hass.callWS({ type: "config/area_registry/list" }), if (!this._loaded) { this._loaded = true; this._load(); }
this._hass.callWS({ type: "config/device_registry/list" }), else if (!this._busy) this._render();
this._hass.callWS({ type: "config/entity_registry/list" }), }
]);
this._areas = areas; async _load() {
const devArea = {}; try {
for (const d of devices) if (d.area_id) devArea[d.id] = d.area_id; const [areas, devices, entities] = await Promise.all([
this._ent2area = {}; this._hass.callWS({ type: "config/area_registry/list" }),
for (const e of entities) { this._hass.callWS({ type: "config/device_registry/list" }),
const a = e.area_id || devArea[e.device_id]; this._hass.callWS({ type: "config/entity_registry/list" }),
if (a) this._ent2area[e.entity_id] = a; ]);
} this._areas = areas;
} catch (e) { this._err = String(e); } const devArea = {};
this._render(); for (const d of devices) if (d.area_id) devArea[d.id] = d.area_id;
} this._ent2area = {};
for (const e of entities) {
_of(area) { const a = e.area_id || devArea[e.device_id];
return Object.entries(this._ent2area).filter(([, a]) => a === area) if (a) this._ent2area[e.entity_id] = a;
.map(([e]) => e).filter((e) => this._hass.states[e]); }
} } catch (e) { this._err = String(e); }
this._render();
_on(area) { }
return this._of(area).filter((e) => {
const s = this._hass.states[e]; _of(area) {
return /^light\.|^switch\./.test(e) && s.state === "on"; return Object.entries(this._ent2area).filter(([, a]) => a === area)
}).length; .map(([e]) => e).filter((e) => this._hass.states[e]);
} }
_call(domain, service, data) { _on(area) {
this._busy = true; return this._of(area).filter((e) => {
this._hass.callService(domain, service, data).finally(() => { const s = this._hass.states[e];
this._busy = false; return /^light\.|^switch\./.test(e) && s.state === "on";
this._render(); }).length;
}); }
}
_call(domain, service, data) {
_plan() { this._busy = true;
const px = ([x, y]) => `${x},${y}`; this._hass.callService(domain, service, data).finally(() => {
return `<svg class="plan" viewBox="150 90 680 530" preserveAspectRatio="xMidYMid meet"> this._busy = false;
${ROOM_ORDER.map((id) => { this._render();
const p = ZONES[id]; });
if (!p) return ""; }
const on = this._on(id);
const cls = "zone" + (id === this._selected ? " sel" : "") + (on ? " act" : ""); _plan() {
return `<polygon class="${cls}" data-r="${id}" points="${p.map(px).join(" ")}"></polygon>`; const px = ([x, y]) => `${x},${y}`;
}).join("")} return `<svg class="plan" viewBox="150 90 680 530" preserveAspectRatio="xMidYMid meet">
${ROOM_ORDER.map((id) => { ${ROOM_ORDER.map((id) => {
const p = ZONES[id]; const p = ZONES[id];
if (!p) return ""; if (!p) return "";
const cx = p.reduce((s, q) => s + q[0], 0) / p.length; const on = this._on(id);
const cy = p.reduce((s, q) => s + q[1], 0) / p.length; const cls = "zone" + (id === this._selected ? " sel" : "") + (on ? " act" : "");
return `<text x="${cx}" y="${cy}" text-anchor="middle">${ROOM_NAMES[id].split(" ")[0]}</text>`; return `<polygon class="${cls}" data-r="${id}" points="${p.map(px).join(" ")}"></polygon>`;
}).join("")} }).join("")}
</svg>`; ${ROOM_ORDER.map((id) => {
} const p = ZONES[id];
if (!p) return "";
_tiles(area) { const cx = p.reduce((s, q) => s + q[0], 0) / p.length;
const ens = this._of(area); const cy = p.reduce((s, q) => s + q[1], 0) / p.length;
const groups = {}; return `<text x="${cx}" y="${cy}" text-anchor="middle">${ROOM_NAMES[id].split(" ")[0]}</text>`;
for (const e of ens) (groups[e.split(".")[0]] ||= []).push(e); }).join("")}
const out = []; </svg>`;
const st = (e) => this._hass.states[e]; }
for (const e of groups.light || []) { _tiles(area) {
const s = st(e); const ens = this._of(area);
const on = s.state === "on"; const groups = {};
const br = s.attributes.brightness ? Math.round(s.attributes.brightness / 255 * 100) : 100; for (const e of ens) (groups[e.split(".")[0]] ||= []).push(e);
out.push(`<div class="tile light ${on ? "on" : ""}"> const out = [];
<div class="tt">${s.attributes.friendly_name || e}</div> const st = (e) => this._hass.states[e];
<button class="big" data-toggle="${e}">${on ? "ВКЛ" : "ВЫКЛ"}</button>
<input class="br" type="range" min="1" max="100" value="${br}" data-br="${e}"> for (const e of groups.light || []) {
</div>`); const s = st(e);
} const on = s.state === "on";
for (const e of groups.switch || []) { const br = s.attributes.brightness ? Math.round(s.attributes.brightness / 255 * 100) : 100;
const s = st(e); out.push(`<div class="tile light ${on ? "on" : ""}">
const on = s.state === "on"; <div class="tt">${s.attributes.friendly_name || e}</div>
out.push(`<div class="tile ${on ? "on" : ""}"> <button class="big" data-toggle="${e}">${on ? "ВКЛ" : "ВЫКЛ"}</button>
<div class="tt">${s.attributes.friendly_name || e}</div> <input class="br" type="range" min="1" max="100" value="${br}" data-br="${e}">
<button class="big" data-toggle="${e}">${on ? "ВКЛ" : "ВЫКЛ"}</button> </div>`);
</div>`); }
} for (const e of groups.switch || []) {
for (const e of groups.climate || []) { const s = st(e);
const s = st(e); const on = s.state === "on";
const cur = s.attributes.current_temperature; out.push(`<div class="tile ${on ? "on" : ""}">
const tgt = s.attributes.temperature; <div class="tt">${s.attributes.friendly_name || e}</div>
out.push(`<div class="tile"> <button class="big" data-toggle="${e}">${on ? "ВКЛ" : "ВЫКЛ"}</button>
<div class="tt">${s.attributes.friendly_name || e}</div> </div>`);
<div class="val">${cur !== undefined ? cur + "°" : "—"}</div> }
<div class="row2"> for (const e of groups.climate || []) {
<button data-clim="${e}" data-d="-0.5">−</button> const s = st(e);
<span class="tgt">${tgt !== undefined ? tgt + "°" : ""}</span> const cur = s.attributes.current_temperature;
<button data-clim="${e}" data-d="0.5">+</button> const tgt = s.attributes.temperature;
</div> out.push(`<div class="tile">
</div>`); <div class="tt">${s.attributes.friendly_name || e}</div>
} <div class="val">${cur !== undefined ? cur + "°" : "—"}</div>
for (const e of groups.cover || []) { <div class="row2">
const s = st(e); <button data-clim="${e}" data-d="-0.5">−</button>
out.push(`<div class="tile"> <span class="tgt">${tgt !== undefined ? tgt + "°" : ""}</span>
<div class="tt">${s.attributes.friendly_name || e}</div> <button data-clim="${e}" data-d="0.5">+</button>
<div class="row3"> </div>
<button data-cover="${e}" data-a="open_cover">↑</button> </div>`);
<button data-cover="${e}" data-a="stop_cover">■</button> }
<button data-cover="${e}" data-a="close_cover">↓</button> for (const e of groups.cover || []) {
</div> const s = st(e);
</div>`); out.push(`<div class="tile">
} <div class="tt">${s.attributes.friendly_name || e}</div>
for (const e of groups.media_player || []) { <div class="row3">
const s = st(e); <button data-cover="${e}" data-a="open_cover">↑</button>
out.push(`<div class="tile"> <button data-cover="${e}" data-a="stop_cover">■</button>
<div class="tt">${s.attributes.friendly_name || e}</div> <button data-cover="${e}" data-a="close_cover">↓</button>
<div class="val sm">${s.state}</div> </div>
<button class="big" data-media="${e}">▶ / ⏸</button> </div>`);
</div>`); }
} for (const e of groups.media_player || []) {
const sensors = (groups.sensor || []).filter((e) => /temperature|humidity/.test(e)).slice(0, 4); const s = st(e);
for (const e of sensors) { out.push(`<div class="tile">
const s = st(e); <div class="tt">${s.attributes.friendly_name || e}</div>
out.push(`<div class="tile sens"> <div class="val sm">${s.state}</div>
<div class="tt">${(s.attributes.friendly_name || e).slice(0, 22)}</div> <button class="big" data-media="${e}">▶ / ⏸</button>
<div class="val">${s.state}${s.attributes.unit_of_measurement || ""}</div> </div>`);
</div>`); }
} const sensors = (groups.sensor || []).filter((e) => /temperature|humidity/.test(e)).slice(0, 4);
if (!out.length) out.push(`<div class="tile empty">В этой комнате пока нет устройств</div>`); for (const e of sensors) {
return out.join(""); const s = st(e);
} out.push(`<div class="tile sens">
<div class="tt">${(s.attributes.friendly_name || e).slice(0, 22)}</div>
_render() { <div class="val">${s.state}${s.attributes.unit_of_measurement || ""}</div>
if (!this._hass) return; </div>`);
const area = this._selected; }
const ens = this._of(area); if (!out.length) out.push(`<div class="tile empty">В этой комнате пока нет устройств</div>`);
const lights = (ens.filter((e) => e.startsWith("light.")) || []); return out.join("");
const onLights = lights.filter((e) => this._hass.states[e].state === "on").length; }
this.shadowRoot.innerHTML = `<style> _render() {
:host { display:block; height:100%; } if (!this._hass) return;
.app { height:100%; box-sizing:border-box; display:grid; const area = this._selected;
grid-template-rows:auto 1fr; gap:14px; padding:14px; const ens = this._of(area);
background:#0b1016; color:#e8eef5; const lights = (ens.filter((e) => e.startsWith("light.")) || []);
font-family:'Segoe UI',system-ui,sans-serif; } const onLights = lights.filter((e) => this._hass.states[e].state === "on").length;
.top { display:flex; align-items:center; gap:14px; }
.clock { font-size:30px; font-weight:700; letter-spacing:.02em; } this.shadowRoot.innerHTML = `<style>
.date { font-size:14px; color:#7f93a8; } :host { display:block; height:100%; }
.chips { display:flex; gap:10px; margin-left:auto; } .app { height:100%; box-sizing:border-box; display:grid;
.chip { padding:8px 14px; border-radius:12px; background:#141c25; border:1px solid #22303d; grid-template-rows:auto 1fr; gap:14px; padding:14px;
font-size:14px; color:#9fb6c9; } background:#0b1016; color:#e8eef5;
.chip.on { border-color:#3d8bff; color:#cfe4ff; background:#12233a; } font-family:'Segoe UI',system-ui,sans-serif; }
.main { display:grid; grid-template-columns: 1.25fr 1fr; gap:14px; min-height:0; } .top { display:flex; align-items:center; gap:14px; }
.plan-wrap { background:#0f151c; border:1px solid #1e2a36; border-radius:18px; padding:8px; .clock { font-size:30px; font-weight:700; letter-spacing:.02em; }
display:flex; align-items:center; justify-content:center; min-height:0; } .date { font-size:14px; color:#7f93a8; }
.plan { width:100%; height:100%; } .chips { display:flex; gap:10px; margin-left:auto; }
.zone { fill:#1a2431; stroke:#2c3d4e; stroke-width:3; cursor:pointer; transition:.15s; } .chip { padding:8px 14px; border-radius:12px; background:#141c25; border:1px solid #22303d;
.zone.act { fill:#1e3448; } font-size:14px; color:#9fb6c9; }
.zone:hover { stroke:#3d8bff; } .chip.on { border-color:#3d8bff; color:#cfe4ff; background:#12233a; }
.zone.sel { fill:#25466b; stroke:#3d8bff; stroke-width:5; } .main { display:grid; grid-template-columns: 1.25fr 1fr; gap:14px; min-height:0; }
text { font-size:15px; fill:#8fb0c8; pointer-events:none; } .plan-wrap { background:#0f151c; border:1px solid #1e2a36; border-radius:18px; padding:8px;
.rooms { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; } display:flex; align-items:center; justify-content:center; min-height:0; }
.rbtn { padding:10px 14px; border-radius:12px; background:#141c25; border:1px solid #22303d; .plan { width:100%; height:100%; }
color:#a9c0d4; font-size:15px; cursor:pointer; min-height:44px; } .zone { fill:#1a2431; stroke:#2c3d4e; stroke-width:3; cursor:pointer; transition:.15s; }
.rbtn.sel { border-color:#3d8bff; color:#dceaff; background:#12233a; } .zone.act { fill:#1e3448; }
.rbtn.on { box-shadow: inset 0 -3px 0 #3d8bff; } .zone:hover { stroke:#3d8bff; }
.panel { background:#0f151c; border:1px solid #1e2a36; border-radius:18px; padding:14px; .zone.sel { fill:#25466b; stroke:#3d8bff; stroke-width:5; }
display:flex; flex-direction:column; min-height:0; } text { font-size:15px; fill:#8fb0c8; pointer-events:none; }
.phead { display:flex; align-items:baseline; gap:10px; margin-bottom:10px; } .rooms { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
.pname { font-size:24px; font-weight:700; } .rbtn { padding:10px 14px; border-radius:12px; background:#141c25; border:1px solid #22303d;
.pmeta { color:#7f93a8; font-size:14px; } color:#a9c0d4; font-size:15px; cursor:pointer; min-height:44px; }
.tiles { display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:12px; .rbtn.sel { border-color:#3d8bff; color:#dceaff; background:#12233a; }
overflow:auto; padding-right:4px; } .rbtn.on { box-shadow: inset 0 -3px 0 #3d8bff; }
.tile { background:#131b24; border:1px solid #22303d; border-radius:16px; padding:12px; .panel { background:#0f151c; border:1px solid #1e2a36; border-radius:18px; padding:14px;
display:flex; flex-direction:column; gap:8px; min-height:130px; } display:flex; flex-direction:column; min-height:0; }
.tile.on { border-color:#3d8bff; background:#12233a; } .phead { display:flex; align-items:baseline; gap:10px; margin-bottom:10px; }
.tt { font-size:14px; color:#9fb6c9; line-height:1.25; } .pname { font-size:24px; font-weight:700; }
.val { font-size:26px; font-weight:700; } .pmeta { color:#7f93a8; font-size:14px; }
.val.sm { font-size:16px; color:#9fb6c9; font-weight:500; } .tiles { display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:12px;
.big { min-height:56px; border-radius:12px; border:1px solid #2a3b4c; background:#0e1620; overflow:auto; padding-right:4px; }
color:#cfe4ff; font-size:16px; font-weight:600; cursor:pointer; } .tile { background:#131b24; border:1px solid #22303d; border-radius:16px; padding:12px;
.tile.on .big { background:#1d4d86; border-color:#4a9bff; } display:flex; flex-direction:column; gap:8px; min-height:130px; }
button { touch-action:manipulation; } .tile.on { border-color:#3d8bff; background:#12233a; }
.row2, .row3 { display:flex; gap:8px; align-items:center; } .tt { font-size:14px; color:#9fb6c9; line-height:1.25; }
.row2 button, .row3 button { flex:1; min-height:48px; border-radius:12px; border:1px solid #2a3b4c; .val { font-size:26px; font-weight:700; }
background:#0e1620; color:#cfe4ff; font-size:20px; cursor:pointer; } .val.sm { font-size:16px; color:#9fb6c9; font-weight:500; }
.tgt { font-size:18px; color:#9fb6c9; min-width:52px; text-align:center; } .big { min-height:56px; border-radius:12px; border:1px solid #2a3b4c; background:#0e1620;
.br { width:100%; accent-color:#3d8bff; height:34px; } color:#cfe4ff; font-size:16px; font-weight:600; cursor:pointer; }
.tile.sens .val { font-size:22px; } .tile.on .big { background:#1d4d86; border-color:#4a9bff; }
.empty { color:#7f93a8; } button { touch-action:manipulation; }
</style> .row2, .row3 { display:flex; gap:8px; align-items:center; }
<div class="app"> .row2 button, .row3 button { flex:1; min-height:48px; border-radius:12px; border:1px solid #2a3b4c;
<div class="top"> background:#0e1620; color:#cfe4ff; font-size:20px; cursor:pointer; }
<div><div class="clock" id="clk">--:--</div><div class="date" id="dt"></div></div> .tgt { font-size:18px; color:#9fb6c9; min-width:52px; text-align:center; }
<div class="chips"> .br { width:100%; accent-color:#3d8bff; height:34px; }
<div class="chip ${onLights ? "on" : ""}">свет: ${onLights}</div> .tile.sens .val { font-size:22px; }
<div class="chip">комнат: ${ROOM_ORDER.length}</div> .empty { color:#7f93a8; }
<div class="chip">устройств: ${ens.length}</div> </style>
</div> <div class="app">
</div> <div class="top">
<div class="main"> <div><div class="clock" id="clk">--:--</div><div class="date" id="dt"></div></div>
<div class="plan-wrap">${this._plan()}</div> <div class="chips">
<div class="panel"> <div class="chip ${onLights ? "on" : ""}">свет: ${onLights}</div>
<div class="phead"><span class="pname">${ROOM_NAMES[area] || area}</span></div> <div class="chip">комнат: ${ROOM_ORDER.length}</div>
<div class="tiles">${this._tiles(area)}</div> <div class="chip">устройств: ${ens.length}</div>
</div> </div>
</div> </div>
</div>`; <div class="main">
<div class="plan-wrap">${this._plan()}</div>
const clk = this.shadowRoot.getElementById("clk"); <div class="panel">
const dt = this.shadowRoot.getElementById("dt"); <div class="phead"><span class="pname">${ROOM_NAMES[area] || area}</span></div>
const now = new Date(); <div class="tiles">${this._tiles(area)}</div>
if (clk) clk.textContent = now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" }); </div>
if (dt) dt.textContent = now.toLocaleDateString("ru-RU", { weekday: "long", day: "numeric", month: "long" }); </div>
</div>`;
this.shadowRoot.querySelectorAll(".zone").forEach((el) =>
el.addEventListener("click", () => { this._selected = el.dataset.r; this._render(); })); const clk = this.shadowRoot.querySelector("#clk");
const dt = this.shadowRoot.querySelector("#dt");
this.shadowRoot.querySelectorAll("[data-toggle]").forEach((b) => const now = new Date();
b.addEventListener("click", () => { if (clk) clk.textContent = now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
const e = b.dataset.toggle; if (dt) dt.textContent = now.toLocaleDateString("ru-RU", { weekday: "long", day: "numeric", month: "long" });
this._call(e.split(".")[0], "toggle", { entity_id: e });
})); this.shadowRoot.querySelectorAll(".zone").forEach((el) =>
this.shadowRoot.querySelectorAll("[data-br]").forEach((r) => el.addEventListener("click", () => { this._selected = el.dataset.r; this._render(); }));
r.addEventListener("change", (ev) => {
this._call("light", "turn_on", { this.shadowRoot.querySelectorAll("[data-toggle]").forEach((b) =>
entity_id: ev.target.dataset.br, brightness_pct: parseInt(ev.target.value, 10), b.addEventListener("click", () => {
}); const e = b.dataset.toggle;
})); this._call(e.split(".")[0], "toggle", { entity_id: e });
this.shadowRoot.querySelectorAll("[data-clim]").forEach((b) => }));
b.addEventListener("click", () => { this.shadowRoot.querySelectorAll("[data-br]").forEach((r) =>
const e = b.dataset.clim; r.addEventListener("change", (ev) => {
const cur = this._hass.states[e].attributes.temperature || 20; this._call("light", "turn_on", {
this._call("climate", "set_temperature", { entity_id: ev.target.dataset.br, brightness_pct: parseInt(ev.target.value, 10),
entity_id: e, temperature: Math.round((cur + parseFloat(b.dataset.d)) * 2) / 2, });
}); }));
})); this.shadowRoot.querySelectorAll("[data-clim]").forEach((b) =>
this.shadowRoot.querySelectorAll("[data-cover]").forEach((b) => b.addEventListener("click", () => {
b.addEventListener("click", () => this._call("cover", b.dataset.a, { entity_id: b.dataset.cover }))); const e = b.dataset.clim;
this.shadowRoot.querySelectorAll("[data-media]").forEach((b) => const cur = this._hass.states[e].attributes.temperature || 20;
b.addEventListener("click", () => this._call("media_player", "media_play_pause", { entity_id: b.dataset.media }))); this._call("climate", "set_temperature", {
} entity_id: e, temperature: Math.round((cur + parseFloat(b.dataset.d)) * 2) / 2,
});
getCardSize() { return 20; } }));
} this.shadowRoot.querySelectorAll("[data-cover]").forEach((b) =>
b.addEventListener("click", () => this._call("cover", b.dataset.a, { entity_id: b.dataset.cover })));
customElements.define("tablet-card", TabletCard); this.shadowRoot.querySelectorAll("[data-media]").forEach((b) =>
b.addEventListener("click", () => this._call("media_player", "media_play_pause", { entity_id: b.dataset.media })));
}
getCardSize() { return 20; }
}
customElements.define("tablet-card", TabletCard);