diff --git a/ops/home/rooms-card.js b/ops/home/rooms-card.js
index c85eac5..2b65f92 100644
--- a/ops/home/rooms-card.js
+++ b/ops/home/rooms-card.js
@@ -1,40 +1,25 @@
-/* Покомнатная панель с редактором границ: тянете вершины — получаете точный план. */
-const ROOMS = [
- { id: "terrasa", name: "Терраса", icon: "mdi:deck",
- 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",
- poly: [[2.45, 0.00], [5.60, 0.00], [5.60, 4.30], [6.21, 4.30],
- [6.21, 8.60], [2.45, 8.60]] },
- { id: "postirochnaia", name: "Тех.пом.", icon: "mdi:server",
- poly: [[4.90, -1.50], [7.40, -1.50], [7.40, 0.00], [4.90, 0.00]] },
- { id: "sanuzel", name: "Санузел", icon: "mdi:shower",
- poly: [[5.83, 0.00], [7.95, 0.00], [7.95, 1.55], [7.00, 1.55],
- [7.00, 2.97], [5.83, 2.97]] },
- { id: "tualet", name: "Туалет", icon: "mdi:toilet",
- poly: [[8.00, 2.20], [9.20, 2.20], [9.20, 3.30], [8.00, 3.30]] },
- { id: "garderob", name: "Гардероб", icon: "mdi:hanger",
- poly: [[9.30, 0.00], [11.33, 0.00], [11.33, 1.30], [9.30, 1.30]] },
- { id: "kladovaia", name: "Кладовая", icon: "mdi:package-variant",
- poly: [[9.30, 1.30], [10.81, 1.30], [10.81, 2.40], [9.30, 2.40]] },
- { id: "koridor", name: "Холл", icon: "mdi:door-open",
- poly: [[7.60, 2.97], [11.33, 2.97], [11.33, 5.29], [7.60, 5.29]] },
- { id: "prihozhaya", name: "Прихожая", icon: "mdi:door",
- poly: [[5.95, 5.10], [8.00, 5.10], [8.00, 7.20], [5.95, 7.20]] },
- { id: "tambur", name: "Тамбур", icon: "mdi:door",
- poly: [[5.95, 7.20], [8.00, 7.20], [8.00, 8.60], [5.95, 8.60]] },
- { id: "kabinet", name: "Комната 11,45", icon: "mdi:desk",
- poly: [[11.60, 0.00], [14.52, 0.00], [14.52, 4.30], [11.60, 4.30]] },
- { id: "danina_komnata", name: "Комната 12,04", icon: "mdi:teddy-bear",
- poly: [[7.30, 5.29], [11.33, 5.29], [11.33, 8.60], [7.30, 8.60]] },
- { id: "spalnia", name: "Комната 14,34", icon: "mdi:bed",
- poly: [[11.33, 4.30], [14.52, 4.30], [14.52, 8.60], [11.33, 8.60]] },
- { id: "kryltso", name: "Крыльцо", icon: "mdi:stairs",
- poly: [[5.95, 8.60], [8.20, 8.60], [8.20, 10.10], [5.95, 10.10]] },
-];
+/* Покомнатная панель: подложка-план + обводка комнат мышью (сохранение + экспорт). */
+const PLAN_W = 916, PLAN_H = 768;
+/* стартовые контуры (в пикселях подложки), сняты ориентировочно */
+const START = {
+ terrasa: [[180, 173], [283, 173], [283, 529], [180, 529]],
+ kitchen: [[283, 173], [415, 173], [415, 351], [441, 351], [441, 529], [283, 529]],
+ postirochnaia: [[386, 111], [491, 111], [491, 173], [386, 173]],
+ sanuzel: [[425, 173], [514, 173], [514, 237], [474, 237], [474, 296], [425, 296]],
+ tualet: [[516, 264], [566, 264], [566, 310], [516, 310]],
+ garderob: [[571, 173], [656, 173], [656, 227], [571, 227]],
+ kladovaia: [[571, 227], [635, 227], [635, 272], [571, 272]],
+ koridor: [[499, 296], [656, 296], [656, 392], [499, 392]],
+ prihozhaya: [[430, 384], [516, 384], [516, 471], [430, 471]],
+ tambur: [[430, 471], [516, 471], [516, 529], [430, 529]],
+ kabinet: [[667, 173], [791, 173], [791, 351], [667, 351]],
+ danina_komnata: [[487, 392], [667, 392], [667, 529], [487, 529]],
+ spalnia: [[667, 351], [791, 351], [791, 529], [667, 529]],
+ kryltso: [[430, 529], [516, 529], [516, 590], [430, 590]],
+};
const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"];
const SENSOR_HINT = /temperature|humidity|co2|illuminance/;
-const VB = [-0.4, -1.9, 15.0, 10.5];
-const STORE = "house3d_room_polys";
+const STORE = "house3d_room_px";
class RoomsCard extends HTMLElement {
constructor() {
@@ -44,24 +29,22 @@ class RoomsCard extends HTMLElement {
this._selected = null;
this._loaded = false;
this._mode = "plan";
- this._edit = false;
- this._polys = JSON.parse(JSON.stringify(ROOMS.map((r) => r.poly)));
+ this._draw = false;
+ this._drawRoom = null;
+ this._tmp = [];
+ this._polys = JSON.parse(JSON.stringify(START));
try {
- const saved = localStorage.getItem(STORE);
- if (saved) {
- const arr = JSON.parse(saved);
- if (Array.isArray(arr) && arr.length === ROOMS.length) this._polys = arr;
- }
+ const saved = JSON.parse(localStorage.getItem(STORE) || "null");
+ if (saved && typeof saved === "object") this._polys = saved;
} catch (e) { /* ignore */ }
this.attachShadow({ mode: "open" });
}
setConfig(config) { this._config = config || {}; }
-
set hass(hass) {
this._hass = hass;
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
- else if (!this._dragging) this._render();
+ else if (!this._busy) this._render();
}
async _loadRegistries() {
@@ -83,12 +66,22 @@ class RoomsCard extends HTMLElement {
this._render();
}
+ _roomList() {
+ const names = {
+ terrasa: "Терраса", kitchen: "Кухня-гостиная", postirochnaia: "Тех.пом.",
+ sanuzel: "Санузел", tualet: "Туалет", garderob: "Гардероб", kladovaia: "Кладовая",
+ koridor: "Холл", prihozhaya: "Прихожая", tambur: "Тамбур",
+ kabinet: "Комната 11,45", danina_komnata: "Комната 12,04",
+ spalnia: "Комната 14,34", kryltso: "Крыльцо",
+ };
+ return Object.keys(START).map((id) => ({ id, name: names[id] || id }));
+ }
+
_entitiesOf(areaId) {
if (!areaId) return [];
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(id) {
return this._entitiesOf(id).filter((e) => {
@@ -111,89 +104,69 @@ class RoomsCard extends HTMLElement {
}
_planSvg(areaId) {
- const [vx, vy, vw, vh] = VB;
- let shapes = "", labels = "", handles = "";
- ROOMS.forEach((r, ri) => {
- const poly = this._polys[ri];
- const pts = poly.map(([x, y]) => `${x},${y}`).join(" ");
+ let shapes = "", labels = "", tmp = "";
+ for (const r of this._roomList()) {
+ const poly = this._polys[r.id] || [];
+ if (!poly.length) continue;
const sel = r.id === areaId;
- shapes += `
+