You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
6.2 KiB

  1. import{Y as j,S as I,i as E,s as x,C as N,D as W,E as P,F as U,g as R,d as T,W as D,o as A,I as M,X as O}from"./index.f09c780f.js";import{w,d as L}from"./index.faf1c53d.js";function J(r){let c;const u=r[1].default,n=N(u,r,r[0],null);return{c(){n&&n.c()},l(t){n&&n.l(t)},m(t,o){n&&n.m(t,o),c=!0},p(t,[o]){n&&n.p&&(!c||o&1)&&W(n,u,t,t[0],c?U(u,t[0],o,null):P(t[0]),null)},i(t){c||(R(n,t),c=!0)},o(t){T(n,t),c=!1},d(t){n&&n.d(t)}}}const K={ctx:"ModalContext"};function se(){return j(K)}function X(r,c,u){let{$$slots:n={},$$scope:t}=c;return D(K,{modal:w({kind:"closed"})}),r.$$set=o=>{"$$scope"in o&&u(0,t=o.$$scope)},[t,n]}class ne extends I{constructor(c){super(),E(this,c,X,J,x,{})}}async function F(r,c){var o;const u=({}.VITE_LUCIFER4_BACKEND_URL||"")+"/"+r,n=await fetch(u,c);if(n.status!==200)throw(o=n.headers.get("Content-Type"))!=null&&o.includes("application/json")?await n.json():await n.text();return await n.json()}async function Y(){return F("state")}async function ie(r){return F("command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})}function z(r){let c;const u=r[1].default,n=N(u,r,r[0],null);return{c(){n&&n.c()},l(t){n&&n.l(t)},m(t,o){n&&n.m(t,o),c=!0},p(t,[o]){n&&n.p&&(!c||o&1)&&W(n,u,t,t[0],c?U(u,t[0],o,null):P(t[0]),null)},i(t){c||(R(n,t),c=!0)},o(t){T(n,t),c=!1},d(t){n&&n.d(t)}}}const B={ctx:"StateContext"};function G(){return j(B)}function H(r,c,u){let{$$slots:n={},$$scope:t}=c;const o=w({assignments:{},devices:{},scripts:{},triggers:{}}),p=w(null);let g=null;const k=L(o,l=>l==null?[]:Object.keys(l.devices).map(a=>l.devices[a]).sort((a,f)=>a.name.localeCompare(f.name))),$=L(o,l=>Object.keys(l.devices).flatMap(a=>l.devices[a].aliases.filter(f=>["tag","room","role","name"].find(e=>f.startsWith(`lucifer:${e}:`)))).sort().filter((a,f,e)=>e[f-1]!==a)),v=L(o,l=>l==null?[]:Object.keys(l.assignments).map(a=>l.assignments[a]).sort((a,f)=>a.id.localeCompare(f.id))),_=L(o,l=>{const a={},f={};for(const e in l.devices){if(!l.devices.hasOwnProperty(e))continue;const i=l.devices[e].aliases.find(b=>b.startsWith("lucifer:room:")),s=l.devices[e].aliases.find(b=>b.startsWith("lucifer:group:")),d=(i==null?void 0:i.slice(13))||"Unroomed",m=(s==null?void 0:s.slice(14))||"";a[d]||(a[d]=[]),s&&(f[e]=m),a[d].push(l.devices[e])}return Object.keys(a).map(e=>({name:e,devices:a[e].filter(i=>!f[i.id]).sort((i,s)=>i.name.localeCompare(s.name)),groups:a[e].filter(i=>!!f[i.id]).reduce((i,s)=>{const d=i.find(m=>m.name===f[s.id]);return d==null?i.push({name:f[s.id],devices:[s]}):d.devices.push(s),i},[]).map(i=>({...i,devices:i.devices.sort((s,d)=>s.name.localeCompare(d.name))})).sort((i,s)=>i.name.localeCompare(s.name))})).sort((e,i)=>e.name.localeCompare(i.name))});async function C(){p.set(null);try{const l=await Y();o.set(l)}catch(l){p.set(l!=null&&l.toString?l.toString():String(l))}}async function y(){let l=`ws://${window.location.host}/subscribe-simple`;({}).VITE_LUCIFER4_BACKEND_URL!=null&&(l={}.VITE_LUCIFER4_BACKEND_URL.replace("http","ws")+"/subscribe-simple");const a=new WebSocket(l);a.onmessage=f=>{const e=JSON.parse(f.data);o.update(i=>{e.full!=null&&(i=e.full);for(const s in e.devices)e.devices.hasOwnProperty(s)&&(i.devices={...i.devices},e.devices[s]!==null?i.devices[s]=e.devices[s]:delete i.devices[s]);for(const s in e.assignments)e.assignments.hasOwnProperty(s)&&(i.assignments={...i.assignments},e.assignments[s]!=null?i.assignments[s]=e.assignments[s]:delete i.assignments[s]);for(const s in e.scripts)e.scripts.hasOwnProperty(s)&&(i.scripts={...i.scripts},e.scripts[s]!=null?i.scripts[s]=e.scripts[s]:delete i.scripts[s]);for(const s in e.triggers)e.triggers.hasOwnProperty(s)&&(i.triggers={...i.triggers},e.triggers[s]!=null?i.triggers[s]=e.triggers[s]:delete i.triggers[s]);return i})},a.onopen=()=>{g!==null&&g.close(),g=a},a.onerror=f=>{console.warn("Socket failed:",f),a.close(),setTimeout(()=>y(),3e3)},a.onclose=()=>{a===g&&(g=null)}}return A(()=>{y(),window.addEventListener("visibilitychange",()=>{document.visibilityState=="visible"?(console.log("Reconnecting"),y()):g!=null&&(console.log("Disconnect