[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))
|
min(_ay, _by), max(_ay, _by), ZI, ZI + WHI, I_WALL.get(_rid, _wlight))
|
||||||
|
|
||||||
|
|
||||||
# ================= ВАННАЯ C (по привязкам владельца) =================
|
# ================= ВАННАЯ C (по проекту владельца) =================
|
||||||
# C1 — дверь, C3 — робот, C4 — ванна (дерево), C6 — окно, C7 — раковина и шкафы
|
|
||||||
_bw = mat_tex("B_Wood", os.path.join(TDIR, "tex_bath_wood.png"), 0.35)
|
_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)
|
_bd = mat_tex("B_Dark", os.path.join(TDIR, "tex_bath_dark.png"), 0.4)
|
||||||
_white2 = mat("B_White", "F4F4F0", 0.25)
|
_wh = mat("B_White", "F4F4F0", 0.25)
|
||||||
_chrome = mat("B_Chrome", "B9C0C6", 0.25, 0.9)
|
_chr = mat("B_Chrome", "B9C0C6", 0.25, 0.9)
|
||||||
_blackm = mat("B_Black", "16181A", 0.35, 0.6)
|
_blk = mat("B_Black", "16181A", 0.35, 0.6)
|
||||||
_bwood = mat("B_WoodCab", "8B5E3C", 0.45)
|
_wood = mat("B_WoodCab", "8B5E3C", 0.45)
|
||||||
_bstone = mat("B_Stone", "6E7679", 0.4)
|
_st = mat("B_Stone", "6E7679", 0.4)
|
||||||
_gmat = mat("B_Mat", "C8B49A", 0.9)
|
_ceil = mat("B_Ceil", "3A3E42", 0.8)
|
||||||
|
_lmp = mat("B_Spot", "F3F0E6", 0.3)
|
||||||
|
|
||||||
# контур: L-образный (низ широкий, верх — узкая часть у окна)
|
|
||||||
_bx0, _bx1 = 3.38, 6.55
|
_bx0, _bx1 = 3.38, 6.55
|
||||||
_by0, _by1 = 5.68, 8.60
|
_by0, _by1 = 5.68, 8.60
|
||||||
_nw = 5.15 # западная граница верхней части
|
_nw, _ny = 5.15, 7.25
|
||||||
_ny = 7.25 # северная граница нижней части
|
# потолок тёмный
|
||||||
|
|
||||||
_floor_poly("bath_floor", ROOMS_M["sanuzel"], ZI - 0.015, 0.03, mat("B_FloorDark", "23262A", 0.55))
|
_zf = bpy.data.objects.get("zone_sanuzel")
|
||||||
|
if _zf:
|
||||||
# стены: дерево — C4 (север нижней части) и C5 (запад верхней), остальное тёмное
|
_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_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_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_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_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.10, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||||
box("bath_c1a", 4.67, 5.75, _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.45, _bx1, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
box("bath_c1b", 6.00, _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_c2", _bx0, 4.67, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
box("bath_c2", _bx0, 4.67, _by0, _by0 + 0.03, ZI, ZI + WHI, _bd)
|
||||||
|
|
||||||
# окно на C6
|
# окно на C6
|
||||||
box("bath_win", 5.45, 6.25, _by1 - 0.05, _by1 + 0.01, ZI + 1.35, ZI + 2.05, _chrome)
|
box("bath_win", 5.45, 6.25, _by1 - 0.05, _by1 - 0.01, ZI + 1.30, ZI + 2.00, _wh)
|
||||||
box("bath_win_glass", 5.5, 6.2, _by1 - 0.03, _by1 - 0.01, ZI + 1.4, ZI + 2.0,
|
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))
|
||||||
mat("B_WinGlass", "C9D4DA", 0.1))
|
|
||||||
|
|
||||||
# ВАННА на C4 (дерево), вдоль стены
|
# ВАННА вдоль C4: тёмный подвесной фронт, белая чаша
|
||||||
_tx0, _tx1 = _bx0 + 0.1, _nw - 0.1
|
_tx0, _tx1 = _bx0 + 0.12, _nw - 0.10
|
||||||
_ty0, _ty1 = _ny - 0.82, _ny - 0.07
|
_ty0, _ty1 = _ny - 0.80, _ny - 0.06
|
||||||
box("bath_tub", _tx0, _tx1, _ty0, _ty1, ZI + 0.02, ZI + 0.58, _white2)
|
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,
|
box("bath_tub_in", _tx0 + 0.09, _tx1 - 0.09, _ty0 + 0.09, _ty1 - 0.09, ZI + 0.28, ZI + 0.62, _st)
|
||||||
ZI + 0.3, ZI + 0.62, _bd)
|
box("bath_tub_front", _tx0, _tx1, _ty0 - 0.05, _ty0, ZI, ZI + 0.62, mat("B_TubPanel", "4A4E52", 0.5))
|
||||||
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)
|
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 (по фото, без кабины)
|
# ДУШ: стойка на C3 над ванной
|
||||||
box("bath_shaft", _bx0 + 0.05, _bx0 + 0.09, 7.00, 7.04, ZI + 0.6, ZI + 2.2, _blackm)
|
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.42, 6.99, 7.07, ZI + 2.1, ZI + 2.14, _blackm)
|
box("bath_rain", _bx0 + 0.05, _bx0 + 0.45, _ny - 0.24, _ny - 0.16, ZI + 2.05, ZI + 2.09, _blk)
|
||||||
box("bath_shower_mix", _bx0 + 0.05, _bx0 + 0.13, 7.05, 7.18, ZI + 1.0, ZI + 1.08, _blackm)
|
box("bath_mix", _bx0 + 0.05, _bx0 + 0.13, _ny - 0.17, _ny - 0.04, ZI + 1.05, ZI + 1.13, _blk)
|
||||||
|
|
||||||
# РАКОВИНА и шкафы на C7
|
# УНИТАЗ на C7 у северного угла + деревянные полки рядом
|
||||||
_vx0, _vx1 = _bx1 - 0.55, _bx1 - 0.06
|
box("bath_wc", 6.02, 6.42, 8.05, 8.50, ZI + 0.28, ZI + 0.70, _wh)
|
||||||
_vy0, _vy1 = 5.95, 6.85
|
box("bath_wc_panel", 6.45, _bx1 - 0.03, 7.95, 8.52, ZI + 0.2, ZI + 1.05, _wood)
|
||||||
box("bath_van", _vx0, _vx1, _vy0, _vy1, ZI + 0.32, ZI + 0.8, _bwood)
|
for _i, _z in enumerate((1.2, 1.6, 2.0)):
|
||||||
box("bath_vtop", _vx0 - 0.02, _vx1 + 0.02, _vy0 - 0.02, _vy1 + 0.02, ZI + 0.8, ZI + 0.84, _bstone)
|
box("bath_cub_%d" % _i, 6.10, 6.45, 7.40, 7.90, ZI + _z, ZI + _z + 0.04, _wood)
|
||||||
box("bath_sink", _vx0 + 0.07, _vx1 - 0.07, _vy0 + 0.16, _vy1 - 0.16, ZI + 0.84, ZI + 0.98, _white2)
|
box("bath_cub_side", 6.10, 6.14, 7.40, 7.90, ZI + 1.15, ZI + 2.04, _wood)
|
||||||
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)
|
|
||||||
|
|
||||||
# УНИТАЗ у окна (на C6)
|
# ТУМБА + накладная раковина + подсвеченное зеркало на C7
|
||||||
box("bath_wc", 5.86, 6.26, 8.00, 8.45, ZI, ZI + 0.38, _white2)
|
_vx0, _vx1 = 6.05, 6.52
|
||||||
box("bath_wc_t", 5.88, 6.24, 8.02, 8.43, ZI + 0.38, ZI + 0.41, _white2)
|
_vy0, _vy1 = 6.15, 7.05
|
||||||
box("bath_wc_panel", 5.86, 6.26, _by1 - 0.09, _by1 - 0.03, ZI + 0.3, ZI + 0.95, _bwood)
|
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
|
# ДВЕРЬ на C1 + полотенцесушитель рядом
|
||||||
box("bath_shelf", 3.65, 4.25, _ny - 0.32, _ny - 0.05, ZI + 1.35, ZI + 1.39, _blackm)
|
box("bath_door", 5.10, 6.00, _by0 + 0.02, _by0 + 0.08, ZI + 0.02, ZI + 2.05, _wh)
|
||||||
box("bath_towel1", 3.68, 4.22, _ny - 0.3, _ny - 0.08, ZI + 1.39, ZI + 1.55, _blackm)
|
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))
|
||||||
box("bath_towel2", 3.68, 4.22, _ny - 0.3, _ny - 0.08, ZI + 1.55, ZI + 1.7, _bd)
|
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_chair", 5.45, 5.85, 6.25, 6.65, ZI + 0.42, ZI + 0.46, mat("B_Chair", "6E7378", 0.7))
|
||||||
box("bath_robot_d", _bx0 + 0.21, _bx0 + 0.44, 6.51, 6.74, ZI + 0.32, ZI + 0.34, _blackm)
|
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)
|
for _i, (_lx, _ly) in enumerate(((4.10, 6.30), (5.60, 6.30), (4.10, 7.70))):
|
||||||
box("bath_light", 5.2, 5.9, 7.0, 7.06, ZI + WHI - 0.05, ZI + WHI - 0.01, _lamp)
|
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)
|
||||||
# дверь на 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)
|
|
||||||
# ================= /ВАННАЯ =================
|
# ================= /ВАННАЯ =================
|
||||||
|
|
||||||
# UV для текстур интерьера
|
# 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 PLAN_W = 916, PLAN_H = 768;
|
||||||
/* стартовые контуры (в пикселях подложки), сняты ориентировочно */
|
/* стартовые контуры (в пикселях подложки), сняты ориентировочно */
|
||||||
const START = {
|
const START = {
|
||||||
terrasa: [[180,173],[283,173],[283,524],[180,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]],
|
kitchen: [[291,173],[425,173],[425,294],[441,294],[441,348],[441,524],[291,524]],
|
||||||
postirochnaia: [[425,114],[499,114],[499,229],[425,229]],
|
postirochnaia: [[425,114],[499,114],[499,229],[425,229]],
|
||||||
sanuzel: [[499,173],[499,229],[425,229],[425,294],[479,294],[558,294],[558,173]],
|
sanuzel: [[499,173],[499,229],[425,229],[425,294],[479,294],[558,294],[558,173]],
|
||||||
tualet: [[558,229],[609,229],[609,294],[558,294]],
|
tualet: [[558,229],[609,229],[609,294],[558,294]],
|
||||||
garderob: [[558,173],[558,229],[656,229],[656,173]],
|
garderob: [[558,173],[558,229],[656,229],[656,173]],
|
||||||
kladovaia: [[609,229],[656,229],[656,294],[609,294]],
|
kladovaia: [[609,229],[656,229],[656,294],[609,294]],
|
||||||
koridor: [[441,294],[441,348],[684,348],[684,294]],
|
koridor: [[441,294],[441,348],[684,348],[684,294]],
|
||||||
prihozhaya: [[441,348],[516,348],[516,442],[441,442]],
|
prihozhaya: [[441,348],[516,348],[516,442],[441,442]],
|
||||||
tambur: [[441,442],[516,442],[516,524],[441,524]],
|
tambur: [[441,442],[516,442],[516,524],[441,524]],
|
||||||
kabinet: [[656,173],[656,294],[684,294],[684,348],[787,348],[787,173],[656,173]],
|
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]],
|
danina_komnata: [[516,348],[633,348],[633,524],[516,524]],
|
||||||
spalnia: [[633,348],[787,348],[787,524],[633,524]],
|
spalnia: [[633,348],[787,348],[787,524],[633,524]],
|
||||||
kryltso: [[441,524],[441,593],[516,593],[516,524]],
|
kryltso: [[441,524],[441,593],[516,593],[516,524]],
|
||||||
};
|
};
|
||||||
const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"];
|
const KEY_DOMAINS = ["light", "switch", "climate", "media_player", "cover", "fan"];
|
||||||
const SENSOR_HINT = /temperature|humidity|co2|illuminance/;
|
const SENSOR_HINT = /temperature|humidity|co2|illuminance/;
|
||||||
const ROOM_TITLES = {
|
const ROOM_TITLES = {
|
||||||
"terrasa": "Терраса",
|
"terrasa": "Терраса",
|
||||||
"kitchen": "Кухня-гостиная",
|
"kitchen": "Кухня-гостиная",
|
||||||
"postirochnaia": "Тех.пом.",
|
"postirochnaia": "Тех.пом.",
|
||||||
"sanuzel": "СУ",
|
"sanuzel": "СУ",
|
||||||
"tualet": "СУ 2",
|
"tualet": "СУ 2",
|
||||||
"garderob": "Гардеробная",
|
"garderob": "Гардеробная",
|
||||||
"kladovaia": "Кладовая",
|
"kladovaia": "Кладовая",
|
||||||
"koridor": "Холл",
|
"koridor": "Холл",
|
||||||
"prihozhaya": "Прихожая",
|
"prihozhaya": "Прихожая",
|
||||||
"tambur": "Тамбур",
|
"tambur": "Тамбур",
|
||||||
"kabinet": "Кабинет",
|
"kabinet": "Кабинет",
|
||||||
"danina_komnata": "Данина комната",
|
"danina_komnata": "Данина комната",
|
||||||
"spalnia": "Спальня",
|
"spalnia": "Спальня",
|
||||||
"kryltso": "Крыльцо"
|
"kryltso": "Крыльцо"
|
||||||
};
|
};
|
||||||
const STORE = "house3d_room_px_v2";
|
const STORE = "house3d_room_px_v2";
|
||||||
|
|
||||||
class RoomsCard extends HTMLElement {
|
class RoomsCard extends HTMLElement {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this._areas = [];
|
this._areas = [];
|
||||||
this._ent2area = {};
|
this._ent2area = {};
|
||||||
this._selected = null;
|
this._selected = null;
|
||||||
this._loaded = false;
|
this._loaded = false;
|
||||||
this._mode = "plan";
|
this._mode = "plan";
|
||||||
this._draw = false;
|
this._draw = false;
|
||||||
this._drawRoom = null;
|
this._drawRoom = null;
|
||||||
this._tmp = [];
|
this._tmp = [];
|
||||||
this._polys = JSON.parse(JSON.stringify(START));
|
this._polys = JSON.parse(JSON.stringify(START));
|
||||||
try {
|
try {
|
||||||
const saved = JSON.parse(localStorage.getItem(STORE) || "null");
|
const saved = JSON.parse(localStorage.getItem(STORE) || "null");
|
||||||
if (saved && typeof saved === "object") this._polys = saved;
|
if (saved && typeof saved === "object") this._polys = saved;
|
||||||
} catch (e) { /* ignore */ }
|
} catch (e) { /* ignore */ }
|
||||||
this.attachShadow({ mode: "open" });
|
this.attachShadow({ mode: "open" });
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
this._on3d = (ev) => {
|
this._on3d = (ev) => {
|
||||||
const room = ev && ev.detail ? ev.detail.room : null;
|
const room = ev && ev.detail ? ev.detail.room : null;
|
||||||
this._selected = room || null;
|
this._selected = room || null;
|
||||||
this._mode = "plan";
|
this._mode = "plan";
|
||||||
this._render();
|
this._render();
|
||||||
// клик по дому — показываем план этой комнаты
|
// клик по дому — показываем план этой комнаты
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
const w = this.shadowRoot.querySelector(".plan-wrap");
|
const w = this.shadowRoot.querySelector(".plan-wrap");
|
||||||
if (w && w.scrollIntoView) w.scrollIntoView({ behavior: "smooth", block: "center" });
|
if (w && w.scrollIntoView) w.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||||
}, 60);
|
}, 60);
|
||||||
};
|
};
|
||||||
document.addEventListener("house3d-room", this._on3d);
|
document.addEventListener("house3d-room", this._on3d);
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnectedCallback() {
|
disconnectedCallback() {
|
||||||
if (this._on3d) document.removeEventListener("house3d-room", this._on3d);
|
if (this._on3d) document.removeEventListener("house3d-room", this._on3d);
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfig(config) { this._config = config || {}; }
|
setConfig(config) { this._config = config || {}; }
|
||||||
set hass(hass) {
|
set hass(hass) {
|
||||||
this._hass = hass;
|
this._hass = hass;
|
||||||
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
|
if (!this._loaded) { this._loaded = true; this._loadRegistries(); }
|
||||||
else if (!this._busy) this._render();
|
else if (!this._busy) this._render();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _loadRegistries() {
|
async _loadRegistries() {
|
||||||
try {
|
try {
|
||||||
const [areas, devices, entities] = await Promise.all([
|
const [areas, devices, entities] = await Promise.all([
|
||||||
this._hass.callWS({ type: "config/area_registry/list" }),
|
this._hass.callWS({ type: "config/area_registry/list" }),
|
||||||
this._hass.callWS({ type: "config/device_registry/list" }),
|
this._hass.callWS({ type: "config/device_registry/list" }),
|
||||||
this._hass.callWS({ type: "config/entity_registry/list" }),
|
this._hass.callWS({ type: "config/entity_registry/list" }),
|
||||||
]);
|
]);
|
||||||
this._areas = areas;
|
this._areas = areas;
|
||||||
const devArea = {};
|
const devArea = {};
|
||||||
for (const d of devices) if (d.area_id) devArea[d.id] = d.area_id;
|
for (const d of devices) if (d.area_id) devArea[d.id] = d.area_id;
|
||||||
this._ent2area = {};
|
this._ent2area = {};
|
||||||
for (const e of entities) {
|
for (const e of entities) {
|
||||||
const a = e.area_id || devArea[e.device_id];
|
const a = e.area_id || devArea[e.device_id];
|
||||||
if (a) this._ent2area[e.entity_id] = a;
|
if (a) this._ent2area[e.entity_id] = a;
|
||||||
}
|
}
|
||||||
} catch (err) { this._error = String(err); }
|
} catch (err) { this._error = String(err); }
|
||||||
this._render();
|
this._render();
|
||||||
}
|
}
|
||||||
|
|
||||||
_roomList() {
|
_roomList() {
|
||||||
const names = {
|
const names = {
|
||||||
terrasa: "Терраса", kitchen: "Кухня-гостиная", postirochnaia: "Тех.пом.",
|
terrasa: "Терраса", kitchen: "Кухня-гостиная", postirochnaia: "Тех.пом.",
|
||||||
sanuzel: "Санузел", tualet: "Туалет", garderob: "Гардероб", kladovaia: "Кладовая",
|
sanuzel: "Санузел", tualet: "Туалет", garderob: "Гардероб", kladovaia: "Кладовая",
|
||||||
koridor: "Холл", prihozhaya: "Прихожая", tambur: "Тамбур",
|
koridor: "Холл", prihozhaya: "Прихожая", tambur: "Тамбур",
|
||||||
kabinet: "Спальня", danina_komnata: "Кабинет",
|
kabinet: "Спальня", danina_komnata: "Кабинет",
|
||||||
spalnia: "Данина комната", kryltso: "Крыльцо",
|
spalnia: "Данина комната", kryltso: "Крыльцо",
|
||||||
};
|
};
|
||||||
return Object.keys(START).map((id) => ({ id, name: names[id] || id }));
|
return Object.keys(START).map((id) => ({ id, name: names[id] || id }));
|
||||||
}
|
}
|
||||||
|
|
||||||
_entitiesOf(areaId) {
|
_entitiesOf(areaId) {
|
||||||
if (!areaId) return [];
|
if (!areaId) return [];
|
||||||
return Object.entries(this._ent2area).filter(([, a]) => a === areaId)
|
return Object.entries(this._ent2area).filter(([, a]) => a === areaId)
|
||||||
.map(([e]) => e).filter((e) => this._hass.states[e]);
|
.map(([e]) => e).filter((e) => this._hass.states[e]);
|
||||||
}
|
}
|
||||||
_domain(e) { return e.split(".")[0]; }
|
_domain(e) { return e.split(".")[0]; }
|
||||||
_on(id) {
|
_on(id) {
|
||||||
return this._entitiesOf(id).filter((e) => {
|
return this._entitiesOf(id).filter((e) => {
|
||||||
const st = this._hass.states[e];
|
const st = this._hass.states[e];
|
||||||
return (this._domain(e) === "light" || this._domain(e) === "switch") && st.state === "on";
|
return (this._domain(e) === "light" || this._domain(e) === "switch") && st.state === "on";
|
||||||
}).length;
|
}).length;
|
||||||
}
|
}
|
||||||
_sensors(id) {
|
_sensors(id) {
|
||||||
const out = [];
|
const out = [];
|
||||||
for (const e of this._entitiesOf(id)) {
|
for (const e of this._entitiesOf(id)) {
|
||||||
if (this._domain(e) !== "sensor" || !SENSOR_HINT.test(e)) continue;
|
if (this._domain(e) !== "sensor" || !SENSOR_HINT.test(e)) continue;
|
||||||
const st = this._hass.states[e];
|
const st = this._hass.states[e];
|
||||||
out.push(`${(st.attributes.friendly_name || e).split(" ").slice(-1)[0]}: ${st.state}${st.attributes.unit_of_measurement || ""}`);
|
out.push(`${(st.attributes.friendly_name || e).split(" ").slice(-1)[0]}: ${st.state}${st.attributes.unit_of_measurement || ""}`);
|
||||||
}
|
}
|
||||||
return out.slice(0, 2);
|
return out.slice(0, 2);
|
||||||
}
|
}
|
||||||
_toggle(e) {
|
_toggle(e) {
|
||||||
const d = this._domain(e);
|
const d = this._domain(e);
|
||||||
if (d === "light" || d === "switch") this._hass.callService(d, "toggle", { entity_id: e });
|
if (d === "light" || d === "switch") this._hass.callService(d, "toggle", { entity_id: e });
|
||||||
}
|
}
|
||||||
|
|
||||||
_wallsSvg() {
|
_wallsSvg() {
|
||||||
const seen = {};
|
const seen = {};
|
||||||
const out = [];
|
const out = [];
|
||||||
for (const r of ROOMS) {
|
for (const r of ROOMS) {
|
||||||
const poly = this._polys[ROOMS.indexOf(r)] || r.poly;
|
const poly = this._polys[ROOMS.indexOf(r)] || r.poly;
|
||||||
for (let i = 0; i < poly.length; i++) {
|
for (let i = 0; i < poly.length; i++) {
|
||||||
const a = poly[i];
|
const a = poly[i];
|
||||||
const b = poly[(i + 1) % poly.length];
|
const b = poly[(i + 1) % poly.length];
|
||||||
const k1 = a[0] + "," + a[1] + "-" + b[0] + "," + b[1];
|
const k1 = a[0] + "," + a[1] + "-" + b[0] + "," + b[1];
|
||||||
const k2 = b[0] + "," + b[1] + "-" + a[0] + "," + a[1];
|
const k2 = b[0] + "," + b[1] + "-" + a[0] + "," + a[1];
|
||||||
if (seen[k1] || seen[k2]) continue;
|
if (seen[k1] || seen[k2]) continue;
|
||||||
seen[k1] = true;
|
seen[k1] = true;
|
||||||
out.push(`<line class="wall" x1="${a[0]}" y1="${a[1]}" x2="${b[0]}" y2="${b[1]}"/>`);
|
out.push(`<line class="wall" x1="${a[0]}" y1="${a[1]}" x2="${b[0]}" y2="${b[1]}"/>`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out.join("");
|
return out.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
_planSvg(areaId) {
|
_planSvg(areaId) {
|
||||||
let shapes = "", labels = "", tmp = "";
|
let shapes = "", labels = "", tmp = "";
|
||||||
for (const r of this._roomList()) {
|
for (const r of this._roomList()) {
|
||||||
const poly = this._polys[r.id] || [];
|
const poly = this._polys[r.id] || [];
|
||||||
if (!poly.length) continue;
|
if (!poly.length) continue;
|
||||||
const sel = r.id === areaId;
|
const sel = r.id === areaId;
|
||||||
shapes += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}"
|
shapes += `<polygon class="zone ${sel ? "sel" : ""}" data-a="${r.id}"
|
||||||
points="${poly.map(([x, y]) => `${x},${y}`).join(" ")}"><title>${r.name}</title></polygon>`;
|
points="${poly.map(([x, y]) => `${x},${y}`).join(" ")}"><title>${r.name}</title></polygon>`;
|
||||||
// на подложке уже есть подписи — свои не рисуем, только подсказку
|
// на подложке уже есть подписи — свои не рисуем, только подсказку
|
||||||
|
|
||||||
}
|
}
|
||||||
if (this._tmp.length) {
|
if (this._tmp.length) {
|
||||||
tmp = `<polyline class="tmp" points="${this._tmp.map(([x, y]) => `${x},${y}`).join(" ")}"/>`;
|
tmp = `<polyline class="tmp" points="${this._tmp.map(([x, y]) => `${x},${y}`).join(" ")}"/>`;
|
||||||
this._tmp.forEach(([x, y]) => {
|
this._tmp.forEach(([x, y]) => {
|
||||||
tmp += `<circle class="tmpdot" cx="${x}" cy="${y}" r="4"/>`;
|
tmp += `<circle class="tmpdot" cx="${x}" cy="${y}" r="4"/>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return `<div class="plan-wrap">
|
return `<div class="plan-wrap">
|
||||||
<svg class="plan" viewBox="170 100 640 510" preserveAspectRatio="xMidYMid meet">
|
<svg class="plan" viewBox="170 100 640 510" preserveAspectRatio="xMidYMid meet">
|
||||||
${shapes}${labels}${tmp}
|
${shapes}${labels}${tmp}
|
||||||
</svg></div>`;
|
</svg></div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
_bindDraw() {
|
_bindDraw() {
|
||||||
const svg = this.shadowRoot.querySelector("svg.layer");
|
const svg = this.shadowRoot.querySelector("svg.layer");
|
||||||
if (!svg) return;
|
if (!svg) return;
|
||||||
svg.addEventListener("click", (ev) => {
|
svg.addEventListener("click", (ev) => {
|
||||||
if (!this._draw) return;
|
if (!this._draw) return;
|
||||||
const pt = svg.createSVGPoint();
|
const pt = svg.createSVGPoint();
|
||||||
pt.x = ev.clientX; pt.y = ev.clientY;
|
pt.x = ev.clientX; pt.y = ev.clientY;
|
||||||
const loc = pt.matrixTransform(svg.getScreenCTM().inverse());
|
const loc = pt.matrixTransform(svg.getScreenCTM().inverse());
|
||||||
this._tmp.push([Math.round(loc.x), Math.round(loc.y)]);
|
this._tmp.push([Math.round(loc.x), Math.round(loc.y)]);
|
||||||
this._render();
|
this._render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_entityRow(e, dom) {
|
_entityRow(e, dom) {
|
||||||
const st = this._hass.states[e];
|
const st = this._hass.states[e];
|
||||||
const nm = st.attributes.friendly_name || e;
|
const nm = st.attributes.friendly_name || e;
|
||||||
const on = st.state === "on";
|
const on = st.state === "on";
|
||||||
if (dom === "light") {
|
if (dom === "light") {
|
||||||
const br = st.attributes.brightness;
|
const br = st.attributes.brightness;
|
||||||
const pct = br ? Math.round((br / 255) * 100) : 0;
|
const pct = br ? Math.round((br / 255) * 100) : 0;
|
||||||
return `<div class="row"><span class="nm">${nm}</span>
|
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"}/>
|
<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>`;
|
<span class="sw ${on ? "on" : ""}" data-e="${e}">${on ? "вкл" : "выкл"}</span></div>`;
|
||||||
}
|
}
|
||||||
if (dom === "climate") {
|
if (dom === "climate") {
|
||||||
const cur = st.attributes.current_temperature;
|
const cur = st.attributes.current_temperature;
|
||||||
const tgt = st.attributes.temperature;
|
const tgt = st.attributes.temperature;
|
||||||
return `<div class="row"><span class="nm">${nm}</span>
|
return `<div class="row"><span class="nm">${nm}</span>
|
||||||
<span class="vl">${cur !== undefined ? cur + "°" : ""} → ${tgt !== undefined ? tgt + "°" : ""}</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>
|
||||||
<span class="btn" data-clim="${e}" data-d="0.5">+</span></div>`;
|
<span class="btn" data-clim="${e}" data-d="0.5">+</span></div>`;
|
||||||
}
|
}
|
||||||
if (dom === "media_player") {
|
if (dom === "media_player") {
|
||||||
const playing = st.state === "playing";
|
const playing = st.state === "playing";
|
||||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
||||||
<span class="btn" data-media="${e}">${playing ? "⏸" : "▶"}</span></div>`;
|
<span class="btn" data-media="${e}">${playing ? "⏸" : "▶"}</span></div>`;
|
||||||
}
|
}
|
||||||
if (dom === "cover") {
|
if (dom === "cover") {
|
||||||
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${st.state}</span>
|
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="open_cover">↑</span>
|
||||||
<span class="btn" data-cover="${e}" data-a="stop_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>`;
|
<span class="btn" data-cover="${e}" data-a="close_cover">↓</span></div>`;
|
||||||
}
|
}
|
||||||
const val = st.state + (st.attributes.unit_of_measurement || "");
|
const val = st.state + (st.attributes.unit_of_measurement || "");
|
||||||
const act = dom === "switch"
|
const act = dom === "switch"
|
||||||
? `<span class="sw ${on ? "on" : ""}" data-e="${e}">${on ? "вкл" : "выкл"}</span>` : "";
|
? `<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>`;
|
return `<div class="row"><span class="nm">${nm}</span><span class="vl">${val}</span>${act}</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
_render() {
|
_render() {
|
||||||
if (!this._hass) return;
|
if (!this._hass) return;
|
||||||
const areaId = this._selected;
|
const areaId = this._selected;
|
||||||
const tiles = this._roomList().map((r) => {
|
const tiles = this._roomList().map((r) => {
|
||||||
const ens = this._entitiesOf(r.id);
|
const ens = this._entitiesOf(r.id);
|
||||||
const on = this._on(r.id);
|
const on = this._on(r.id);
|
||||||
const sensors = this._sensors(r.id).join(" · ");
|
const sensors = this._sensors(r.id).join(" · ");
|
||||||
return `<button class="tile ${r.id === areaId ? "sel" : ""}" data-a="${r.id}">
|
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-top"><ha-icon icon="mdi:floor-plan"></ha-icon><span class="cnt">${ens.length}</span></div>
|
||||||
<div class="tile-name">${r.name}</div>
|
<div class="tile-name">${r.name}</div>
|
||||||
${on ? `<div class="tile-meta">💡 ${on}</div>` : ""}
|
${on ? `<div class="tile-meta">💡 ${on}</div>` : ""}
|
||||||
${sensors ? `<div class="tile-sens">${sensors}</div>` : ""}</button>`;
|
${sensors ? `<div class="tile-sens">${sensors}</div>` : ""}</button>`;
|
||||||
}).join("");
|
}).join("");
|
||||||
|
|
||||||
const list = this._roomList();
|
const list = this._roomList();
|
||||||
const jsonStr = this._jsonPx();
|
const jsonStr = this._jsonPx();
|
||||||
const drawBar = this._draw ? `<div class="drawbar">
|
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>
|
<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>
|
<span class="hint">кликайте по углам комнаты на плане (${this._tmp.length} точек)</span>
|
||||||
<button data-act="finish" ${this._tmp.length < 3 ? "disabled" : ""}>Готово</button>
|
<button data-act="finish" ${this._tmp.length < 3 ? "disabled" : ""}>Готово</button>
|
||||||
<button data-act="cancel">Отмена</button>
|
<button data-act="cancel">Отмена</button>
|
||||||
<button data-act="clear">Очистить комнату</button>
|
<button data-act="clear">Очистить комнату</button>
|
||||||
<button data-act="copy">Скопировать</button>
|
<button data-act="copy">Скопировать</button>
|
||||||
<button data-act="download">Скачать JSON</button>
|
<button data-act="download">Скачать JSON</button>
|
||||||
</div>
|
</div>
|
||||||
<textarea class="json" readonly rows="3">${jsonStr}</textarea>
|
<textarea class="json" readonly rows="3">${jsonStr}</textarea>
|
||||||
<div class="hint">если «Скопировать» не сработало — нажмите в поле и Ctrl+A, Ctrl+C, или скачайте файл</div>` : "";
|
<div class="hint">если «Скопировать» не сработало — нажмите в поле и Ctrl+A, Ctrl+C, или скачайте файл</div>` : "";
|
||||||
|
|
||||||
let detail = "";
|
let detail = "";
|
||||||
if (areaId) {
|
if (areaId) {
|
||||||
const ens = this._entitiesOf(areaId);
|
const ens = this._entitiesOf(areaId);
|
||||||
const groups = {};
|
const groups = {};
|
||||||
for (const e of ens) (groups[this._domain(e)] ||= []).push(e);
|
for (const e of ens) (groups[this._domain(e)] ||= []).push(e);
|
||||||
const rows = Object.keys(groups).sort((a, b) => {
|
const rows = Object.keys(groups).sort((a, b) => {
|
||||||
const ia = KEY_DOMAINS.includes(a) ? KEY_DOMAINS.indexOf(a) : 60 + a.charCodeAt(0);
|
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);
|
const ib = KEY_DOMAINS.includes(b) ? KEY_DOMAINS.indexOf(b) : 60 + b.charCodeAt(0);
|
||||||
return ia - ib;
|
return ia - ib;
|
||||||
}).map((dom) => {
|
}).map((dom) => {
|
||||||
const items = groups[dom].map((e) => this._entityRow(e, dom)).join("");
|
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>`;
|
return `<div class="grp"><div class="grp-h">${dom} · ${groups[dom].length}</div>${items}</div>`;
|
||||||
}).join("");
|
}).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>`;
|
const passive = ens.filter((e) => /^(sensor|binary_sensor)\./.test(e));
|
||||||
}
|
const rank = (e) => {
|
||||||
|
const d = (this._hass.states[e] || {}).attributes.device_class || "";
|
||||||
this.shadowRoot.innerHTML = `<style>
|
if (d === "temperature") return 0;
|
||||||
:host { display:block; font-family: var(--paper-font-body1_-_font-family, system-ui); }
|
if (d === "humidity") return 1;
|
||||||
.bar { display:flex; gap:6px; margin-bottom:8px; flex-wrap:wrap; }
|
if (/^(sensor)\./.test(e)) return 2;
|
||||||
.bar button { background:rgba(30,36,44,.9); color:#cfe0f0; border:1px solid #39424e;
|
return 3;
|
||||||
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); }
|
passive.sort((a, b) => rank(a) - rank(b));
|
||||||
.plan-wrap { position:relative; border-radius:12px; overflow:hidden; background:#0f151c; }
|
const metric = (e) => {
|
||||||
.plan { display:block; width:100%; height:auto; }
|
const st = this._hass.states[e];
|
||||||
.layer { position:absolute; inset:0; width:100%; height:100%; cursor:crosshair; }
|
if (!st) return "";
|
||||||
.zone { fill:rgba(47,127,224,0.10); stroke:rgba(47,127,224,0.75); stroke-width:2; cursor:pointer; }
|
const u = st.attributes.unit_of_measurement || "";
|
||||||
.zone:hover { fill:rgba(47,127,224,0.25); }
|
const nm = (st.attributes.friendly_name || e).replace(/^.*?: /, "");
|
||||||
.zone.sel { fill:rgba(47,127,224,0.32); stroke:#1f6fd0; stroke-width:3; }
|
const val = st.state;
|
||||||
.lbl { font-size:11px; fill:#123a6b; pointer-events:none; paint-order:stroke; stroke:#ffffff; stroke-width:3px; }
|
return `<div class="mt"><div class="mv">${val}${u ? " " + u : ""}</div><div class="mn">${nm}</div></div>`;
|
||||||
.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; }
|
const metrics = passive.length
|
||||||
.drawbar { display:flex; gap:8px; align-items:center; margin-top:8px; flex-wrap:wrap; }
|
? `<div class="metrics">${passive.slice(0, 8).map(metric).join("")}</div>`
|
||||||
.drawbar button { background:#243040; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
: `<div class="metrics empty">Датчиков температуры/влажности в этой комнате пока нет</div>`;
|
||||||
padding:5px 10px; font-size:12px; cursor:pointer; }
|
const photoKey = { sanuzel: "sanuzel" }[areaId] || null;
|
||||||
.drawbar button[disabled] { opacity:.45; cursor:default; }
|
const photos = photoKey
|
||||||
.drawbar .sel { background:#1a222c; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
? [1, 2, 3].map((n) => `<img class="room-photo" src="/local/house3d/rooms/${photoKey}-${n}.png?v=1"
|
||||||
padding:5px 8px; font-size:12px; }
|
onerror="this.style.display='none'">`).join("")
|
||||||
.hint { font-size:11px; opacity:.65; }
|
: "";
|
||||||
.json { width:100%; margin-top:6px; font-family:ui-monospace,monospace; font-size:10px;
|
detail = `<div class="detail"><div class="d-head">${(list.find((r) => r.id === areaId) || {}).name || areaId}
|
||||||
background:#0f1318; color:#9fd0ff; border:1px solid #26303c; border-radius:8px; }
|
<button class="close" data-close="1">×</button></div>
|
||||||
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap:10px; }
|
${photos ? `<div class="photos">${photos}</div>` : ""}${metrics}
|
||||||
.tile { text-align:left; border:1px solid #2a2f36; border-radius:14px;
|
${rows || "<div class='row'>устройств пока нет</div>"}</div>`;
|
||||||
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; }
|
this.shadowRoot.innerHTML = `<style>
|
||||||
.tile.sel { border-color:#4aa3ff; box-shadow:0 0 0 1px #4aa3ff inset; }
|
:host { display:block; font-family: var(--paper-font-body1_-_font-family, system-ui); }
|
||||||
.tile-top { display:flex; justify-content:space-between; align-items:center; opacity:.85; }
|
.bar { display:flex; gap:6px; margin-bottom:8px; flex-wrap:wrap; }
|
||||||
.cnt { font-size:11px; padding:1px 7px; border-radius:9px; background:rgba(74,163,255,.18); color:#8fc4ff; }
|
.bar button { background:rgba(30,36,44,.9); color:#cfe0f0; border:1px solid #39424e;
|
||||||
.tile-name { font-weight:600; margin-top:6px; font-size:14px; }
|
border-radius:9px; padding:4px 10px; font-size:12px; cursor:pointer; }
|
||||||
.tile-meta { font-size:11px; opacity:.7; margin-top:2px; }
|
.bar button.on { border-color:#4aa3ff; color:#dceaff; background:rgba(74,163,255,.16); }
|
||||||
.tile-sens { font-size:11px; opacity:.85; margin-top:6px; color:#9ed3ff; }
|
.plan-wrap { position:relative; border-radius:12px; overflow:hidden; background:#0f151c; }
|
||||||
.detail { border:1px solid #2a2f36; border-radius:14px; padding:12px; margin-top:10px;
|
.plan { display:block; width:100%; height:auto; }
|
||||||
background: rgba(14,17,21,.92); max-height:420px; overflow:auto; }
|
.layer { position:absolute; inset:0; width:100%; height:100%; cursor:crosshair; }
|
||||||
.d-head { font-weight:700; margin-bottom:8px; display:flex; justify-content:space-between; }
|
.zone { fill:rgba(47,127,224,0.10); stroke:rgba(47,127,224,0.75); stroke-width:2; cursor:pointer; }
|
||||||
.close { background:none;border:none;color:#9aa7b4;font-size:18px;cursor:pointer; }
|
.zone:hover { fill:rgba(47,127,224,0.25); }
|
||||||
.grp-h { font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:#7d8b99; margin:10px 0 4px; }
|
.zone.sel { fill:rgba(47,127,224,0.32); stroke:#1f6fd0; stroke-width:3; }
|
||||||
.row { display:flex; gap:8px; align-items:center; font-size:12px; padding:3px 0;
|
.lbl { font-size:11px; fill:#123a6b; pointer-events:none; paint-order:stroke; stroke:#ffffff; stroke-width:3px; }
|
||||||
border-bottom:1px dashed rgba(255,255,255,.05); }
|
.tmp { fill:rgba(255,122,0,0.2); stroke:#ff7a00; stroke-width:2; stroke-dasharray:6 4; }
|
||||||
.nm { flex:1; opacity:.9; } .vl { opacity:.65; }
|
.tmpdot { fill:#ff7a00; stroke:#fff; stroke-width:1.5; }
|
||||||
.sw { font-size:11px; padding:1px 8px; border-radius:8px; border:1px solid #3a4350; cursor:pointer; }
|
.drawbar { display:flex; gap:8px; align-items:center; margin-top:8px; flex-wrap:wrap; }
|
||||||
.br { width:70px; accent-color:#4aa3ff; }
|
.drawbar button { background:#243040; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
||||||
.btn { font-size:12px; padding:0 6px; border-radius:6px; border:1px solid #3a4350; cursor:pointer; }
|
padding:5px 10px; font-size:12px; cursor:pointer; }
|
||||||
.sw.on { background:rgba(74,163,255,.2); border-color:#4aa3ff; color:#bcdcff; }
|
.drawbar button[disabled] { opacity:.45; cursor:default; }
|
||||||
</style>
|
.drawbar .sel { background:#1a222c; color:#cfe0f0; border:1px solid #3a4a5e; border-radius:9px;
|
||||||
<div class="bar">
|
padding:5px 8px; font-size:12px; }
|
||||||
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
|
.hint { font-size:11px; opacity:.65; }
|
||||||
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
|
.json { width:100%; margin-top:6px; font-family:ui-monospace,monospace; font-size:10px;
|
||||||
<button class="${this._draw ? "on" : ""}" data-draw="1">Обводка комнат</button>
|
background:#0f1318; color:#9fd0ff; border:1px solid #26303c; border-radius:8px; }
|
||||||
</div>
|
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap:10px; }
|
||||||
${this._mode === "plan" ? this._planSvg(areaId) + drawBar : `<div class="grid">${tiles}</div>`}
|
.tile { text-align:left; border:1px solid #2a2f36; border-radius:14px;
|
||||||
${detail}`;
|
background: linear-gradient(160deg, rgba(30,36,44,.95), rgba(18,22,27,.95));
|
||||||
|
color: #e8eef5; padding:12px; cursor:pointer; }
|
||||||
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>
|
.tile:hover { border-color:#4aa3ff; }
|
||||||
b.addEventListener("click", () => { this._mode = b.dataset.mode; this._render(); }));
|
.tile.sel { border-color:#4aa3ff; box-shadow:0 0 0 1px #4aa3ff inset; }
|
||||||
const db = this.shadowRoot.querySelector("[data-draw]");
|
.tile-top { display:flex; justify-content:space-between; align-items:center; opacity:.85; }
|
||||||
if (db) db.addEventListener("click", () => {
|
.cnt { font-size:11px; padding:1px 7px; border-radius:9px; background:rgba(74,163,255,.18); color:#8fc4ff; }
|
||||||
this._draw = !this._draw;
|
.tile-name { font-weight:600; margin-top:6px; font-size:14px; }
|
||||||
this._tmp = [];
|
.tile-meta { font-size:11px; opacity:.7; margin-top:2px; }
|
||||||
this._drawRoom = this._drawRoom || "terrasa";
|
.tile-sens { font-size:11px; opacity:.85; margin-top:6px; color:#9ed3ff; }
|
||||||
this._render();
|
.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; }
|
||||||
if (this._mode === "plan") {
|
.mv { font-size:20px; font-weight:700; color:#dceaff; }
|
||||||
this.shadowRoot.querySelectorAll(".zone").forEach((el) =>
|
.mn { font-size:11px; color:#7f93a8; margin-top:2px; }
|
||||||
el.addEventListener("click", (ev) => {
|
.metrics.empty { color:#7f93a8; font-size:12px; }
|
||||||
if (this._draw) { return; }
|
.photos { display:flex; gap:8px; overflow-x:auto; margin:6px 0 10px; }
|
||||||
this._selected = this._selected === el.dataset.a ? null : el.dataset.a;
|
.room-photo { height:150px; border-radius:10px; border:1px solid #2a2f36; flex:0 0 auto; }
|
||||||
this._render();
|
.detail { border:1px solid #2a2f36; border-radius:14px; padding:12px; margin-top:10px;
|
||||||
}));
|
background: rgba(14,17,21,.92); max-height:420px; overflow:auto; }
|
||||||
if (this._draw) this._bindDraw();
|
.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; }
|
||||||
const sel = this.shadowRoot.querySelector(".sel");
|
.grp-h { font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:#7d8b99; margin:10px 0 4px; }
|
||||||
if (sel) sel.addEventListener("change", () => { this._drawRoom = sel.value; this._tmp = []; this._render(); });
|
.row { display:flex; gap:8px; align-items:center; font-size:12px; padding:3px 0;
|
||||||
const finish = this.shadowRoot.querySelector("[data-act=finish]");
|
border-bottom:1px dashed rgba(255,255,255,.05); }
|
||||||
if (finish) finish.addEventListener("click", () => {
|
.nm { flex:1; opacity:.9; } .vl { opacity:.65; }
|
||||||
if (this._tmp.length >= 3 && this._drawRoom) {
|
.sw { font-size:11px; padding:1px 8px; border-radius:8px; border:1px solid #3a4350; cursor:pointer; }
|
||||||
this._polys[this._drawRoom] = this._tmp.slice();
|
.br { width:70px; accent-color:#4aa3ff; }
|
||||||
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
.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; }
|
||||||
this._tmp = [];
|
</style>
|
||||||
this._render();
|
<div class="bar">
|
||||||
});
|
<button class="${this._mode === "plan" ? "on" : ""}" data-mode="plan">План</button>
|
||||||
const cancel = this.shadowRoot.querySelector("[data-act=cancel]");
|
<button class="${this._mode === "tiles" ? "on" : ""}" data-mode="tiles">Плитки</button>
|
||||||
if (cancel) cancel.addEventListener("click", () => { this._tmp = []; this._render(); });
|
<button class="${this._draw ? "on" : ""}" data-draw="1">Обводка комнат</button>
|
||||||
const clear = this.shadowRoot.querySelector("[data-act=clear]");
|
</div>
|
||||||
if (clear) clear.addEventListener("click", () => {
|
${this._mode === "plan" ? this._planSvg(areaId) + drawBar : `<div class="grid">${tiles}</div>`}
|
||||||
delete this._polys[this._drawRoom];
|
${detail}`;
|
||||||
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
|
||||||
this._tmp = [];
|
this.shadowRoot.querySelectorAll("[data-mode]").forEach((b) =>
|
||||||
this._render();
|
b.addEventListener("click", () => { this._mode = b.dataset.mode; this._render(); }));
|
||||||
});
|
const db = this.shadowRoot.querySelector("[data-draw]");
|
||||||
const copy = this.shadowRoot.querySelector("[data-act=copy]");
|
if (db) db.addEventListener("click", () => {
|
||||||
if (copy) copy.addEventListener("click", async () => {
|
this._draw = !this._draw;
|
||||||
const txt = this._jsonPx();
|
this._tmp = [];
|
||||||
let ok = false;
|
this._drawRoom = this._drawRoom || "terrasa";
|
||||||
try {
|
this._render();
|
||||||
if (navigator.clipboard && window.isSecureContext) {
|
});
|
||||||
await navigator.clipboard.writeText(txt);
|
if (this._mode === "plan") {
|
||||||
ok = true;
|
this.shadowRoot.querySelectorAll(".zone").forEach((el) =>
|
||||||
}
|
el.addEventListener("click", (ev) => {
|
||||||
} catch (e) { ok = false; }
|
if (this._draw) { return; }
|
||||||
if (!ok) {
|
this._selected = this._selected === el.dataset.a ? null : el.dataset.a;
|
||||||
try {
|
this._render();
|
||||||
const ta = this.shadowRoot.querySelector(".json");
|
}));
|
||||||
ta.focus(); ta.select();
|
if (this._draw) this._bindDraw();
|
||||||
ok = document.execCommand("copy");
|
}
|
||||||
} catch (e) { ok = false; }
|
const sel = this.shadowRoot.querySelector(".sel");
|
||||||
}
|
if (sel) sel.addEventListener("change", () => { this._drawRoom = sel.value; this._tmp = []; this._render(); });
|
||||||
copy.textContent = ok ? "Скопировано ✓" : "Выделите поле и Ctrl+C";
|
const finish = this.shadowRoot.querySelector("[data-act=finish]");
|
||||||
});
|
if (finish) finish.addEventListener("click", () => {
|
||||||
const dl = this.shadowRoot.querySelector("[data-act=download]");
|
if (this._tmp.length >= 3 && this._drawRoom) {
|
||||||
if (dl) dl.addEventListener("click", () => this._download());
|
this._polys[this._drawRoom] = this._tmp.slice();
|
||||||
this.shadowRoot.querySelectorAll(".tile").forEach((el) =>
|
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
||||||
el.addEventListener("click", () => {
|
}
|
||||||
this._selected = this._selected === el.dataset.a ? null : el.dataset.a;
|
this._tmp = [];
|
||||||
window.setTimeout(() => { const w = this.shadowRoot.querySelector('.plan-wrap'); if (w && w.scrollIntoView) w.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 50);
|
this._render();
|
||||||
document.dispatchEvent(new CustomEvent("house3d-select",
|
});
|
||||||
{ detail: { room: this._selected ? "zone_" + this._selected : null } }));
|
const cancel = this.shadowRoot.querySelector("[data-act=cancel]");
|
||||||
this._render();
|
if (cancel) cancel.addEventListener("click", () => { this._tmp = []; this._render(); });
|
||||||
}));
|
const clear = this.shadowRoot.querySelector("[data-act=clear]");
|
||||||
this.shadowRoot.querySelectorAll(".sw").forEach((s) =>
|
if (clear) clear.addEventListener("click", () => {
|
||||||
s.addEventListener("click", (ev) => { ev.stopPropagation(); this._toggle(s.dataset.e); }));
|
delete this._polys[this._drawRoom];
|
||||||
this.shadowRoot.querySelectorAll(".br").forEach((el) =>
|
try { localStorage.setItem(STORE, JSON.stringify(this._polys)); } catch (e) { /* ignore */ }
|
||||||
el.addEventListener("change", (ev) => {
|
this._tmp = [];
|
||||||
ev.stopPropagation();
|
this._render();
|
||||||
const pct = parseInt(ev.target.value, 10);
|
});
|
||||||
this._hass.callService("light", "turn_on", {
|
const copy = this.shadowRoot.querySelector("[data-act=copy]");
|
||||||
entity_id: ev.target.dataset.e, brightness_pct: pct,
|
if (copy) copy.addEventListener("click", async () => {
|
||||||
});
|
const txt = this._jsonPx();
|
||||||
}));
|
let ok = false;
|
||||||
this.shadowRoot.querySelectorAll("[data-clim]").forEach((el) =>
|
try {
|
||||||
el.addEventListener("click", (ev) => {
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
ev.stopPropagation();
|
await navigator.clipboard.writeText(txt);
|
||||||
const eid = el.dataset.clim;
|
ok = true;
|
||||||
const st = this._hass.states[eid];
|
}
|
||||||
const cur = st.attributes.temperature || 20;
|
} catch (e) { ok = false; }
|
||||||
this._hass.callService("climate", "set_temperature", {
|
if (!ok) {
|
||||||
entity_id: eid, temperature: Math.round((cur + parseFloat(el.dataset.d)) * 2) / 2,
|
try {
|
||||||
});
|
const ta = this.shadowRoot.querySelector(".json");
|
||||||
}));
|
ta.focus(); ta.select();
|
||||||
this.shadowRoot.querySelectorAll("[data-media]").forEach((el) =>
|
ok = document.execCommand("copy");
|
||||||
el.addEventListener("click", (ev) => {
|
} catch (e) { ok = false; }
|
||||||
ev.stopPropagation();
|
}
|
||||||
this._hass.callService("media_player", el.dataset.a, { entity_id: el.dataset.media });
|
copy.textContent = ok ? "Скопировано ✓" : "Выделите поле и Ctrl+C";
|
||||||
}));
|
});
|
||||||
this.shadowRoot.querySelectorAll("[data-cover]").forEach((el) =>
|
const dl = this.shadowRoot.querySelector("[data-act=download]");
|
||||||
el.addEventListener("click", (ev) => {
|
if (dl) dl.addEventListener("click", () => this._download());
|
||||||
ev.stopPropagation();
|
this.shadowRoot.querySelectorAll(".tile").forEach((el) =>
|
||||||
this._hass.callService("cover", el.dataset.a, { entity_id: el.dataset.cover });
|
el.addEventListener("click", () => {
|
||||||
}));
|
this._selected = this._selected === el.dataset.a ? null : el.dataset.a;
|
||||||
const close = this.shadowRoot.querySelector(".close");
|
window.setTimeout(() => { const w = this.shadowRoot.querySelector('.plan-wrap'); if (w && w.scrollIntoView) w.scrollIntoView({ behavior: 'smooth', block: 'center' }); }, 50);
|
||||||
if (close) close.addEventListener("click", () => { this._selected = null; this._render(); });
|
document.dispatchEvent(new CustomEvent("house3d-select",
|
||||||
}
|
{ detail: { room: this._selected ? "zone_" + this._selected : null } }));
|
||||||
|
this._render();
|
||||||
_jsonPx() {
|
}));
|
||||||
try { return JSON.stringify(this._polys); } catch (e) { return "{}"; }
|
this.shadowRoot.querySelectorAll(".sw").forEach((s) =>
|
||||||
}
|
s.addEventListener("click", (ev) => { ev.stopPropagation(); this._toggle(s.dataset.e); }));
|
||||||
|
this.shadowRoot.querySelectorAll(".br").forEach((el) =>
|
||||||
_download() {
|
el.addEventListener("change", (ev) => {
|
||||||
try {
|
ev.stopPropagation();
|
||||||
const blob = new Blob([this._jsonPx()], { type: "application/json" });
|
const pct = parseInt(ev.target.value, 10);
|
||||||
const a = document.createElement("a");
|
this._hass.callService("light", "turn_on", {
|
||||||
a.href = URL.createObjectURL(blob);
|
entity_id: ev.target.dataset.e, brightness_pct: pct,
|
||||||
a.download = "room-zones.json";
|
});
|
||||||
a.click();
|
}));
|
||||||
setTimeout(() => URL.revokeObjectURL(a.href), 2000);
|
this.shadowRoot.querySelectorAll("[data-clim]").forEach((el) =>
|
||||||
} catch (e) { /* ignore */ }
|
el.addEventListener("click", (ev) => {
|
||||||
}
|
ev.stopPropagation();
|
||||||
|
const eid = el.dataset.clim;
|
||||||
getCardSize() { return 14; }
|
const st = this._hass.states[eid];
|
||||||
}
|
const cur = st.attributes.temperature || 20;
|
||||||
|
this._hass.callService("climate", "set_temperature", {
|
||||||
customElements.define("rooms-card", RoomsCard);
|
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);
|
||||||