[HOME] Панель: план дома как подложка + зоны комнат по размерам владельца
lint / hygiene (push) Failing after 20s
lint / hygiene (push) Failing after 20s
This commit is contained in:
1 parent
92e31e6859
commit
fbe79d86ff
2 files changed
+266
-230
No files matched your search
@@ -40,3 +40,45 @@ koridor 2, spalnia 2, kabinet 1, kladovaia 1.
|
||||
1. Уточнить границы комнат по плану (стены, перегородки).
|
||||
2. Сделать 3D-модель покомнатной: отдельные меши комнат для кликов в 3D.
|
||||
3. Добавить панели: климат, медиа, свет по зонам.
|
||||
|
||||
|
||||
# Покомнатный план в панели (01.11.2026, вечер)
|
||||
|
||||
## Решение
|
||||
|
||||
Геометрию комнат вручную по фото я собирать перестал — это давало расхождения.
|
||||
Вместо этого в панель поставлен **точный цветной план владельца** как подложка
|
||||
(`/local/house3d/plan.png`), а комнаты — кликабельные зоны поверх него.
|
||||
|
||||
## Как устроено
|
||||
|
||||
* подложка — план 916×768 (из документа заказчика);
|
||||
* зоны комнат заданы в метрах: `x` от западного края террасы (0…14,55),
|
||||
`y` от северной стены блока (0…8,60); тех.пом. и крыльцо — снаружи;
|
||||
* перевод в проценты подложки: `PX0=180, PY0=173, 42 px/м`;
|
||||
* клик по зоне → панель со всеми сущностями комнаты (данные из реестров HA);
|
||||
* переключатель «План / Плитки».
|
||||
|
||||
## Привязки зон (метры)
|
||||
|
||||
| Комната | x | y |
|
||||
|---|---|---|
|
||||
| Терраса | 0…2,45 | 0…8,35 |
|
||||
| Кухня-гостиная | 2,45…6,16 | 0…8,35 |
|
||||
| Тех.пом. | 5,71…7,62 | −1,50…0 |
|
||||
| СУ 6,29 | 5,83…7,74 | 0,30…3,07 |
|
||||
| Туалет 1,43 | 8,69…9,40 | 2,71…3,55 |
|
||||
| Гардероб 2,99 | 9,05…10,95 | 0,05…1,50 |
|
||||
| Кладовая 1,30 | 9,29…10,95 | 1,50…2,83 |
|
||||
| Холл 6,83 | 9,05…11,07 | 3,07…5,48 |
|
||||
| Комната 11,45 | 11,07…14,55 | 0,05…3,31 |
|
||||
| Комната 12,04 | 7,74…11,07 | 5,48…8,38 |
|
||||
| Комната 14,34 | 11,07…14,55 | 3,55…8,60 |
|
||||
| Тамбур 2,94 | 5,95…7,74 | 7,41…8,38 |
|
||||
| Крыльцо 3,00 | 5,95…7,74 | 8,38…9,70 |
|
||||
|
||||
Проверка: наложение зон на подложку — `sources/plan/hotspots-check3.png`.
|
||||
|
||||
## Модель панели
|
||||
|
||||
`rooms-card.js` v5, ресурс `/local/house3d/rooms-card.js?v=5`.
|
||||
+224
-230
@@ -1,230 +1,224 @@
|
||||
/* Покомнатная панель: ПЛАН (кликабельная схема) + плитки зон + список устройств. */
|
||||
const AREA_M2 = {
|
||||
kitchen: 27.65, danina_komnata: 11.14, spalnia: 14.34, postirochnaia: 4.32,
|
||||
tambur: 2.96, koridor: 6.83, kabinet: 11.45, sanuzel: 6.29, tualet: 1.43,
|
||||
garderob: 2.99, kladovaia: 1.30, terrasa: 20.09, kryltso: 3.00,
|
||||
};
|
||||
/* черновые прямоугольники: [x0, y0, x1, y1] в метрах (x — длина, y — ширина) */
|
||||
const AREA_RECT = {
|
||||
kitchen: [0, 0, 3.37, 8.2],
|
||||
koridor: [3.37, 0, 4.35, 8.2],
|
||||
tambur: [4.35, 0, 5.85, 1.75],
|
||||
tualet: [4.35, 1.75, 5.15, 3.55],
|
||||
garderob: [4.35, 3.55, 5.85, 5.9],
|
||||
kladovaia: [5.85, 0, 7.1, 1.75],
|
||||
sanuzel: [5.85, 1.75, 7.95, 4.3],
|
||||
spalnia: [5.85, 4.3, 8.95, 8.2],
|
||||
danina_komnata: [8.95, 0, 12.1, 4.05],
|
||||
kabinet: [8.95, 4.05, 12.1, 8.2],
|
||||
postirochnaia: [3.21, 8.6, 5.29, 10.1],
|
||||
terrasa: [-2.45, 0, 0, 8.2],
|
||||
kryltso: [3.71, -1.5, 5.51, 0],
|
||||
};
|
||||
const AREA_ICON = {
|
||||
kitchen: "mdi:silverware-fork-knife", danina_komnata: "mdi:teddy-bear",
|
||||
spalnia: "mdi:bed", postirochnaia: "mdi:server", tambur: "mdi:door",
|
||||
koridor: "mdi:door-open", kabinet: "mdi:desk", sanuzel: "mdi:shower",
|
||||
tualet: "mdi:toilet", garderob: "mdi:hanger", kladovaia: "mdi:package-variant",
|
||||
terrasa: "mdi:deck", kryltso: "mdi:stairs",
|
||||
};
|
||||
const ROOM_ORDER = ["kitchen", "koridor", "spalnia", "danina_komnata", "kabinet",
|
||||
"sanuzel", "tualet", "garderob", "kladovaia", "tambur", "postirochnaia",
|
||||
"terrasa", "kryltso"];
|
||||
const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"];
|
||||
const SENSOR_HINT = /temperature|humidity|co2|illuminance/;
|
||||
|
||||
class RoomsCard extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this._areas = [];
|
||||
this._ent2area = {};
|
||||
this._selected = null;
|
||||
this._loaded = false;
|
||||
this._mode = "plan";
|
||||
this.attachShadow({ mode: "open" });
|
||||
}
|
||||
|
||||
setConfig(config) { this._config = config || {}; }
|
||||
|
||||
set hass(hass) {
|
||||
this._hass = hass;
|
||||
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
|
||||
else this._render();
|
||||
}
|
||||
|
||||
async _loadRegistries() {
|
||||
try {
|
||||
const [areas, devices, entities] = await Promise.all([
|
||||
this._hass.callWS({ type: "config/area_registry/list" }),
|
||||
this._hass.callWS({ type: "config/device_registry/list" }),
|
||||
this._hass.callWS({ type: "config/entity_registry/list" }),
|
||||
]);
|
||||
this._areas = areas;
|
||||
const devArea = {};
|
||||
for (const d of devices) if (d.area_id) devArea[d.id] = d.area_id;
|
||||
this._ent2area = {};
|
||||
for (const e of entities) {
|
||||
const a = e.area_id || devArea[e.device_id];
|
||||
if (a) this._ent2area[e.entity_id] = a;
|
||||
}
|
||||
} catch (err) { this._error = String(err); }
|
||||
this._render();
|
||||
}
|
||||
|
||||
_entitiesOf(areaId) {
|
||||
return Object.entries(this._ent2area).filter(([, a]) => a === areaId)
|
||||
.map(([e]) => e).filter((e) => this._hass.states[e]);
|
||||
}
|
||||
|
||||
_domain(e) { return e.split(".")[0]; }
|
||||
|
||||
_on(areaId) {
|
||||
return this._entitiesOf(areaId).filter((e) => {
|
||||
const st = this._hass.states[e];
|
||||
return (this._domain(e) === "light" || this._domain(e) === "switch") && st.state === "on";
|
||||
}).length;
|
||||
}
|
||||
|
||||
_sensors(areaId) {
|
||||
const out = [];
|
||||
for (const e of this._entitiesOf(areaId)) {
|
||||
if (this._domain(e) !== "sensor" || !SENSOR_HINT.test(e)) continue;
|
||||
const st = this._hass.states[e];
|
||||
out.push({ n: (st.attributes.friendly_name || e).split(" ").slice(-1)[0], v: st.state, u: st.attributes.unit_of_measurement || "" });
|
||||
}
|
||||
return out.slice(0, 2);
|
||||
}
|
||||
|
||||
_toggle(e) {
|
||||
const d = this._domain(e);
|
||||
if (d === "light" || d === "switch") this._hass.callService(d, "toggle", { entity_id: e });
|
||||
}
|
||||
|
||||
_planSvg(areaId) {
|
||||
const S = 34;
|
||||
const x0 = -2.8, y0 = -1.9, x1 = 12.4, y1 = 10.4;
|
||||
const W = (x1 - x0) * S, H = (y1 - y0) * S;
|
||||
const px = (x) => (x - x0) * S;
|
||||
const py = (y) => (y1 - y) * S;
|
||||
let rects = "";
|
||||
for (const id of ROOM_ORDER) {
|
||||
const r = AREA_RECT[id];
|
||||
if (!r) continue;
|
||||
const name = (this._areas.find((a) => a.area_id === id) || {}).name || id;
|
||||
const on = this._on(id);
|
||||
const sel = id === areaId;
|
||||
const [a0, b0, a1, b1] = r;
|
||||
const w = (a1 - a0) * S, h = (b1 - b0) * S;
|
||||
rects += `<g class="room ${sel ? "sel" : ""}" data-a="${id}">
|
||||
<rect x="${px(a0)}" y="${py(b1)}" width="${w}" height="${h}" rx="3"
|
||||
fill="${sel ? "rgba(74,163,255,.28)" : "rgba(40,48,58,.85)"}"
|
||||
stroke="${sel ? "#4aa3ff" : "#59636f"}" stroke-width="1.5"/>
|
||||
<text x="${px(a0) + 6}" y="${py(b1) + 16}" fill="#dfe8f2" font-size="11" font-weight="600">${name}</text>
|
||||
<text x="${px(a0) + 6}" y="${py(b1) + 29}" fill="#8fb6d8" font-size="9">${AREA_M2[id] || ""} м²${on ? " · 💡" + on : ""}</text>
|
||||
</g>`;
|
||||
}
|
||||
return `<svg viewBox="0 0 ${W} ${H}" class="plan">
|
||||
<rect x="0" y="0" width="${W}" height="${H}" fill="rgba(10,13,17,.6)" rx="10"/>
|
||||
${rects}</svg>`;
|
||||
}
|
||||
|
||||
_render() {
|
||||
if (!this._hass) return;
|
||||
const areaId = this._selected;
|
||||
const tiles = ROOM_ORDER.filter((a) => this._areas.some((x) => x.area_id === a)).map((id) => {
|
||||
const area = this._areas.find((x) => x.area_id === id);
|
||||
const ens = this._entitiesOf(id);
|
||||
const on = this._on(id);
|
||||
const sensors = this._sensors(id).map((s) => `${s.n}: ${s.v}${s.u}`).join(" · ");
|
||||
return `<button class="tile ${id === areaId ? "sel" : ""}" data-a="${id}">
|
||||
<div class="tile-top"><ha-icon icon="${AREA_ICON[id] || "mdi:home"}"></ha-icon>
|
||||
<span class="cnt">${ens.length}</span></div>
|
||||
<div class="tile-name">${area.name}</div>
|
||||
<div class="tile-meta">${AREA_M2[id] || ""} м²${on ? ` · 💡 ${on}` : ""}</div>
|
||||
${sensors ? `<div class="tile-sens">${sensors}</div>` : ""}</button>`;
|
||||
}).join("");
|
||||
|
||||
let detail = "";
|
||||
if (areaId) {
|
||||
const area = this._areas.find((x) => x.area_id === areaId);
|
||||
const ens = this._entitiesOf(areaId);
|
||||
const groups = {};
|
||||
for (const e of ens) (groups[this._domain(e)] ||= []).push(e);
|
||||
const order = Object.keys(groups).sort((a, b) => {
|
||||
const ia = KEY_DOMAINS.includes(a) ? KEY_DOMAINS.indexOf(a) : 50 + a.charCodeAt(0);
|
||||
const ib = KEY_DOMAINS.includes(b) ? KEY_DOMAINS.indexOf(b) : 50 + b.charCodeAt(0);
|
||||
return ia - ib;
|
||||
});
|
||||
const rows = order.map((dom) => {
|
||||
const items = groups[dom].map((e) => {
|
||||
const st = this._hass.states[e];
|
||||
const nm = st.attributes.friendly_name || e;
|
||||
const val = st.state + (st.attributes.unit_of_measurement || "");
|
||||
const act = ["light", "switch"].includes(dom)
|
||||
? `<span class="sw ${st.state === "on" ? "on" : ""}" data-e="${e}">${st.state === "on" ? "вкл" : "выкл"}</span>` : "";
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${val}</span>${act}</div>`;
|
||||
}).join("");
|
||||
return `<div class="grp"><div class="grp-h">${dom} · ${groups[dom].length}</div>${items}</div>`;
|
||||
}).join("");
|
||||
detail = `<div class="detail"><div class="d-head">${area ? area.name : areaId}
|
||||
<button class="close" data-close="1">×</button></div>${rows || "<div class='row'>нет устройств</div>"}</div>`;
|
||||
}
|
||||
|
||||
this.shadowRoot.innerHTML = `<style>
|
||||
:host { display:block; font-family: var(--paper-font-body1_-_font-family, system-ui); }
|
||||
.bar { display:flex; gap:6px; margin-bottom:8px; }
|
||||
.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; }
|
||||
.bar button.on { border-color:#4aa3ff; color:#dceaff; background:rgba(74,163,255,.16); }
|
||||
.plan { width:100%; height:auto; display:block; margin-bottom:10px; }
|
||||
.room { cursor:pointer; }
|
||||
.room:hover rect { stroke:#4aa3ff; }
|
||||
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap:10px; }
|
||||
.tile { text-align:left; border:1px solid var(--divider-color, #2a2f36); border-radius:14px;
|
||||
background: linear-gradient(160deg, rgba(30,36,44,.95), rgba(18,22,27,.95));
|
||||
color: var(--primary-text-color, #e8eef5); padding:12px; cursor:pointer; }
|
||||
.tile:hover { border-color:#4aa3ff; }
|
||||
.tile.sel { border-color:#4aa3ff; box-shadow:0 0 0 1px #4aa3ff inset; }
|
||||
.tile-top { display:flex; justify-content:space-between; align-items:center; opacity:.85; }
|
||||
.cnt { font-size:11px; padding:1px 7px; border-radius:9px; background:rgba(74,163,255,.18); color:#8fc4ff; }
|
||||
.tile-name { font-weight:600; margin-top:6px; font-size:14px; }
|
||||
.tile-meta { font-size:11px; opacity:.65; margin-top:2px; }
|
||||
.tile-sens { font-size:11px; opacity:.85; margin-top:6px; color:#9ed3ff; }
|
||||
.detail { border:1px solid #2a2f36; border-radius:14px; padding:12px; margin-top:10px;
|
||||
background: rgba(14,17,21,.92); max-height:420px; overflow:auto; }
|
||||
.d-head { font-weight:700; margin-bottom:8px; display:flex; justify-content:space-between; }
|
||||
.close { background:none;border:none;color:#9aa7b4;font-size:18px;cursor:pointer; }
|
||||
.grp-h { font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:#7d8b99; margin:10px 0 4px; }
|
||||
.row { display:flex; gap:8px; align-items:center; font-size:12px; padding:3px 0;
|
||||
border-bottom:1px dashed rgba(255,255,255,.05); }
|
||||
.nm { flex:1; opacity:.9; } .vl { opacity:.65; }
|
||||
.sw { font-size:11px; padding:1px 8px; border-radius:8px; border:1px solid #3a4350; cursor:pointer; }
|
||||
.sw.on { background:rgba(74,163,255,.2); border-color:#4aa3ff; color:#bcdcff; }
|
||||
</style>
|
||||
<div class="bar">
|
||||
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
|
||||
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
|
||||
</div>
|
||||
${this._mode === "plan" ? this._planSvg(areaId) : `<div class="grid">${tiles}</div>`}
|
||||
${detail}`;
|
||||
|
||||
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>
|
||||
b.addEventListener("click", () => { this._mode = b.dataset.mode; this._render(); }));
|
||||
this.shadowRoot.querySelectorAll(".room").forEach((g) =>
|
||||
g.addEventListener("click", () => {
|
||||
this._selected = this._selected === g.dataset.a ? null : g.dataset.a; this._render();
|
||||
}));
|
||||
this.shadowRoot.querySelectorAll(".tile").forEach((b) =>
|
||||
b.addEventListener("click", () => {
|
||||
this._selected = this._selected === b.dataset.a ? null : b.dataset.a; this._render();
|
||||
}));
|
||||
this.shadowRoot.querySelectorAll(".sw").forEach((s) =>
|
||||
s.addEventListener("click", (ev) => { ev.stopPropagation(); this._toggle(s.dataset.e); }));
|
||||
const close = this.shadowRoot.querySelector(".close");
|
||||
if (close) close.addEventListener("click", () => { this._selected = null; this._render(); });
|
||||
}
|
||||
|
||||
getCardSize() { return 8; }
|
||||
}
|
||||
|
||||
customElements.define("rooms-card", RoomsCard);
|
||||
/* Покомнатная панель: точный план владельца как подложка + кликабельные зоны. */
|
||||
const AREA_M2 = {
|
||||
kitchen: 27.65, danina_komnata: 12.04, spalnia: 14.34, postirochnaia: 4.32,
|
||||
tambur: 2.94, koridor: 6.83, kabinet: 11.45, sanuzel: 6.29, tualet: 1.43,
|
||||
garderob: 2.99, kladovaia: 1.30, terrasa: 20.09, kryltso: 3.00,
|
||||
};
|
||||
const AREA_ICON = {
|
||||
kitchen: "mdi:silverware-fork-knife", danina_komnata: "mdi:teddy-bear",
|
||||
spalnia: "mdi:bed", postirochnaia: "mdi:server", tambur: "mdi:door",
|
||||
koridor: "mdi:door-open", kabinet: "mdi:desk", sanuzel: "mdi:shower",
|
||||
tualet: "mdi:toilet", garderob: "mdi:hanger", kladovaia: "mdi:package-variant",
|
||||
terrasa: "mdi:deck", kryltso: "mdi:stairs",
|
||||
};
|
||||
/* [x0, y0, x1, y1] в метрах: x от западного края террасы, y от северной стены блока */
|
||||
const AREA_RECT = {
|
||||
terrasa: [0.00, 0.00, 2.45, 8.35],
|
||||
kitchen: [2.45, 0.00, 6.16, 8.35],
|
||||
postirochnaia: [5.71, -1.50, 7.62, 0.00],
|
||||
sanuzel: [5.83, 0.30, 7.74, 3.07],
|
||||
tualet: [8.69, 2.71, 9.40, 3.55],
|
||||
garderob: [9.05, 0.05, 10.95, 1.50],
|
||||
kladovaia: [9.29, 1.50, 10.95, 2.83],
|
||||
koridor: [9.05, 3.07, 11.07, 5.48],
|
||||
kabinet: [11.07, 0.05, 14.55, 3.31],
|
||||
danina_komnata: [7.74, 5.48, 11.07, 8.38],
|
||||
spalnia: [11.07, 3.55, 14.55, 8.60],
|
||||
tambur: [5.95, 7.41, 7.74, 8.38],
|
||||
kryltso: [5.95, 8.38, 7.74, 9.70],
|
||||
};
|
||||
const ROOM_ORDER = ["kitchen", "koridor", "spalnia", "danina_komnata", "kabinet",
|
||||
"sanuzel", "tualet", "garderob", "kladovaia", "tambur", "postirochnaia",
|
||||
"terrasa", "kryltso"];
|
||||
const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"];
|
||||
const SENSOR_HINT = /temperature|humidity|co2|illuminance/;
|
||||
/* подложка: план 916x768, дом 0..14.55 м по X и 0..8.6 м по Y от северной стены */
|
||||
const IMG_W = 916, IMG_H = 768, PX0 = 180, PY0 = 173, PX_M = 41.99, PY_M = 41.4;
|
||||
|
||||
class RoomsCard extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this._areas = [];
|
||||
this._ent2area = {};
|
||||
this._selected = null;
|
||||
this._loaded = false;
|
||||
this._mode = "plan";
|
||||
this.attachShadow({ mode: "open" });
|
||||
}
|
||||
|
||||
setConfig(config) { this._config = config || {}; }
|
||||
|
||||
set hass(hass) {
|
||||
this._hass = hass;
|
||||
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
|
||||
else this._render();
|
||||
}
|
||||
|
||||
async _loadRegistries() {
|
||||
try {
|
||||
const [areas, devices, entities] = await Promise.all([
|
||||
this._hass.callWS({ type: "config/area_registry/list" }),
|
||||
this._hass.callWS({ type: "config/device_registry/list" }),
|
||||
this._hass.callWS({ type: "config/entity_registry/list" }),
|
||||
]);
|
||||
this._areas = areas;
|
||||
const devArea = {};
|
||||
for (const d of devices) if (d.area_id) devArea[d.id] = d.area_id;
|
||||
this._ent2area = {};
|
||||
for (const e of entities) {
|
||||
const a = e.area_id || devArea[e.device_id];
|
||||
if (a) this._ent2area[e.entity_id] = a;
|
||||
}
|
||||
} catch (err) { this._error = String(err); }
|
||||
this._render();
|
||||
}
|
||||
|
||||
_entitiesOf(areaId) {
|
||||
return Object.entries(this._ent2area).filter(([, a]) => a === areaId)
|
||||
.map(([e]) => e).filter((e) => this._hass.states[e]);
|
||||
}
|
||||
|
||||
_domain(e) { return e.split(".")[0]; }
|
||||
|
||||
_on(areaId) {
|
||||
return this._entitiesOf(areaId).filter((e) => {
|
||||
const st = this._hass.states[e];
|
||||
return (this._domain(e) === "light" || this._domain(e) === "switch") && st.state === "on";
|
||||
}).length;
|
||||
}
|
||||
|
||||
_sensors(areaId) {
|
||||
const out = [];
|
||||
for (const e of this._entitiesOf(areaId)) {
|
||||
if (this._domain(e) !== "sensor" || !SENSOR_HINT.test(e)) continue;
|
||||
const st = this._hass.states[e];
|
||||
out.push(`${(st.attributes.friendly_name || e).split(" ").slice(-1)[0]}: ${st.state}${st.attributes.unit_of_measurement || ""}`);
|
||||
}
|
||||
return out.slice(0, 2);
|
||||
}
|
||||
|
||||
_toggle(e) {
|
||||
const d = this._domain(e);
|
||||
if (d === "light" || d === "switch") this._hass.callService(d, "toggle", { entity_id: e });
|
||||
}
|
||||
|
||||
_hotspots(areaId) {
|
||||
let out = "";
|
||||
for (const id of ROOM_ORDER) {
|
||||
const r = AREA_RECT[id];
|
||||
if (!r) continue;
|
||||
const [x0, y0, x1, y1] = r;
|
||||
const left = ((x0 * PX_M + PX0) / IMG_W) * 100;
|
||||
const top = ((y0 * PY_M + PY0) / IMG_H) * 100;
|
||||
const w = (((x1 - x0) * PX_M) / IMG_W) * 100;
|
||||
const h = (((y1 - y0) * PY_M) / IMG_H) * 100;
|
||||
const name = (this._areas.find((a) => a.area_id === id) || {}).name || id;
|
||||
out += `<div class="hs ${id === areaId ? "sel" : ""}" data-a="${id}"
|
||||
style="left:${left}%;top:${top}%;width:${w}%;height:${h}%"
|
||||
title="${name} · ${AREA_M2[id] || ""} м²"></div>`;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
_render() {
|
||||
if (!this._hass) return;
|
||||
const areaId = this._selected;
|
||||
const plan = `<div class="plan-wrap">
|
||||
<img src="/local/house3d/plan.png" alt="План дома"/>
|
||||
${this._hotspots(areaId)}
|
||||
</div>`;
|
||||
|
||||
const tiles = ROOM_ORDER.filter((a) => this._areas.some((x) => x.area_id === a)).map((id) => {
|
||||
const area = this._areas.find((x) => x.area_id === id);
|
||||
const ens = this._entitiesOf(id);
|
||||
const on = this._on(id);
|
||||
const sensors = this._sensors(id).join(" · ");
|
||||
return `<button class="tile ${id === areaId ? "sel" : ""}" data-a="${id}">
|
||||
<div class="tile-top"><ha-icon icon="${AREA_ICON[id] || "mdi:home"}"></ha-icon>
|
||||
<span class="cnt">${ens.length}</span></div>
|
||||
<div class="tile-name">${area.name}</div>
|
||||
<div class="tile-meta">${AREA_M2[id] || ""} м²${on ? ` · 💡 ${on}` : ""}</div>
|
||||
${sensors ? `<div class="tile-sens">${sensors}</div>` : ""}</button>`;
|
||||
}).join("");
|
||||
|
||||
let detail = "";
|
||||
if (areaId) {
|
||||
const area = this._areas.find((x) => x.area_id === areaId);
|
||||
const ens = this._entitiesOf(areaId);
|
||||
const groups = {};
|
||||
for (const e of ens) (groups[this._domain(e)] ||= []).push(e);
|
||||
const rows = Object.keys(groups).sort((a, b) => {
|
||||
const ia = KEY_DOMAINS.includes(a) ? KEY_DOMAINS.indexOf(a) : 60 + a.charCodeAt(0);
|
||||
const ib = KEY_DOMAINS.includes(b) ? KEY_DOMAINS.indexOf(b) : 60 + b.charCodeAt(0);
|
||||
return ia - ib;
|
||||
}).map((dom) => {
|
||||
const items = groups[dom].map((e) => {
|
||||
const st = this._hass.states[e];
|
||||
const nm = st.attributes.friendly_name || e;
|
||||
const val = st.state + (st.attributes.unit_of_measurement || "");
|
||||
const act = ["light", "switch"].includes(dom)
|
||||
? `<span class="sw ${st.state === "on" ? "on" : ""}" data-e="${e}">${st.state === "on" ? "вкл" : "выкл"}</span>` : "";
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${val}</span>${act}</div>`;
|
||||
}).join("");
|
||||
return `<div class="grp"><div class="grp-h">${dom} · ${groups[dom].length}</div>${items}</div>`;
|
||||
}).join("");
|
||||
detail = `<div class="detail"><div class="d-head">${area ? area.name : areaId}
|
||||
<button class="close" data-close="1">×</button></div>${rows || "<div class='row'>нет устройств</div>"}</div>`;
|
||||
}
|
||||
|
||||
this.shadowRoot.innerHTML = `<style>
|
||||
:host { display:block; font-family: var(--paper-font-body1_-_font-family, system-ui); }
|
||||
.bar { display:flex; gap:6px; margin-bottom:8px; }
|
||||
.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; }
|
||||
.bar button.on { border-color:#4aa3ff; color:#dceaff; background:rgba(74,163,255,.16); }
|
||||
.plan-wrap { position:relative; border-radius:12px; overflow:hidden; background:#f7f7f4; }
|
||||
.plan-wrap img { display:block; width:100%; height:auto; }
|
||||
.hs { position:absolute; cursor:pointer; border:2px solid transparent; border-radius:4px; transition:.12s; }
|
||||
.hs:hover { border-color:#2f7fe0; background:rgba(47,127,224,.16); }
|
||||
.hs.sel { border-color:#2f7fe0; background:rgba(47,127,224,.26); }
|
||||
.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;
|
||||
background: linear-gradient(160deg, rgba(30,36,44,.95), rgba(18,22,27,.95));
|
||||
color: #e8eef5; padding:12px; cursor:pointer; }
|
||||
.tile:hover { border-color:#4aa3ff; }
|
||||
.tile.sel { border-color:#4aa3ff; box-shadow:0 0 0 1px #4aa3ff inset; }
|
||||
.tile-top { display:flex; justify-content:space-between; align-items:center; opacity:.85; }
|
||||
.cnt { font-size:11px; padding:1px 7px; border-radius:9px; background:rgba(74,163,255,.18); color:#8fc4ff; }
|
||||
.tile-name { font-weight:600; margin-top:6px; font-size:14px; }
|
||||
.tile-meta { font-size:11px; opacity:.65; margin-top:2px; }
|
||||
.tile-sens { font-size:11px; opacity:.85; margin-top:6px; color:#9ed3ff; }
|
||||
.detail { border:1px solid #2a2f36; border-radius:14px; padding:12px; margin-top:10px;
|
||||
background: rgba(14,17,21,.92); max-height:420px; overflow:auto; }
|
||||
.d-head { font-weight:700; margin-bottom:8px; display:flex; justify-content:space-between; }
|
||||
.close { background:none;border:none;color:#9aa7b4;font-size:18px;cursor:pointer; }
|
||||
.grp-h { font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:#7d8b99; margin:10px 0 4px; }
|
||||
.row { display:flex; gap:8px; align-items:center; font-size:12px; padding:3px 0;
|
||||
border-bottom:1px dashed rgba(255,255,255,.05); }
|
||||
.nm { flex:1; opacity:.9; } .vl { opacity:.65; }
|
||||
.sw { font-size:11px; padding:1px 8px; border-radius:8px; border:1px solid #3a4350; cursor:pointer; }
|
||||
.sw.on { background:rgba(74,163,255,.2); border-color:#4aa3ff; color:#bcdcff; }
|
||||
</style>
|
||||
<div class="bar">
|
||||
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
|
||||
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
|
||||
</div>
|
||||
${this._mode === "plan" ? plan : `<div class="grid">${tiles}</div>`}
|
||||
${detail}`;
|
||||
|
||||
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>
|
||||
b.addEventListener("click", () => { this._mode = b.dataset.mode; this._render(); }));
|
||||
this.shadowRoot.querySelectorAll(".hs, .tile").forEach((el) =>
|
||||
el.addEventListener("click", () => {
|
||||
this._selected = this._selected === el.dataset.a ? null : el.dataset.a; this._render();
|
||||
}));
|
||||
this.shadowRoot.querySelectorAll(".sw").forEach((s) =>
|
||||
s.addEventListener("click", (ev) => { ev.stopPropagation(); this._toggle(s.dataset.e); }));
|
||||
const close = this.shadowRoot.querySelector(".close");
|
||||
if (close) close.addEventListener("click", () => { this._selected = null; this._render(); });
|
||||
}
|
||||
|
||||
getCardSize() { return 12; }
|
||||
}
|
||||
|
||||
customElements.define("rooms-card", RoomsCard);
|
||||
Reference in new issue
Block a user