[HOME] Панель: план рисуется по стенам из размеров чертежа (14 зон, без фото)
lint / hygiene (push) Failing after 24s

This commit is contained in:
root committed 2026-11-01 22:40:00 +03:00
1 parent 5709f5b837
commit cbcd218c8f
2 files changed
+37 -34

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

+37 -34
View File
@@ -1,39 +1,38 @@
/* Покомнатная панель: план-подложка (img) + слой зон (SVG) по контурам комнат. */ /* Покомнатная панель: план рисуется по стенам (SVG), зоны = комнаты. */
const ROOMS = [ const ROOMS = [
{ id: "terrasa", name: "Терраса", icon: "mdi:deck", { id: "terrasa", name: "Терраса", icon: "mdi:deck",
poly: [[0.00, 0.00], [2.45, 0.00], [2.45, 8.35], [0.00, 8.35]] }, poly: [[0.00, 0.00], [2.45, 0.00], [2.45, 8.60], [0.00, 8.60]] },
{ id: "kitchen", name: "Кухня-гостиная", icon: "mdi:silverware-fork-knife", { id: "kitchen", name: "Кухня-гостиная", icon: "mdi:silverware-fork-knife",
poly: [[2.45, 0.00], [6.16, 0.00], [6.16, 8.35], [2.45, 8.35]] }, poly: [[2.45, 0.00], [6.21, 0.00], [6.21, 8.60], [2.45, 8.60]] },
{ id: "postirochnaia", name: "Тех.пом.", icon: "mdi:server", { id: "postirochnaia", name: "Тех.пом.", icon: "mdi:server",
poly: [[5.71, -1.50], [7.62, -1.50], [7.62, 0.00], [5.71, 0.00]] }, poly: [[5.71, -1.50], [7.62, -1.50], [7.62, 0.00], [5.71, 0.00]] },
{ id: "sanuzel", name: "Санузел", icon: "mdi:shower", { id: "sanuzel", name: "Санузел", icon: "mdi:shower",
poly: [[5.83, 0.30], [7.74, 0.30], [7.74, 1.55], [7.30, 1.55], poly: [[5.83, 0.00], [7.95, 0.00], [7.95, 2.97], [5.83, 2.97]] },
[7.30, 3.07], [5.83, 3.07]] },
{ id: "tualet", name: "Туалет", icon: "mdi:toilet", { id: "tualet", name: "Туалет", icon: "mdi:toilet",
poly: [[7.74, 1.90], [8.62, 1.90], [8.62, 3.55], [7.74, 3.55]] }, poly: [[7.95, 1.55], [9.00, 1.55], [9.00, 2.97], [7.95, 2.97]] },
{ id: "garderob", name: "Гардероб", icon: "mdi:hanger", { id: "garderob", name: "Гардероб", icon: "mdi:hanger",
poly: [[9.05, 0.05], [10.95, 0.05], [10.95, 1.50], [9.05, 1.50]] }, poly: [[9.00, 0.00], [10.81, 0.00], [10.81, 1.55], [9.00, 1.55]] },
{ id: "kladovaia", name: "Кладовая", icon: "mdi:package-variant", { id: "kladovaia", name: "Кладовая", icon: "mdi:package-variant",
poly: [[9.29, 1.50], [10.95, 1.50], [10.95, 2.83], [9.29, 2.83]] }, poly: [[9.00, 1.55], [10.81, 1.55], [10.81, 2.40], [9.00, 2.40]] },
{ id: "koridor", name: "Холл", icon: "mdi:door-open", { id: "koridor", name: "Холл", icon: "mdi:door-open",
poly: [[7.74, 3.07], [9.05, 3.07], [9.05, 2.83], [11.07, 2.83], poly: [[6.21, 2.97], [10.81, 2.97], [10.81, 5.29], [6.21, 5.29]] },
[11.07, 5.48], [7.74, 5.48]] },
{ id: "prihozhaya", name: "Прихожая", icon: "mdi:door", { id: "prihozhaya", name: "Прихожая", icon: "mdi:door",
poly: [[5.95, 5.48], [7.74, 5.48], [7.74, 7.41], [5.95, 7.41]] }, poly: [[6.21, 5.29], [7.74, 5.29], [7.74, 7.35], [6.21, 7.35]] },
{ id: "tambur", name: "Тамбур", icon: "mdi:door", { id: "tambur", name: "Тамбур", icon: "mdi:door",
poly: [[5.95, 7.41], [7.74, 7.41], [7.74, 8.38], [5.95, 8.38]] }, poly: [[6.21, 7.35], [7.74, 7.35], [7.74, 8.60], [6.21, 8.60]] },
{ id: "kabinet", name: "Комната 11,45", icon: "mdi:desk", { id: "kabinet", name: "Комната 11,45", icon: "mdi:desk",
poly: [[11.07, 0.05], [14.55, 0.05], [14.55, 3.31], [11.07, 3.31]] }, poly: [[11.33, 0.00], [14.52, 0.00], [14.52, 3.41], [11.33, 3.41]] },
{ id: "danina_komnata", name: "Комната 12,04", icon: "mdi:teddy-bear", { id: "danina_komnata", name: "Комната 12,04", icon: "mdi:teddy-bear",
poly: [[7.74, 5.48], [11.07, 5.48], [11.07, 8.38], [7.74, 8.38]] }, poly: [[7.74, 5.29], [11.33, 5.29], [11.33, 8.60], [7.74, 8.60]] },
{ id: "spalnia", name: "Комната 14,34", icon: "mdi:bed", { id: "spalnia", name: "Комната 14,34", icon: "mdi:bed",
poly: [[11.07, 3.55], [14.55, 3.55], [14.55, 8.60], [11.07, 8.60]] }, poly: [[11.33, 3.41], [14.52, 3.41], [14.52, 8.60], [11.33, 8.60]] },
{ id: "kryltso", name: "Крыльцо", icon: "mdi:stairs", { id: "kryltso", name: "Крыльцо", icon: "mdi:stairs",
poly: [[5.95, 8.38], [7.74, 8.38], [7.74, 9.70], [5.95, 9.70]] }, poly: [[6.21, 8.60], [7.74, 8.60], [7.74, 10.10], [6.21, 10.10]] },
]; ];
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 IMG_W = 916, IMG_H = 768, PX0 = 180, PY0 = 173, PX_M = 42.0, PY_M = 41.4; /* рамка плана в метрах */
const VB = [-0.4, -1.9, 15.0, 10.5];
class RoomsCard extends HTMLElement { class RoomsCard extends HTMLElement {
constructor() { constructor() {
@@ -103,17 +102,22 @@ class RoomsCard extends HTMLElement {
if (d === "light" || d === "switch") this._hass.callService(d, "toggle", { entity_id: e }); if (d === "light" || d === "switch") this._hass.callService(d, "toggle", { entity_id: e });
} }
_planHtml(areaId) { _planSvg(areaId) {
const pts = (poly) => poly.map(([x, y]) => const [vx, vy, vw, vh] = VB;
`${(x * PX_M + PX0).toFixed(1)},${(y * PY_M + PY0).toFixed(1)}`).join(" "); let shapes = "";
const shapes = ROOMS.map((r) => { let labels = "";
for (const r of ROOMS) {
const pts = r.poly.map(([x, y]) => `${x},${y}`).join(" ");
const sel = r.id === areaId; const sel = r.id === areaId;
return `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}" points="${pts(r.poly)}"><title>${r.name}</title></polygon>`; const on = this._on(r.id);
}).join(""); shapes += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}" points="${pts}"><title>${r.name}</title></polygon>`;
return `<div class="plan-wrap"> const cx = r.poly.reduce((s, p) => s + p[0], 0) / r.poly.length;
<img class="plan-img" src="/local/house3d/plan.png?v=6" alt="План дома"/> const cy = r.poly.reduce((s, p) => s + p[1], 0) / r.poly.length;
<svg class="plan-layer" viewBox="0 0 ${IMG_W} ${IMG_H}" preserveAspectRatio="none">${shapes}</svg> labels += `<text class="lbl" x="${cx}" y="${cy}" text-anchor="middle">${r.name}${on ? " · " + on : ""}</text>`;
</div>`; }
return `<svg class="plan" viewBox="${vx} ${vy} ${vw} ${vh}">
<rect x="${vx}" y="${vy}" width="${vw}" height="${vh}" fill="none"/>
${shapes}${labels}</svg>`;
} }
_render() { _render() {
@@ -161,12 +165,11 @@ class RoomsCard extends HTMLElement {
.bar button { background:rgba(30,36,44,.9); color:#cfe0f0; border:1px solid #39424e; .bar button { background:rgba(30,36,44,.9); color:#cfe0f0; border:1px solid #39424e;
border-radius:9px; padding:4px 10px; font-size:12px; cursor:pointer; } border-radius:9px; padding:4px 10px; font-size:12px; cursor:pointer; }
.bar button.on { border-color:#4aa3ff; color:#dceaff; background:rgba(74,163,255,.16); } .bar button.on { border-color:#4aa3ff; color:#dceaff; background:rgba(74,163,255,.16); }
.plan-wrap { position:relative; line-height:0; border-radius:12px; overflow:hidden; background:#f7f7f4; } .plan { display:block; width:100%; height:auto; background:#f4f3ee; border-radius:12px; }
.plan-img { display:block; width:100%; height:auto; } .zone { fill:#e9e4d8; stroke:#2b2b2b; stroke-width:0.06; cursor:pointer; transition:.12s; }
.plan-layer { position:absolute; inset:0; width:100%; height:100%; } .zone:hover { fill:#bcd6f5; stroke:#2f7fe0; }
.zone { fill:rgba(47,127,224,0); stroke:rgba(47,127,224,0); stroke-width:2; cursor:pointer; transition:.12s; } .zone.sel { fill:#9ec4f0; stroke:#1f6fd0; stroke-width:0.09; }
.zone:hover { fill:rgba(47,127,224,.18); stroke:rgba(47,127,224,.9); } .lbl { font-size:0.30px; fill:#2a2a2a; pointer-events:none; }
.zone.sel { fill:rgba(47,127,224,.30); stroke:rgba(20,90,200,1); stroke-width:3; }
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap:10px; } .grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap:10px; }
.tile { text-align:left; border:1px solid #2a2f36; border-radius:14px; .tile { text-align:left; border:1px solid #2a2f36; border-radius:14px;
background: linear-gradient(160deg, rgba(30,36,44,.95), rgba(18,22,27,.95)); background: linear-gradient(160deg, rgba(30,36,44,.95), rgba(18,22,27,.95));
@@ -193,7 +196,7 @@ class RoomsCard extends HTMLElement {
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button> <button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button> <button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
</div> </div>
${this._mode === "plan" ? this._planHtml(areaId) : `<div class="grid">${tiles}</div>`} ${this._mode === "plan" ? this._planSvg(areaId) : `<div class="grid">${tiles}</div>`}
${detail}`; ${detail}`;
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) => this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>