From 7af3d4a40369f4409fbb757507a4794c18b8c2bd Mon Sep 17 00:00:00 2001 From: Roman Buryan Date: Sun, 1 Nov 2026 23:55:07 +0300 Subject: [PATCH] =?UTF-8?q?[HOME]=20=D0=9F=D0=B0=D0=BD=D0=B5=D0=BB=D1=8C:?= =?UTF-8?q?=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D0=B2=D0=B5=D1=82=D0=BE=D0=BC=20(=D1=8F=D1=80=D0=BA?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C),=20=D0=BA=D0=BB=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D0=BC,=20=D0=BC=D0=B5=D0=B4=D0=B8=D0=B0=20=D0=B8?= =?UTF-8?q?=20=D1=88=D1=82=D0=BE=D1=80=D0=B0=D0=BC=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D1=8F=D0=BC=D0=BE=20=D0=B8=D0=B7=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=BA=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BD=D0=B0=D1=82?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ops/home/rooms-card.js | 94 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 9 deletions(-) diff --git a/ops/home/rooms-card.js b/ops/home/rooms-card.js index 4137434..4bcc464 100644 --- a/ops/home/rooms-card.js +++ b/ops/home/rooms-card.js @@ -40,6 +40,20 @@ class RoomsCard extends HTMLElement { this.attachShadow({ mode: "open" }); } + connectedCallback() { + this._on3d = (ev) => { + const room = ev && ev.detail ? ev.detail.room : null; + this._selected = room || null; + this._mode = "plan"; + this._render(); + }; + document.addEventListener("house3d-room", this._on3d); + } + + disconnectedCallback() { + if (this._on3d) document.removeEventListener("house3d-room", this._on3d); + } + setConfig(config) { this._config = config || {}; } set hass(hass) { this._hass = hass; @@ -141,6 +155,42 @@ class RoomsCard extends HTMLElement { }); } + _entityRow(e, dom) { + const st = this._hass.states[e]; + const nm = st.attributes.friendly_name || e; + const on = st.state === "on"; + if (dom === "light") { + const br = st.attributes.brightness; + const pct = br ? Math.round((br / 255) * 100) : 0; + return `
${nm} + + ${on ? "вкл" : "выкл"}
`; + } + if (dom === "climate") { + const cur = st.attributes.current_temperature; + const tgt = st.attributes.temperature; + return `
${nm} + ${cur !== undefined ? cur + "°" : ""} → ${tgt !== undefined ? tgt + "°" : ""} + − + +
`; + } + if (dom === "media_player") { + const playing = st.state === "playing"; + return `
${nm}${st.state} + ${playing ? "⏸" : "▶"}
`; + } + if (dom === "cover") { + return `
${nm}${st.state} + ↑ + ■ + ↓
`; + } + const val = st.state + (st.attributes.unit_of_measurement || ""); + const act = dom === "switch" + ? `${on ? "вкл" : "выкл"}` : ""; + return `
${nm}${val}${act}
`; + } + _render() { if (!this._hass) return; const areaId = this._selected; @@ -179,14 +229,7 @@ class RoomsCard extends HTMLElement { 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) - ? `${st.state === "on" ? "вкл" : "выкл"}` : ""; - return `
${nm}${val}${act}
`; - }).join(""); + const items = groups[dom].map((e) => this._entityRow(e, dom)).join(""); return `
${dom} · ${groups[dom].length}
${items}
`; }).join(""); detail = `
${(list.find((r) => r.id === areaId) || {}).name || areaId} @@ -237,6 +280,8 @@ class RoomsCard extends HTMLElement { 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; } + .br { width:70px; accent-color:#4aa3ff; } + .btn { font-size:12px; padding:0 6px; border-radius:6px; border:1px solid #3a4350; cursor:pointer; } .sw.on { background:rgba(74,163,255,.2); border-color:#4aa3ff; color:#bcdcff; }
@@ -308,10 +353,41 @@ class RoomsCard extends HTMLElement { if (dl) dl.addEventListener("click", () => this._download()); this.shadowRoot.querySelectorAll(".tile").forEach((el) => el.addEventListener("click", () => { - this._selected = this._selected === el.dataset.a ? null : el.dataset.a; this._render(); + this._selected = this._selected === el.dataset.a ? null : el.dataset.a; + document.dispatchEvent(new CustomEvent("house3d-select", + { detail: { room: this._selected ? "zone_" + this._selected : null } })); + this._render(); })); this.shadowRoot.querySelectorAll(".sw").forEach((s) => s.addEventListener("click", (ev) => { ev.stopPropagation(); this._toggle(s.dataset.e); })); + this.shadowRoot.querySelectorAll(".br").forEach((el) => + el.addEventListener("change", (ev) => { + ev.stopPropagation(); + const pct = parseInt(ev.target.value, 10); + this._hass.callService("light", "turn_on", { + entity_id: ev.target.dataset.e, brightness_pct: pct, + }); + })); + this.shadowRoot.querySelectorAll("[data-clim]").forEach((el) => + el.addEventListener("click", (ev) => { + ev.stopPropagation(); + const eid = el.dataset.clim; + const st = this._hass.states[eid]; + const cur = st.attributes.temperature || 20; + this._hass.callService("climate", "set_temperature", { + entity_id: eid, temperature: Math.round((cur + parseFloat(el.dataset.d)) * 2) / 2, + }); + })); + this.shadowRoot.querySelectorAll("[data-media]").forEach((el) => + el.addEventListener("click", (ev) => { + ev.stopPropagation(); + this._hass.callService("media_player", el.dataset.a, { entity_id: el.dataset.media }); + })); + this.shadowRoot.querySelectorAll("[data-cover]").forEach((el) => + el.addEventListener("click", (ev) => { + ev.stopPropagation(); + this._hass.callService("cover", el.dataset.a, { entity_id: el.dataset.cover }); + })); const close = this.shadowRoot.querySelector(".close"); if (close) close.addEventListener("click", () => { this._selected = null; this._render(); }); }