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