[HOME] Карточка комнаты: рендеры проекта (ванная) сверху + пассивные показатели (температура, влажность, датчики) в каждой комнате
lint / hygiene (push) Failing after 24s
No files matched your search
|
Before Width: | Height: | Size: 1.6 MiB After Width: | Height: | Size: 1.6 MiB |
@@ -728,91 +728,89 @@ def main():
|
||||
min(_ay, _by), max(_ay, _by), ZI, ZI + WHI, I_WALL.get(_rid, _wlight))
|
||||
|
||||
|
||||
# ================= ВАННАЯ C (по привязкам владельца) =================
|
||||
# C1 — дверь, C3 — робот, C4 — ванна (дерево), C6 — окно, C7 — раковина и шкафы
|
||||
# ================= ВАННАЯ C (по проекту владельца) =================
|
||||
_bw = mat_tex("B_Wood", os.path.join(TDIR, "tex_bath_wood.png"), 0.35)
|
||||
_bd = mat_tex("B_Dark", os.path.join(TDIR, "tex_bath_dark.png"), 0.4)
|
||||
_white2 = mat("B_White", "F4F4F0", 0.25)
|
||||
_chrome = mat("B_Chrome", "B9C0C6", 0.25, 0.9)
|
||||
_blackm = mat("B_Black", "16181A", 0.35, 0.6)
|
||||
_bwood = mat("B_WoodCab", "8B5E3C", 0.45)
|
||||
_bstone = mat("B_Stone", "6E7679", 0.4)
|
||||
_gmat = mat("B_Mat", "C8B49A", 0.9)
|
||||
_wh = mat("B_White", "F4F4F0", 0.25)
|
||||
_chr = mat("B_Chrome", "B9C0C6", 0.25, 0.9)
|
||||
_blk = mat("B_Black", "16181A", 0.35, 0.6)
|
||||
_wood = mat("B_WoodCab", "8B5E3C", 0.45)
|
||||
_st = mat("B_Stone", "6E7679", 0.4)
|
||||
_ceil = mat("B_Ceil", "3A3E42", 0.8)
|
||||
_lmp = mat("B_Spot", "F3F0E6", 0.3)
|
||||
|
||||
# контур: L-образный (низ широкий, верх — узкая часть у окна)
|
||||
_bx0, _bx1 = 3.38, 6.55
|
||||
_by0, _by1 = 5.68, 8.60
|
||||
_nw = 5.15 # западная граница верхней части
|
||||
_ny = 7.25 # северная граница нижней части
|
||||
_nw, _ny = 5.15, 7.25
|
||||
# потолок тёмный
|
||||
|
||||
_floor_poly("bath_floor", ROOMS_M["sanuzel"], ZI - 0.015, 0.03, mat("B_FloorDark", "23262A", 0.55))
|
||||
|
||||
# стены: дерево — C4 (север нижней части) и C5 (запад верхней), остальное тёмное
|
||||
_zf = bpy.data.objects.get("zone_sanuzel")
|
||||
if _zf:
|
||||
_zf.data.materials.clear()
|
||||
_zf.data.materials.append(mat("B_FloorDark", "23262A", 0.55))
|
||||
# стены: дерево C4/C5/C3, серый C1/C2/C6/C7
|
||||
box("bath_c4", _bx0, _nw, _ny - 0.03, _ny, ZI, ZI + WHI, _bw)
|
||||
box("bath_c5", _nw - 0.03, _nw, _ny, _by1, ZI, ZI + WHI, _bw)
|
||||
box("bath_c3", _bx0, _bx0 + 0.03, _by0, _ny, ZI, ZI + WHI, _bw)
|
||||
box("bath_c7", _bx1 - 0.03, _bx1, _by0, _by1, ZI, ZI + WHI, _bd)
|
||||
box("bath_c6", _nw, _bx1, _by1 - 0.03, _by1, ZI, ZI + WHI, _bd)
|
||||
box("bath_c3", _bx0, _bx0 + 0.03, _by0, _ny, ZI, ZI + WHI, _bw)
|
||||
box("bath_c1a", 4.67, 5.75, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||
box("bath_c1b", 6.45, _bx1, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||
box("bath_c1_top", 5.75, 6.45, _by0, _by0 + 0.03, ZI + 2.05, ZI + WHI, _bd)
|
||||
box("bath_c1a", 4.67, 5.10, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||
box("bath_c1_top", 5.10, 6.00, _by0, _by0 + 0.03, ZI + 2.05, ZI + WHI, _bd)
|
||||
box("bath_c1b", 6.00, _bx1, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||
box("bath_c2", _bx0, 4.67, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||
|
||||
# окно на C6
|
||||
box("bath_win", 5.45, 6.25, _by1 - 0.05, _by1 + 0.01, ZI + 1.35, ZI + 2.05, _chrome)
|
||||
box("bath_win_glass", 5.5, 6.2, _by1 - 0.03, _by1 - 0.01, ZI + 1.4, ZI + 2.0,
|
||||
mat("B_WinGlass", "C9D4DA", 0.1))
|
||||
box("bath_win", 5.45, 6.25, _by1 - 0.05, _by1 - 0.01, ZI + 1.30, ZI + 2.00, _wh)
|
||||
box("bath_win_g", 5.5, 6.2, _by1 - 0.03, _by1 - 0.001, ZI + 1.35, ZI + 1.95, mat("B_Win", "DCE3E6", 0.15))
|
||||
|
||||
# ВАННА на C4 (дерево), вдоль стены
|
||||
_tx0, _tx1 = _bx0 + 0.1, _nw - 0.1
|
||||
_ty0, _ty1 = _ny - 0.82, _ny - 0.07
|
||||
box("bath_tub", _tx0, _tx1, _ty0, _ty1, ZI + 0.02, ZI + 0.58, _white2)
|
||||
box("bath_tub_in", _tx0 + 0.09, _tx1 - 0.09, _ty0 + 0.09, _ty1 - 0.09,
|
||||
ZI + 0.3, ZI + 0.62, _bd)
|
||||
box("bath_tub_front", _tx0, _tx1, _ty0 - 0.04, _ty0, ZI + 0.02, ZI + 0.6, _bwood)
|
||||
box("bath_glass", _tx1, _tx1 + 0.03, _ty0, _ty1, ZI + 0.6, ZI + 1.9, _chrome)
|
||||
|
||||
# ВАННА вдоль C4: тёмный подвесной фронт, белая чаша
|
||||
_tx0, _tx1 = _bx0 + 0.12, _nw - 0.10
|
||||
_ty0, _ty1 = _ny - 0.80, _ny - 0.06
|
||||
box("bath_tub", _tx0, _tx1, _ty0, _ty1, ZI + 0.05, ZI + 0.58, _wh)
|
||||
box("bath_tub_in", _tx0 + 0.09, _tx1 - 0.09, _ty0 + 0.09, _ty1 - 0.09, ZI + 0.28, ZI + 0.62, _st)
|
||||
box("bath_tub_front", _tx0, _tx1, _ty0 - 0.05, _ty0, ZI, ZI + 0.62, mat("B_TubPanel", "4A4E52", 0.5))
|
||||
# стеклянная перегородка на чёрном профиле (у изголовья)
|
||||
box("bath_glass", _tx1, _tx1 + 0.02, _ty0, _ty1, ZI + 0.62, ZI + 1.95, mat("B_Glass", "AFC0C8", 0.1))
|
||||
box("bath_glass_fr", _tx1 - 0.01, _tx1 + 0.03, _ty0, _ty1, ZI + 0.62, ZI + 0.66, _blk)
|
||||
|
||||
# ДУШ: только стойка на C3 (по фото, без кабины)
|
||||
box("bath_shaft", _bx0 + 0.05, _bx0 + 0.09, 7.00, 7.04, ZI + 0.6, ZI + 2.2, _blackm)
|
||||
box("bath_rain", _bx0 + 0.05, _bx0 + 0.42, 6.99, 7.07, ZI + 2.1, ZI + 2.14, _blackm)
|
||||
box("bath_shower_mix", _bx0 + 0.05, _bx0 + 0.13, 7.05, 7.18, ZI + 1.0, ZI + 1.08, _blackm)
|
||||
# ДУШ: стойка на C3 над ванной
|
||||
box("bath_shaft", _bx0 + 0.05, _bx0 + 0.09, _ny - 0.22, _ny - 0.18, ZI + 0.7, ZI + 2.15, _blk)
|
||||
box("bath_rain", _bx0 + 0.05, _bx0 + 0.45, _ny - 0.24, _ny - 0.16, ZI + 2.05, ZI + 2.09, _blk)
|
||||
box("bath_mix", _bx0 + 0.05, _bx0 + 0.13, _ny - 0.17, _ny - 0.04, ZI + 1.05, ZI + 1.13, _blk)
|
||||
|
||||
# РАКОВИНА и шкафы на C7
|
||||
_vx0, _vx1 = _bx1 - 0.55, _bx1 - 0.06
|
||||
_vy0, _vy1 = 5.95, 6.85
|
||||
box("bath_van", _vx0, _vx1, _vy0, _vy1, ZI + 0.32, ZI + 0.8, _bwood)
|
||||
box("bath_vtop", _vx0 - 0.02, _vx1 + 0.02, _vy0 - 0.02, _vy1 + 0.02, ZI + 0.8, ZI + 0.84, _bstone)
|
||||
box("bath_sink", _vx0 + 0.07, _vx1 - 0.07, _vy0 + 0.16, _vy1 - 0.16, ZI + 0.84, ZI + 0.98, _white2)
|
||||
box("bath_mirror", _bx1 - 0.07, _bx1 - 0.05, _vy0 + 0.18, _vy1 - 0.18, ZI + 1.2, ZI + 1.85, _chrome)
|
||||
box("bath_mirror_led", _bx1 - 0.06, _bx1 - 0.02, _vy0 + 0.02, _vy1 - 0.02, ZI + 1.12, ZI + 1.16, _lamp)
|
||||
# шкафы вдоль C7 выше раковины
|
||||
for _i, _z in enumerate((1.15, 1.55, 1.95)):
|
||||
box("bath_shelf7_%d" % _i, _bx1 - 0.27, _bx1 - 0.02, 7.50, 8.40, ZI + _z, ZI + _z + 0.04, _bwood)
|
||||
box("bath_side7", _bx1 - 0.29, _bx1 - 0.25, 7.50, 8.40, ZI + 1.1, ZI + 2.0, _bwood)
|
||||
# УНИТАЗ на C7 у северного угла + деревянные полки рядом
|
||||
box("bath_wc", 6.02, 6.42, 8.05, 8.50, ZI + 0.28, ZI + 0.70, _wh)
|
||||
box("bath_wc_panel", 6.45, _bx1 - 0.03, 7.95, 8.52, ZI + 0.2, ZI + 1.05, _wood)
|
||||
for _i, _z in enumerate((1.2, 1.6, 2.0)):
|
||||
box("bath_cub_%d" % _i, 6.10, 6.45, 7.40, 7.90, ZI + _z, ZI + _z + 0.04, _wood)
|
||||
box("bath_cub_side", 6.10, 6.14, 7.40, 7.90, ZI + 1.15, ZI + 2.04, _wood)
|
||||
|
||||
# УНИТАЗ у окна (на C6)
|
||||
box("bath_wc", 5.86, 6.26, 8.00, 8.45, ZI, ZI + 0.38, _white2)
|
||||
box("bath_wc_t", 5.88, 6.24, 8.02, 8.43, ZI + 0.38, ZI + 0.41, _white2)
|
||||
box("bath_wc_panel", 5.86, 6.26, _by1 - 0.09, _by1 - 0.03, ZI + 0.3, ZI + 0.95, _bwood)
|
||||
# ТУМБА + накладная раковина + подсвеченное зеркало на C7
|
||||
_vx0, _vx1 = 6.05, 6.52
|
||||
_vy0, _vy1 = 6.15, 7.05
|
||||
box("bath_van", _vx0, _vx1, _vy0, _vy1, ZI + 0.35, ZI + 0.80, _wood)
|
||||
box("bath_vtop", _vx0 - 0.02, _vx1 + 0.02, _vy0 - 0.02, _vy1 + 0.02, ZI + 0.80, ZI + 0.84, _blk)
|
||||
box("bath_sink", _vx0 + 0.05, _vx1 - 0.05, _vy0 + 0.18, _vy1 - 0.18, ZI + 0.84, ZI + 1.00, _wh)
|
||||
box("bath_mirror", _bx1 - 0.07, _bx1 - 0.05, _vy0 + 0.10, _vy1 - 0.10, ZI + 1.15, ZI + 1.95, _chr)
|
||||
box("bath_mirror_led", _bx1 - 0.09, _bx1 - 0.02, _vy0 + 0.06, _vy1 - 0.06, ZI + 1.10, ZI + 1.15, _lmp)
|
||||
|
||||
# полки с полотенцами над ванной на C4
|
||||
box("bath_shelf", 3.65, 4.25, _ny - 0.32, _ny - 0.05, ZI + 1.35, ZI + 1.39, _blackm)
|
||||
box("bath_towel1", 3.68, 4.22, _ny - 0.3, _ny - 0.08, ZI + 1.39, ZI + 1.55, _blackm)
|
||||
box("bath_towel2", 3.68, 4.22, _ny - 0.3, _ny - 0.08, ZI + 1.55, ZI + 1.7, _bd)
|
||||
# ДВЕРЬ на C1 + полотенцесушитель рядом
|
||||
box("bath_door", 5.10, 6.00, _by0 + 0.02, _by0 + 0.08, ZI + 0.02, ZI + 2.05, _wh)
|
||||
box("bath_door_line", 5.10, 6.00, _by0 + 0.01, _by0 + 0.09, ZI + 1.02, ZI + 1.06, mat("B_DoorLine", "D8D2C4", 0.6))
|
||||
for _i, _z in enumerate((0.95, 1.20, 1.45)):
|
||||
box("bath_rad_%d" % _i, 4.20, 4.80, _by0 + 0.06, _by0 + 0.10, ZI + _z, ZI + _z + 0.04, _blk)
|
||||
box("bath_rad_l", 4.18, 4.22, _by0 + 0.06, _by0 + 0.10, ZI + 0.9, ZI + 1.5, _blk)
|
||||
box("bath_rad_r", 4.78, 4.82, _by0 + 0.06, _by0 + 0.10, ZI + 0.9, ZI + 1.5, _blk)
|
||||
|
||||
# робот-пылесос у C3
|
||||
box("bath_robot", _bx0 + 0.15, _bx0 + 0.5, 6.45, 6.8, ZI, ZI + 0.32, _white2)
|
||||
box("bath_robot_d", _bx0 + 0.21, _bx0 + 0.44, 6.51, 6.74, ZI + 0.32, ZI + 0.34, _blackm)
|
||||
# кресло у тумбы
|
||||
box("bath_chair", 5.45, 5.85, 6.25, 6.65, ZI + 0.42, ZI + 0.46, mat("B_Chair", "6E7378", 0.7))
|
||||
for _dx, _dy in ((0.02, 0.02), (0.36, 0.02), (0.02, 0.36), (0.36, 0.36)):
|
||||
box("bath_chair_l_%s" % _dx, 5.45 + _dx, 5.50 + _dx, 6.25 + _dy, 6.30 + _dy, ZI, ZI + 0.42, _wood)
|
||||
|
||||
# коврик и свет
|
||||
box("bath_mat", 4.9, 5.8, 5.95, 7.05, ZI + 0.005, ZI + 0.02, _gmat)
|
||||
box("bath_light", 5.2, 5.9, 7.0, 7.06, ZI + WHI - 0.05, ZI + WHI - 0.01, _lamp)
|
||||
|
||||
# дверь на C1 (в холл)
|
||||
box("bath_door", 5.75, 6.45, _by0 + 0.02, _by0 + 0.08, ZI + 0.02, ZI + 2.05, _white)
|
||||
box("bath_door_stripe", 5.75, 6.45, _by0 + 0.01, _by0 + 0.09, ZI + 1.15, ZI + 1.3, _blackm)
|
||||
print("ванная C собрана по привязкам", flush=True)
|
||||
# три точечных светильника на тёмном потолке
|
||||
for _i, (_lx, _ly) in enumerate(((4.10, 6.30), (5.60, 6.30), (4.10, 7.70))):
|
||||
box("bath_spot_%d" % _i, _lx, _lx + 0.12, _ly, _ly + 0.12, ZI + WHI - 0.10, ZI + WHI - 0.02, _lmp)
|
||||
print("ванная C по проекту", flush=True)
|
||||
# ================= /ВАННАЯ =================
|
||||
|
||||
# UV для текстур интерьера
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
@@ -1,451 +1,486 @@
|
||||
/* Покомнатная панель: подложка-план + обводка комнат мышью (сохранение + экспорт). */
|
||||
const PLAN_W = 916, PLAN_H = 768;
|
||||
/* стартовые контуры (в пикселях подложки), сняты ориентировочно */
|
||||
const START = {
|
||||
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_v2";
|
||||
|
||||
class RoomsCard extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this._areas = [];
|
||||
this._ent2area = {};
|
||||
this._selected = null;
|
||||
this._loaded = false;
|
||||
this._mode = "plan";
|
||||
this._draw = false;
|
||||
this._drawRoom = null;
|
||||
this._tmp = [];
|
||||
this._polys = JSON.parse(JSON.stringify(START));
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(STORE) || "null");
|
||||
if (saved && typeof saved === "object") this._polys = saved;
|
||||
} catch (e) { /* ignore */ }
|
||||
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();
|
||||
// клик по дому — показываем план этой комнаты
|
||||
window.setTimeout(() => {
|
||||
const w = this.shadowRoot.querySelector(".plan-wrap");
|
||||
if (w && w.scrollIntoView) w.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
}, 60);
|
||||
};
|
||||
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;
|
||||
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
|
||||
else if (!this._busy) 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();
|
||||
}
|
||||
|
||||
_roomList() {
|
||||
const names = {
|
||||
terrasa: "Терраса", kitchen: "Кухня-гостиная", postirochnaia: "Тех.пом.",
|
||||
sanuzel: "Санузел", tualet: "Туалет", garderob: "Гардероб", kladovaia: "Кладовая",
|
||||
koridor: "Холл", prihozhaya: "Прихожая", tambur: "Тамбур",
|
||||
kabinet: "Спальня", danina_komnata: "Кабинет",
|
||||
spalnia: "Данина комната", 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) => {
|
||||
const st = this._hass.states[e];
|
||||
return (this._domain(e) === "light" || this._domain(e) === "switch") && st.state === "on";
|
||||
}).length;
|
||||
}
|
||||
_sensors(id) {
|
||||
const out = [];
|
||||
for (const e of this._entitiesOf(id)) {
|
||||
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 });
|
||||
}
|
||||
|
||||
_wallsSvg() {
|
||||
const seen = {};
|
||||
const out = [];
|
||||
for (const r of ROOMS) {
|
||||
const poly = this._polys[ROOMS.indexOf(r)] || r.poly;
|
||||
for (let i = 0; i < poly.length; i++) {
|
||||
const a = poly[i];
|
||||
const b = poly[(i + 1) % poly.length];
|
||||
const k1 = a[0] + "," + a[1] + "-" + b[0] + "," + b[1];
|
||||
const k2 = b[0] + "," + b[1] + "-" + a[0] + "," + a[1];
|
||||
if (seen[k1] || seen[k2]) continue;
|
||||
seen[k1] = true;
|
||||
out.push(`<line class="wall" x1="${a[0]}" y1="${a[1]}" x2="${b[0]}" y2="${b[1]}"/>`);
|
||||
}
|
||||
}
|
||||
return out.join("");
|
||||
}
|
||||
|
||||
_planSvg(areaId) {
|
||||
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 += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}"
|
||||
points="${poly.map(([x, y]) => `${x},${y}`).join(" ")}"><title>${r.name}</title></polygon>`;
|
||||
// на подложке уже есть подписи — свои не рисуем, только подсказку
|
||||
|
||||
}
|
||||
if (this._tmp.length) {
|
||||
tmp = `<polyline class="tmp" points="${this._tmp.map(([x, y]) => `${x},${y}`).join(" ")}"/>`;
|
||||
this._tmp.forEach(([x, y]) => {
|
||||
tmp += `<circle class="tmpdot" cx="${x}" cy="${y}" r="4"/>`;
|
||||
});
|
||||
}
|
||||
return `<div class="plan-wrap">
|
||||
<svg class="plan" viewBox="170 100 640 510" preserveAspectRatio="xMidYMid meet">
|
||||
${shapes}${labels}${tmp}
|
||||
</svg></div>`;
|
||||
}
|
||||
|
||||
_bindDraw() {
|
||||
const svg = this.shadowRoot.querySelector("svg.layer");
|
||||
if (!svg) return;
|
||||
svg.addEventListener("click", (ev) => {
|
||||
if (!this._draw) return;
|
||||
const pt = svg.createSVGPoint();
|
||||
pt.x = ev.clientX; pt.y = ev.clientY;
|
||||
const loc = pt.matrixTransform(svg.getScreenCTM().inverse());
|
||||
this._tmp.push([Math.round(loc.x), Math.round(loc.y)]);
|
||||
this._render();
|
||||
});
|
||||
}
|
||||
|
||||
_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 `<div class="row"><span class="nm">${nm}</span>
|
||||
<input class="br" type="range" min="1" max="100" value="${pct || 100}" data-br="${e}" ${on ? "" : "disabled"}/>
|
||||
<span class="sw ${on ? "on" : ""}" data-e="${e}">${on ? "вкл" : "выкл"}</span></div>`;
|
||||
}
|
||||
if (dom === "climate") {
|
||||
const cur = st.attributes.current_temperature;
|
||||
const tgt = st.attributes.temperature;
|
||||
return `<div class="row"><span class="nm">${nm}</span>
|
||||
<span class="vl">${cur !== undefined ? cur + "°" : ""} → ${tgt !== undefined ? tgt + "°" : ""}</span>
|
||||
<span class="btn" data-clim="${e}" data-d="-0.5">−</span>
|
||||
<span class="btn" data-clim="${e}" data-d="0.5">+</span></div>`;
|
||||
}
|
||||
if (dom === "media_player") {
|
||||
const playing = st.state === "playing";
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
||||
<span class="btn" data-media="${e}">${playing ? "⏸" : "▶"}</span></div>`;
|
||||
}
|
||||
if (dom === "cover") {
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
||||
<span class="btn" data-cover="${e}" data-a="open_cover">↑</span>
|
||||
<span class="btn" data-cover="${e}" data-a="stop_cover">■</span>
|
||||
<span class="btn" data-cover="${e}" data-a="close_cover">↓</span></div>`;
|
||||
}
|
||||
const val = st.state + (st.attributes.unit_of_measurement || "");
|
||||
const act = dom === "switch"
|
||||
? `<span class="sw ${on ? "on" : ""}" data-e="${e}">${on ? "вкл" : "выкл"}</span>` : "";
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${val}</span>${act}</div>`;
|
||||
}
|
||||
|
||||
_render() {
|
||||
if (!this._hass) return;
|
||||
const areaId = this._selected;
|
||||
const tiles = this._roomList().map((r) => {
|
||||
const ens = this._entitiesOf(r.id);
|
||||
const on = this._on(r.id);
|
||||
const sensors = this._sensors(r.id).join(" · ");
|
||||
return `<button class="tile ${r.id === areaId ? "sel" : ""}" data-a="${r.id}">
|
||||
<div class="tile-top"><ha-icon icon="mdi:floor-plan"></ha-icon><span class="cnt">${ens.length}</span></div>
|
||||
<div class="tile-name">${r.name}</div>
|
||||
${on ? `<div class="tile-meta">💡 ${on}</div>` : ""}
|
||||
${sensors ? `<div class="tile-sens">${sensors}</div>` : ""}</button>`;
|
||||
}).join("");
|
||||
|
||||
const list = this._roomList();
|
||||
const jsonStr = this._jsonPx();
|
||||
const drawBar = this._draw ? `<div class="drawbar">
|
||||
<select class="sel">${list.map((r) => `<option value="${r.id}" ${r.id === this._drawRoom ? "selected" : ""}>${r.name}</option>`).join("")}</select>
|
||||
<span class="hint">кликайте по углам комнаты на плане (${this._tmp.length} точек)</span>
|
||||
<button data-act="finish" ${this._tmp.length < 3 ? "disabled" : ""}>Готово</button>
|
||||
<button data-act="cancel">Отмена</button>
|
||||
<button data-act="clear">Очистить комнату</button>
|
||||
<button data-act="copy">Скопировать</button>
|
||||
<button data-act="download">Скачать JSON</button>
|
||||
</div>
|
||||
<textarea class="json" readonly rows="3">${jsonStr}</textarea>
|
||||
<div class="hint">если «Скопировать» не сработало — нажмите в поле и Ctrl+A, Ctrl+C, или скачайте файл</div>` : "";
|
||||
|
||||
let detail = "";
|
||||
if (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) => this._entityRow(e, dom)).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">${(list.find((r) => r.id === areaId) || {}).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; flex-wrap:wrap; }
|
||||
.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:#0f151c; }
|
||||
.plan { display:block; width:100%; height:auto; }
|
||||
.layer { position:absolute; inset:0; width:100%; height:100%; cursor:crosshair; }
|
||||
.zone { fill:rgba(47,127,224,0.10); stroke:rgba(47,127,224,0.75); stroke-width:2; cursor:pointer; }
|
||||
.zone:hover { fill:rgba(47,127,224,0.25); }
|
||||
.zone.sel { fill:rgba(47,127,224,0.32); stroke:#1f6fd0; stroke-width:3; }
|
||||
.lbl { font-size:11px; fill:#123a6b; pointer-events:none; paint-order:stroke; stroke:#ffffff; stroke-width:3px; }
|
||||
.tmp { fill:rgba(255,122,0,0.2); stroke:#ff7a00; stroke-width:2; stroke-dasharray:6 4; }
|
||||
.tmpdot { fill:#ff7a00; stroke:#fff; stroke-width:1.5; }
|
||||
.drawbar { display:flex; gap:8px; align-items:center; margin-top:8px; flex-wrap:wrap; }
|
||||
.drawbar button { background:#243040; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
||||
padding:5px 10px; font-size:12px; cursor:pointer; }
|
||||
.drawbar button[disabled] { opacity:.45; cursor:default; }
|
||||
.drawbar .sel { background:#1a222c; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
||||
padding:5px 8px; font-size:12px; }
|
||||
.hint { font-size:11px; opacity:.65; }
|
||||
.json { width:100%; margin-top:6px; font-family:ui-monospace,monospace; font-size:10px;
|
||||
background:#0f1318; color:#9fd0ff; border:1px solid #26303c; border-radius:8px; }
|
||||
.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:.7; 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; }
|
||||
.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; }
|
||||
</style>
|
||||
<div class="bar">
|
||||
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
|
||||
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
|
||||
<button class="${this._draw ? "on" : ""}" data-draw="1">Обводка комнат</button>
|
||||
</div>
|
||||
${this._mode === "plan" ? this._planSvg(areaId) + drawBar : `<div class="grid">${tiles}</div>`}
|
||||
${detail}`;
|
||||
|
||||
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>
|
||||
b.addEventListener("click", () => { this._mode = b.dataset.mode; this._render(); }));
|
||||
const db = this.shadowRoot.querySelector("[data-draw]");
|
||||
if (db) db.addEventListener("click", () => {
|
||||
this._draw = !this._draw;
|
||||
this._tmp = [];
|
||||
this._drawRoom = this._drawRoom || "terrasa";
|
||||
this._render();
|
||||
});
|
||||
if (this._mode === "plan") {
|
||||
this.shadowRoot.querySelectorAll(".zone").forEach((el) =>
|
||||
el.addEventListener("click", (ev) => {
|
||||
if (this._draw) { return; }
|
||||
this._selected = this._selected === el.dataset.a ? null : el.dataset.a;
|
||||
this._render();
|
||||
}));
|
||||
if (this._draw) this._bindDraw();
|
||||
}
|
||||
const sel = this.shadowRoot.querySelector(".sel");
|
||||
if (sel) sel.addEventListener("change", () => { this._drawRoom = sel.value; this._tmp = []; this._render(); });
|
||||
const finish = this.shadowRoot.querySelector("[data-act=finish]");
|
||||
if (finish) finish.addEventListener("click", () => {
|
||||
if (this._tmp.length >= 3 && this._drawRoom) {
|
||||
this._polys[this._drawRoom] = this._tmp.slice();
|
||||
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
||||
}
|
||||
this._tmp = [];
|
||||
this._render();
|
||||
});
|
||||
const cancel = this.shadowRoot.querySelector("[data-act=cancel]");
|
||||
if (cancel) cancel.addEventListener("click", () => { this._tmp = []; this._render(); });
|
||||
const clear = this.shadowRoot.querySelector("[data-act=clear]");
|
||||
if (clear) clear.addEventListener("click", () => {
|
||||
delete this._polys[this._drawRoom];
|
||||
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
||||
this._tmp = [];
|
||||
this._render();
|
||||
});
|
||||
const copy = this.shadowRoot.querySelector("[data-act=copy]");
|
||||
if (copy) copy.addEventListener("click", async () => {
|
||||
const txt = this._jsonPx();
|
||||
let ok = false;
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(txt);
|
||||
ok = true;
|
||||
}
|
||||
} catch (e) { ok = false; }
|
||||
if (!ok) {
|
||||
try {
|
||||
const ta = this.shadowRoot.querySelector(".json");
|
||||
ta.focus(); ta.select();
|
||||
ok = document.execCommand("copy");
|
||||
} catch (e) { ok = false; }
|
||||
}
|
||||
copy.textContent = ok ? "Скопировано ✓" : "Выделите поле и Ctrl+C";
|
||||
});
|
||||
const dl = this.shadowRoot.querySelector("[data-act=download]");
|
||||
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;
|
||||
window.setTimeout(() => { const w = this.shadowRoot.querySelector('.plan-wrap'); if (w && w.scrollIntoView) w.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 50);
|
||||
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(); });
|
||||
}
|
||||
|
||||
_jsonPx() {
|
||||
try { return JSON.stringify(this._polys); } catch (e) { return "{}"; }
|
||||
}
|
||||
|
||||
_download() {
|
||||
try {
|
||||
const blob = new Blob([this._jsonPx()], { type: "application/json" });
|
||||
const a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = "room-zones.json";
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
getCardSize() { return 14; }
|
||||
}
|
||||
|
||||
customElements.define("rooms-card", RoomsCard);
|
||||
/* Покомнатная панель: подложка-план + обводка комнат мышью (сохранение + экспорт). */
|
||||
const PLAN_W = 916, PLAN_H = 768;
|
||||
/* стартовые контуры (в пикселях подложки), сняты ориентировочно */
|
||||
const START = {
|
||||
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_v2";
|
||||
|
||||
class RoomsCard extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this._areas = [];
|
||||
this._ent2area = {};
|
||||
this._selected = null;
|
||||
this._loaded = false;
|
||||
this._mode = "plan";
|
||||
this._draw = false;
|
||||
this._drawRoom = null;
|
||||
this._tmp = [];
|
||||
this._polys = JSON.parse(JSON.stringify(START));
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(STORE) || "null");
|
||||
if (saved && typeof saved === "object") this._polys = saved;
|
||||
} catch (e) { /* ignore */ }
|
||||
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();
|
||||
// клик по дому — показываем план этой комнаты
|
||||
window.setTimeout(() => {
|
||||
const w = this.shadowRoot.querySelector(".plan-wrap");
|
||||
if (w && w.scrollIntoView) w.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
}, 60);
|
||||
};
|
||||
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;
|
||||
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
|
||||
else if (!this._busy) 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();
|
||||
}
|
||||
|
||||
_roomList() {
|
||||
const names = {
|
||||
terrasa: "Терраса", kitchen: "Кухня-гостиная", postirochnaia: "Тех.пом.",
|
||||
sanuzel: "Санузел", tualet: "Туалет", garderob: "Гардероб", kladovaia: "Кладовая",
|
||||
koridor: "Холл", prihozhaya: "Прихожая", tambur: "Тамбур",
|
||||
kabinet: "Спальня", danina_komnata: "Кабинет",
|
||||
spalnia: "Данина комната", 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) => {
|
||||
const st = this._hass.states[e];
|
||||
return (this._domain(e) === "light" || this._domain(e) === "switch") && st.state === "on";
|
||||
}).length;
|
||||
}
|
||||
_sensors(id) {
|
||||
const out = [];
|
||||
for (const e of this._entitiesOf(id)) {
|
||||
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 });
|
||||
}
|
||||
|
||||
_wallsSvg() {
|
||||
const seen = {};
|
||||
const out = [];
|
||||
for (const r of ROOMS) {
|
||||
const poly = this._polys[ROOMS.indexOf(r)] || r.poly;
|
||||
for (let i = 0; i < poly.length; i++) {
|
||||
const a = poly[i];
|
||||
const b = poly[(i + 1) % poly.length];
|
||||
const k1 = a[0] + "," + a[1] + "-" + b[0] + "," + b[1];
|
||||
const k2 = b[0] + "," + b[1] + "-" + a[0] + "," + a[1];
|
||||
if (seen[k1] || seen[k2]) continue;
|
||||
seen[k1] = true;
|
||||
out.push(`<line class="wall" x1="${a[0]}" y1="${a[1]}" x2="${b[0]}" y2="${b[1]}"/>`);
|
||||
}
|
||||
}
|
||||
return out.join("");
|
||||
}
|
||||
|
||||
_planSvg(areaId) {
|
||||
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 += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}"
|
||||
points="${poly.map(([x, y]) => `${x},${y}`).join(" ")}"><title>${r.name}</title></polygon>`;
|
||||
// на подложке уже есть подписи — свои не рисуем, только подсказку
|
||||
|
||||
}
|
||||
if (this._tmp.length) {
|
||||
tmp = `<polyline class="tmp" points="${this._tmp.map(([x, y]) => `${x},${y}`).join(" ")}"/>`;
|
||||
this._tmp.forEach(([x, y]) => {
|
||||
tmp += `<circle class="tmpdot" cx="${x}" cy="${y}" r="4"/>`;
|
||||
});
|
||||
}
|
||||
return `<div class="plan-wrap">
|
||||
<svg class="plan" viewBox="170 100 640 510" preserveAspectRatio="xMidYMid meet">
|
||||
${shapes}${labels}${tmp}
|
||||
</svg></div>`;
|
||||
}
|
||||
|
||||
_bindDraw() {
|
||||
const svg = this.shadowRoot.querySelector("svg.layer");
|
||||
if (!svg) return;
|
||||
svg.addEventListener("click", (ev) => {
|
||||
if (!this._draw) return;
|
||||
const pt = svg.createSVGPoint();
|
||||
pt.x = ev.clientX; pt.y = ev.clientY;
|
||||
const loc = pt.matrixTransform(svg.getScreenCTM().inverse());
|
||||
this._tmp.push([Math.round(loc.x), Math.round(loc.y)]);
|
||||
this._render();
|
||||
});
|
||||
}
|
||||
|
||||
_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 `<div class="row"><span class="nm">${nm}</span>
|
||||
<input class="br" type="range" min="1" max="100" value="${pct || 100}" data-br="${e}" ${on ? "" : "disabled"}/>
|
||||
<span class="sw ${on ? "on" : ""}" data-e="${e}">${on ? "вкл" : "выкл"}</span></div>`;
|
||||
}
|
||||
if (dom === "climate") {
|
||||
const cur = st.attributes.current_temperature;
|
||||
const tgt = st.attributes.temperature;
|
||||
return `<div class="row"><span class="nm">${nm}</span>
|
||||
<span class="vl">${cur !== undefined ? cur + "°" : ""} → ${tgt !== undefined ? tgt + "°" : ""}</span>
|
||||
<span class="btn" data-clim="${e}" data-d="-0.5">−</span>
|
||||
<span class="btn" data-clim="${e}" data-d="0.5">+</span></div>`;
|
||||
}
|
||||
if (dom === "media_player") {
|
||||
const playing = st.state === "playing";
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
||||
<span class="btn" data-media="${e}">${playing ? "⏸" : "▶"}</span></div>`;
|
||||
}
|
||||
if (dom === "cover") {
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
||||
<span class="btn" data-cover="${e}" data-a="open_cover">↑</span>
|
||||
<span class="btn" data-cover="${e}" data-a="stop_cover">■</span>
|
||||
<span class="btn" data-cover="${e}" data-a="close_cover">↓</span></div>`;
|
||||
}
|
||||
const val = st.state + (st.attributes.unit_of_measurement || "");
|
||||
const act = dom === "switch"
|
||||
? `<span class="sw ${on ? "on" : ""}" data-e="${e}">${on ? "вкл" : "выкл"}</span>` : "";
|
||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${val}</span>${act}</div>`;
|
||||
}
|
||||
|
||||
_render() {
|
||||
if (!this._hass) return;
|
||||
const areaId = this._selected;
|
||||
const tiles = this._roomList().map((r) => {
|
||||
const ens = this._entitiesOf(r.id);
|
||||
const on = this._on(r.id);
|
||||
const sensors = this._sensors(r.id).join(" · ");
|
||||
return `<button class="tile ${r.id === areaId ? "sel" : ""}" data-a="${r.id}">
|
||||
<div class="tile-top"><ha-icon icon="mdi:floor-plan"></ha-icon><span class="cnt">${ens.length}</span></div>
|
||||
<div class="tile-name">${r.name}</div>
|
||||
${on ? `<div class="tile-meta">💡 ${on}</div>` : ""}
|
||||
${sensors ? `<div class="tile-sens">${sensors}</div>` : ""}</button>`;
|
||||
}).join("");
|
||||
|
||||
const list = this._roomList();
|
||||
const jsonStr = this._jsonPx();
|
||||
const drawBar = this._draw ? `<div class="drawbar">
|
||||
<select class="sel">${list.map((r) => `<option value="${r.id}" ${r.id === this._drawRoom ? "selected" : ""}>${r.name}</option>`).join("")}</select>
|
||||
<span class="hint">кликайте по углам комнаты на плане (${this._tmp.length} точек)</span>
|
||||
<button data-act="finish" ${this._tmp.length < 3 ? "disabled" : ""}>Готово</button>
|
||||
<button data-act="cancel">Отмена</button>
|
||||
<button data-act="clear">Очистить комнату</button>
|
||||
<button data-act="copy">Скопировать</button>
|
||||
<button data-act="download">Скачать JSON</button>
|
||||
</div>
|
||||
<textarea class="json" readonly rows="3">${jsonStr}</textarea>
|
||||
<div class="hint">если «Скопировать» не сработало — нажмите в поле и Ctrl+A, Ctrl+C, или скачайте файл</div>` : "";
|
||||
|
||||
let detail = "";
|
||||
if (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) => this._entityRow(e, dom)).join("");
|
||||
return `<div class="grp"><div class="grp-h">${dom} · ${groups[dom].length}</div>${items}</div>`;
|
||||
}).join("");
|
||||
// пассивная информация: температура, влажность и прочие датчики
|
||||
const passive = ens.filter((e) => /^(sensor|binary_sensor)\./.test(e));
|
||||
const rank = (e) => {
|
||||
const d = (this._hass.states[e] || {}).attributes.device_class || "";
|
||||
if (d === "temperature") return 0;
|
||||
if (d === "humidity") return 1;
|
||||
if (/^(sensor)\./.test(e)) return 2;
|
||||
return 3;
|
||||
};
|
||||
passive.sort((a, b) => rank(a) - rank(b));
|
||||
const metric = (e) => {
|
||||
const st = this._hass.states[e];
|
||||
if (!st) return "";
|
||||
const u = st.attributes.unit_of_measurement || "";
|
||||
const nm = (st.attributes.friendly_name || e).replace(/^.*?: /, "");
|
||||
const val = st.state;
|
||||
return `<div class="mt"><div class="mv">${val}${u ? " " + u : ""}</div><div class="mn">${nm}</div></div>`;
|
||||
};
|
||||
const metrics = passive.length
|
||||
? `<div class="metrics">${passive.slice(0, 8).map(metric).join("")}</div>`
|
||||
: `<div class="metrics empty">Датчиков температуры/влажности в этой комнате пока нет</div>`;
|
||||
const photoKey = { sanuzel: "sanuzel" }[areaId] || null;
|
||||
const photos = photoKey
|
||||
? [1, 2, 3].map((n) => `<img class="room-photo" src="/local/house3d/rooms/${photoKey}-${n}.png?v=1"
|
||||
onerror="this.style.display='none'">`).join("")
|
||||
: "";
|
||||
detail = `<div class="detail"><div class="d-head">${(list.find((r) => r.id === areaId) || {}).name || areaId}
|
||||
<button class="close" data-close="1">×</button></div>
|
||||
${photos ? `<div class="photos">${photos}</div>` : ""}${metrics}
|
||||
${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; flex-wrap:wrap; }
|
||||
.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:#0f151c; }
|
||||
.plan { display:block; width:100%; height:auto; }
|
||||
.layer { position:absolute; inset:0; width:100%; height:100%; cursor:crosshair; }
|
||||
.zone { fill:rgba(47,127,224,0.10); stroke:rgba(47,127,224,0.75); stroke-width:2; cursor:pointer; }
|
||||
.zone:hover { fill:rgba(47,127,224,0.25); }
|
||||
.zone.sel { fill:rgba(47,127,224,0.32); stroke:#1f6fd0; stroke-width:3; }
|
||||
.lbl { font-size:11px; fill:#123a6b; pointer-events:none; paint-order:stroke; stroke:#ffffff; stroke-width:3px; }
|
||||
.tmp { fill:rgba(255,122,0,0.2); stroke:#ff7a00; stroke-width:2; stroke-dasharray:6 4; }
|
||||
.tmpdot { fill:#ff7a00; stroke:#fff; stroke-width:1.5; }
|
||||
.drawbar { display:flex; gap:8px; align-items:center; margin-top:8px; flex-wrap:wrap; }
|
||||
.drawbar button { background:#243040; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
||||
padding:5px 10px; font-size:12px; cursor:pointer; }
|
||||
.drawbar button[disabled] { opacity:.45; cursor:default; }
|
||||
.drawbar .sel { background:#1a222c; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
||||
padding:5px 8px; font-size:12px; }
|
||||
.hint { font-size:11px; opacity:.65; }
|
||||
.json { width:100%; margin-top:6px; font-family:ui-monospace,monospace; font-size:10px;
|
||||
background:#0f1318; color:#9fd0ff; border:1px solid #26303c; border-radius:8px; }
|
||||
.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:.7; margin-top:2px; }
|
||||
.tile-sens { font-size:11px; opacity:.85; margin-top:6px; color:#9ed3ff; }
|
||||
.metrics { display:flex; flex-wrap:wrap; gap:8px; margin:8px 0 10px; }
|
||||
.mt { min-width:92px; padding:8px 12px; border-radius:12px; background:#141c25; border:1px solid #22303d; }
|
||||
.mv { font-size:20px; font-weight:700; color:#dceaff; }
|
||||
.mn { font-size:11px; color:#7f93a8; margin-top:2px; }
|
||||
.metrics.empty { color:#7f93a8; font-size:12px; }
|
||||
.photos { display:flex; gap:8px; overflow-x:auto; margin:6px 0 10px; }
|
||||
.room-photo { height:150px; border-radius:10px; border:1px solid #2a2f36; flex:0 0 auto; }
|
||||
.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; }
|
||||
.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; }
|
||||
</style>
|
||||
<div class="bar">
|
||||
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
|
||||
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
|
||||
<button class="${this._draw ? "on" : ""}" data-draw="1">Обводка комнат</button>
|
||||
</div>
|
||||
${this._mode === "plan" ? this._planSvg(areaId) + drawBar : `<div class="grid">${tiles}</div>`}
|
||||
${detail}`;
|
||||
|
||||
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>
|
||||
b.addEventListener("click", () => { this._mode = b.dataset.mode; this._render(); }));
|
||||
const db = this.shadowRoot.querySelector("[data-draw]");
|
||||
if (db) db.addEventListener("click", () => {
|
||||
this._draw = !this._draw;
|
||||
this._tmp = [];
|
||||
this._drawRoom = this._drawRoom || "terrasa";
|
||||
this._render();
|
||||
});
|
||||
if (this._mode === "plan") {
|
||||
this.shadowRoot.querySelectorAll(".zone").forEach((el) =>
|
||||
el.addEventListener("click", (ev) => {
|
||||
if (this._draw) { return; }
|
||||
this._selected = this._selected === el.dataset.a ? null : el.dataset.a;
|
||||
this._render();
|
||||
}));
|
||||
if (this._draw) this._bindDraw();
|
||||
}
|
||||
const sel = this.shadowRoot.querySelector(".sel");
|
||||
if (sel) sel.addEventListener("change", () => { this._drawRoom = sel.value; this._tmp = []; this._render(); });
|
||||
const finish = this.shadowRoot.querySelector("[data-act=finish]");
|
||||
if (finish) finish.addEventListener("click", () => {
|
||||
if (this._tmp.length >= 3 && this._drawRoom) {
|
||||
this._polys[this._drawRoom] = this._tmp.slice();
|
||||
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
||||
}
|
||||
this._tmp = [];
|
||||
this._render();
|
||||
});
|
||||
const cancel = this.shadowRoot.querySelector("[data-act=cancel]");
|
||||
if (cancel) cancel.addEventListener("click", () => { this._tmp = []; this._render(); });
|
||||
const clear = this.shadowRoot.querySelector("[data-act=clear]");
|
||||
if (clear) clear.addEventListener("click", () => {
|
||||
delete this._polys[this._drawRoom];
|
||||
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
||||
this._tmp = [];
|
||||
this._render();
|
||||
});
|
||||
const copy = this.shadowRoot.querySelector("[data-act=copy]");
|
||||
if (copy) copy.addEventListener("click", async () => {
|
||||
const txt = this._jsonPx();
|
||||
let ok = false;
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(txt);
|
||||
ok = true;
|
||||
}
|
||||
} catch (e) { ok = false; }
|
||||
if (!ok) {
|
||||
try {
|
||||
const ta = this.shadowRoot.querySelector(".json");
|
||||
ta.focus(); ta.select();
|
||||
ok = document.execCommand("copy");
|
||||
} catch (e) { ok = false; }
|
||||
}
|
||||
copy.textContent = ok ? "Скопировано ✓" : "Выделите поле и Ctrl+C";
|
||||
});
|
||||
const dl = this.shadowRoot.querySelector("[data-act=download]");
|
||||
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;
|
||||
window.setTimeout(() => { const w = this.shadowRoot.querySelector('.plan-wrap'); if (w && w.scrollIntoView) w.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 50);
|
||||
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(); });
|
||||
}
|
||||
|
||||
_jsonPx() {
|
||||
try { return JSON.stringify(this._polys); } catch (e) { return "{}"; }
|
||||
}
|
||||
|
||||
_download() {
|
||||
try {
|
||||
const blob = new Blob([this._jsonPx()], { type: "application/json" });
|
||||
const a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = "room-zones.json";
|
||||
a.click();
|
||||
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
getCardSize() { return 14; }
|
||||
}
|
||||
|
||||
customElements.define("rooms-card", RoomsCard);
|
||||