iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 11.2 kB
JavaScript
export const __rspack_esm_id=52422;export const __rspack_esm_ids=[52422];export const __webpack_modules__={74706(t,i,e){e.a(t,async function(t,a){try{e.r(i),e.d(i,{HaScriptTrace:()=>N});e(18111),e(20116),e(13579),e(69112),e(33110),e(14603),e(47566),e(98721);var o=e(62826),s=(e(68825),e(35211)),r=e(5124),c=e(22441),n=e(36312),h=e(1087),d=e(91926),l=e(18350),p=e(29823),_=(e(70947),e(26300)),g=e(66289),u=(e(62647),e(98920)),v=e(7370),b=e(193),w=e(29804),f=e(73003),$=e(68886),y=e(22792),k=e(86531),m=e(61165),I=e(65063),x=e(81310),C=e(14503),T=e(30039),A=e(48240),L=t([l,p,_,g,u,v,b,w,f,$,x,A,k]);[l,p,_,g,u,v,b,w,f,$,x,A,k]=L.then?(await L)():L;const M="M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z",H="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z",E="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z",q="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z",z="M1,12L5,16V13H17.17C17.58,14.17 18.69,15 20,15A3,3 0 0,0 23,12A3,3 0 0,0 20,9C18.69,9 17.58,9.83 17.17,11H5V8L1,12Z",S="M23,12L19,16V13H6.83C6.42,14.17 5.31,15 4,15A3,3 0 0,1 1,12A3,3 0 0,1 4,9C5.31,9 6.42,9.83 6.83,11H19V8L23,12Z",Z="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z",V=["details","timeline","logbook","config"];class N extends r.WF{render(){const t=this._entityId?this.hass.states[this._entityId]:void 0,i=this._graph,e=i?.trackedNodes,a=i?.renderedNodes,o=t?.attributes.friendly_name||this._entityId;return r.qy` ${""} <hass-subpage .hass="${this.hass}" .narrow="${this.narrow}" .header="${o}" .scrollable="${this.narrow}"> ${!this.narrow&&this.scriptId?r.qy` <ha-button class="trace-link" ="${this._navigateToScript}" slot="toolbar-icon" appearance="plain"> ${this.hass.localize("ui.panel.config.script.trace.edit_script")} </ha-button> `:r.s6} <ha-dropdown slot="toolbar-icon" -select="${this._handleDropdownSelect}"> <ha-icon-button slot="trigger" .label="${this.hass.localize("ui.common.menu")}" .path="${M}"></ha-icon-button> <ha-dropdown-item .disabled="${!t}" value="show_info"> ${this.hass.localize("ui.panel.config.script.editor.show_info")} <ha-svg-icon slot="icon" .path="${E}"></ha-svg-icon> </ha-dropdown-item> ${this.narrow&&this.scriptId?r.qy`<ha-dropdown-item value="edit_script"> ${this.hass.localize("ui.panel.config.script.trace.edit_script")} <ha-svg-icon slot="icon" .path="${q}"></ha-svg-icon> </ha-dropdown-item> `:r.s6} <wa-divider></wa-divider> <ha-dropdown-item value="refresh"> ${this.hass.localize("ui.panel.config.automation.trace.refresh")} <ha-svg-icon slot="icon" .path="${Z}"></ha-svg-icon> </ha-dropdown-item> <ha-dropdown-item .disabled="${!this._trace}" value="download_trace"> ${this.hass.localize("ui.panel.config.automation.trace.download_trace")} <ha-svg-icon slot="icon" .path="${H}"></ha-svg-icon> </ha-dropdown-item> </ha-dropdown> <div class="toolbar"> ${this._traces&&this._traces.length>0?r.qy` <ha-icon-button .disabled="${this._traces[this._traces.length-1].run_id===this._runId}" .label="${this.hass.localize("ui.panel.config.automation.trace.older_trace")}" ="${this._pickOlderTrace}" .path="${z}"></ha-icon-button> <ha-trace-picker .hass="${this.hass}" .traces="${this._traces}" .value="${this._runId}" -changed="${this._pickTrace}"></ha-trace-picker> <ha-icon-button .disabled="${this._traces[0].run_id===this._runId}" .label="${this.hass.localize("ui.panel.config.automation.trace.newer_trace")}" ="${this._pickNewerTrace}" .path="${S}"></ha-icon-button> `:""} </div> ${void 0===this._traces?r.qy`<div class="container">Loading…</div>`:0===this._traces.length?r.qy`<div class="container"> ${this.hass.localize("ui.panel.config.automation.trace.no_traces_found")} </div>`:void 0===this._trace?"":r.qy` <div class="main"> <div class="graph"> <hat-script-graph .hass="${this.hass}" .trace="${this._trace}" .selected="${this._selected?.path}" -node-selected="${this._pickNode}"></hat-script-graph> </div> <div class="info"> <ha-tab-group -tab-show="${this._handleTabChanged}"> ${V.map(t=>r.qy` <ha-tab-group-tab slot="nav" .active="${this._view===t}" .panel="${t}"> ${this.hass.localize(`ui.panel.config.automation.trace.tabs.${"config"===t?"script_config":t}`)} </ha-tab-group-tab> `)} ${this._trace.blueprint_inputs?r.qy` <ha-tab-group-tab slot="nav" .active="${"blueprint"===this._view}" panel="blueprint"> ${this.hass.localize("ui.panel.config.automation.trace.tabs.blueprint_config")} </ha-tab-group-tab> `:""} </ha-tab-group> ${void 0===this._selected||void 0===this._logbookEntries||void 0===e?"":"details"===this._view?r.qy` <ha-trace-path-details .hass="${this.hass}" .narrow="${this.narrow}" .trace="${this._trace}" .selected="${this._selected}" .logbookEntries="${this._logbookEntries}" .trackedNodes="${e}" .renderedNodes="${a}"></ha-trace-path-details> `:"config"===this._view?r.qy` <ha-trace-config .trace="${this._trace}"></ha-trace-config> `:"logbook"===this._view?r.qy` <ha-trace-logbook .hass="${this.hass}" .narrow="${this.narrow}" .trace="${this._trace}" .logbookEntries="${this._logbookEntries}"></ha-trace-logbook> `:"blueprint"===this._view?r.qy` <ha-trace-blueprint-config .trace="${this._trace}"></ha-trace-blueprint-config> `:r.qy` <ha-trace-timeline .hass="${this.hass}" .trace="${this._trace}" .logbookEntries="${this._logbookEntries}" .selected="${this._selected}" -changed="${this._timelinePathPicked}"></ha-trace-timeline> `} </div> </div> `} </hass-subpage> `}firstUpdated(t){if(super.firstUpdated(t),!this.scriptId)return;const i=new URLSearchParams(location.search);this._loadTraces(i.get("run_id")||void 0),this._entityId=this._entityRegistry.find(t=>t.unique_id===this.scriptId)?.entity_id}willUpdate(t){super.willUpdate(t),t.get("scriptId")&&(this._traces=void 0,this._runId=void 0,this._trace=void 0,this._logbookEntries=void 0,this.scriptId&&(this._loadTraces(),this._entityId=this._entityRegistry.find(t=>t.unique_id===this.scriptId)?.entity_id)),t.has("_runId")&&this._runId&&(this._trace=void 0,this._logbookEntries=void 0,this._loadTrace())}_pickOlderTrace(){const t=this._traces.findIndex(t=>t.run_id===this._runId);this._runId=this._traces[t+1].run_id,this._selected=void 0}_pickNewerTrace(){const t=this._traces.findIndex(t=>t.run_id===this._runId);this._runId=this._traces[t-1].run_id,this._selected=void 0}_pickTrace(t){this._runId=t.detail.value,this._selected=void 0}_pickNode(t){this._selected=t.detail}_refreshTraces(){this._loadTraces()}async _loadTraces(t){if(this._traces=await(0,m.d1)(this.hass,"script",this.scriptId),this._traces.reverse(),t&&(this._runId=t),this._runId&&!this._traces.some(t=>t.run_id===this._runId)){if(this._runId=void 0,this._selected=void 0,t){const t=new URLSearchParams(location.search);t.delete("run_id"),history.replaceState(null,"",`${location.pathname}?${t.toString()}`)}await(0,I.showAlertDialog)(this,{text:this.hass.localize("ui.panel.config.automation.trace.trace_no_longer_available")})}!this._runId&&this._traces.length>0&&(this._runId=this._traces[0].run_id)}async _loadTrace(){const t=await(0,m.E4)(this.hass,"script",this.scriptId,this._runId);this._logbookEntries=(0,n.x)(this.hass.config,"logbook")?await(0,k.gd)(this.hass,t.timestamp.start,t.context.id):[],this._trace=t}_downloadTrace(){const t=JSON.stringify({trace:this._trace,logbookEntries:this._logbookEntries},void 0,2),i=new Blob([t],{type:"application/json"}),e=URL.createObjectURL(i);(0,T.R)(e,`trace ${this._entityId} ${this._trace.timestamp.start}.json`)}_importTrace(){const t=prompt(this.hass.localize("ui.panel.config.automation.trace.enter_downloaded_trace"));t&&(window.localStorage.setItem("devTrace",t),this._loadLocalTrace(t))}_loadLocalStorageTrace(){const t=window.localStorage.getItem("devTrace");t&&this._loadLocalTrace(t)}_loadLocalTrace(t){const i=JSON.parse(t);this._trace=i.trace,this._logbookEntries=i.logbookEntries}_handleTabChanged(t){this._view=t.detail.name}_timelinePathPicked(t){const i=t.detail.value,e=this._graph.trackedNodes;e[i]&&(this._selected=e[i])}async _showInfo(){this._entityId&&(0,h.r)(this,"hass-more-info",{entityId:this._entityId})}_navigateToScript(){this.scriptId&&(0,d.oo)(`/config/script/edit/${this.scriptId}`)}_handleDropdownSelect(t){const i=t.detail?.item?.value;if(i)switch(i){case"show_info":this._showInfo();break;case"refresh":this._refreshTraces();break;case"download_trace":this._downloadTrace();break;case"edit_script":this._navigateToScript()}}static get styles(){return[C.RF,r.AH`.toolbar{display:flex;align-items:center;justify-content:center;height:var(--header-height);background-color:var(--primary-background-color);color:var(--app-header-text-color,#fff);border-bottom:var(--app-header-border-bottom,none);box-sizing:border-box}.main{flex:1;min-height:0;display:flex;overflow:hidden;background-color:var(--card-background-color)}:host([narrow]) .main{flex:none;height:auto;flex-direction:column;overflow:visible}.container{padding:16px}.graph{border-right:1px solid var(--divider-color);max-width:50%;box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden}hat-script-graph{flex:1;min-width:0;min-height:0}:host([narrow]) .graph{max-width:100%;overflow:visible;height:auto}:host([narrow]) hat-script-graph{overflow:visible;flex:none}.info{flex:1;overflow-y:auto;background-color:var(--card-background-color)}ha-tab-group{background-color:var(--primary-background-color);border-bottom:1px solid var(--divider-color);direction:var(--direction)}ha-tab-group-tab::part(base){padding:2px 16px}:host([narrow]) .info{overflow:visible}.trace-link{text-decoration:none}ha-trace-picker{flex-grow:1;max-width:500px}`]}constructor(...t){super(...t),this.isWide=!1,this.narrow=!1,this._view="details"}}(0,o.Cg)([(0,c.MZ)({attribute:!1})],N.prototype,"hass",void 0),(0,o.Cg)([(0,c.MZ)({attribute:!1})],N.prototype,"scriptId",void 0),(0,o.Cg)([(0,c.MZ)({attribute:!1})],N.prototype,"scripts",void 0),(0,o.Cg)([(0,c.MZ)({attribute:"is-wide",type:Boolean})],N.prototype,"isWide",void 0),(0,o.Cg)([(0,c.MZ)({type:Boolean,reflect:!0})],N.prototype,"narrow",void 0),(0,o.Cg)([(0,c.MZ)({attribute:!1})],N.prototype,"route",void 0),(0,o.Cg)([(0,c.wk)(),(0,s.Fg)({context:y.ih,subscribe:!0})],N.prototype,"_entityRegistry",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_entityId",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_traces",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_runId",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_selected",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_trace",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_logbookEntries",void 0),(0,o.Cg)([(0,c.wk)()],N.prototype,"_view",void 0),(0,o.Cg)([(0,c.P)("hat-script-graph")],N.prototype,"_graph",void 0),N=(0,o.Cg)([(0,c.EM)("ha-script-trace")],N),a()}catch(t){a(t)}})}};