iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
11 lines • 36.1 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[34310],{42653:function(t,o,e){e(18111),e(61701),e(62953);var i=e(40445),r=e(5124),s=e(67576);let a,n,l,d=t=>t;class c extends r.WF{render(){return this.items.map(t=>(0,r.qy)(a||(a=d` <span><strong>${0}</strong>:</span> <span>${0}${0}</span> `),t.label,t.value,t.subValue&&t.subValue.length>0?(0,r.qy)(n||(n=d` (<pre>${0}</pre>)`),t.subValue):r.s6))}constructor(...t){super(...t),this.items=[]}}c.styles=(0,r.AH)(l||(l=d`:host{display:grid;grid-template-columns:auto 1fr;gap:6px;white-space:pre-wrap;flex-wrap:nowrap}span{display:flex;align-items:center;flex-flow:wrap;word-wrap:break-word}pre{margin:0 3px;padding:3px;background-color:var(--markdown-code-background-color,none);border-radius:var(--ha-border-radius-sm);line-height:var(--ha-line-height-condensed)}`)),(0,i.Cg)([(0,s.MZ)({attribute:!1})],c.prototype,"items",void 0),c=(0,i.Cg)([(0,s.EM)("ha-code-editor-completion-items")],c)},15717:function(t,o,e){e.a(t,async function(t,i){try{e.r(o),e.d(o,{HaCodeEditor:function(){return j}});e(89463),e(16280),e(44114),e(26910),e(13609),e(18111),e(22489),e(61701),e(3362),e(84864),e(57465),e(27495),e(17642),e(58004),e(33853),e(45876),e(32475),e(15024),e(31698),e(42762),e(62953);var r=e(40445),s=e(40158),a=e(9657),n=e(57644),l=e(5124),d=e(67576),c=e(22786),h=e(35211),p=e(1087),u=e(57237),m=e(28455),_=e(37981),f=e(65522),v=e(55931),b=e(63130),g=e(14503),C=e(81619),y=e(36918),M=e(22792),x=(e(42653),e(47680),e(9882)),w=t([s,x,n,a]);[s,x,n,a]=w.then?(await w)():w;let k,I,L,F=t=>t;const H="M19.5,3.09L15,7.59V4H13V11H20V9H16.41L20.91,4.5L19.5,3.09M4,13V15H7.59L3.09,19.5L4.5,20.91L9,16.41V20H11V13H4Z",S="M10,21V19H6.41L10.91,14.5L9.5,13.09L5,17.59V14H3V21H10M14.5,10.91L19,6.41V10H21V3H14V5H17.59L13.09,9.5L14.5,10.91Z",V="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z",E="M14,12H10V10H14M14,16H10V14H14M20,8H17.19C16.74,7.22 16.12,6.55 15.37,6.04L17,4.41L15.59,3L13.42,5.17C12.96,5.06 12.5,5 12,5C11.5,5 11.04,5.06 10.59,5.17L8.41,3L7,4.41L8.62,6.04C7.88,6.55 7.26,7.22 6.81,8H4V10H6.09C6.04,10.33 6,10.66 6,11V12H4V14H6V15C6,15.34 6.04,15.67 6.09,16H4V18H6.81C7.85,19.79 9.78,21 12,21C14.22,21 16.15,19.79 17.19,18H20V16H17.91C17.96,15.67 18,15.34 18,15V14H20V12H18V11C18,10.66 17.96,10.33 17.91,10H20V8Z",T="M20,8H17.19C16.74,7.2 16.12,6.5 15.37,6L17,4.41L15.59,3L13.42,5.17C12.96,5.06 12.5,5 12,5C11.5,5 11.05,5.06 10.59,5.17L8.41,3L7,4.41L8.62,6C7.87,6.5 7.26,7.21 6.81,8H4V10H6.09C6.03,10.33 6,10.66 6,11V12H4V14H6V15C6,15.34 6.03,15.67 6.09,16H4V18H6.81C8.47,20.87 12.14,21.84 15,20.18C15.91,19.66 16.67,18.9 17.19,18H20V16H17.91C17.97,15.67 18,15.34 18,15V14H20V12H18V11C18,10.66 17.97,10.33 17.91,10H20V8M16,15A4,4 0 0,1 12,19A4,4 0 0,1 8,15V11A4,4 0 0,1 12,7A4,4 0 0,1 16,11V15M14,10V12H10V10H14M10,14H14V16H10V14Z",A="M11,6C12.38,6 13.63,6.56 14.54,7.46L12,10H18V4L15.95,6.05C14.68,4.78 12.93,4 11,4C7.47,4 4.57,6.61 4.08,10H6.1C6.56,7.72 8.58,6 11,6M16.64,15.14C17.3,14.24 17.76,13.17 17.92,12H15.9C15.44,14.28 13.42,16 11,16C9.62,16 8.37,15.44 7.46,14.54L10,12H4V18L6.05,15.95C7.32,17.22 9.07,18 11,18C12.55,18 14,17.5 15.14,16.64L20,21.5L21.5,20L16.64,15.14Z",$="M18.4,10.6C16.55,9 14.15,8 11.5,8C6.85,8 2.92,11.03 1.54,15.22L3.9,16C4.95,12.81 7.95,10.5 11.5,10.5C13.45,10.5 15.23,11.22 16.62,12.38L13,16H22V7L18.4,10.6Z",P="M12.5,8C9.85,8 7.45,9 5.6,10.6L2,7V16H11L7.38,12.38C8.77,11.22 10.54,10.5 12.5,10.5C16.04,10.5 19.05,12.81 20.1,16L22.47,15.22C21.08,11.03 17.15,8 12.5,8Z",R={key:"Mod-s",run:t=>((0,p.r)(t.dom,"editor-save"),!0)},D=t=>{const o=document.createElement("ha-icon");return o.icon=t.label,o};class j extends l.mN{set value(t){this._value=t}get value(){return this.codemirror?this.codemirror.state.doc.toString():this._value}get hasComments(){if(!this.codemirror||!this._loadedCodeMirror)return!1;const t=this._loadedCodeMirror.highlightingFor(this.codemirror.state,[this._loadedCodeMirror.tags.comment]);return!!this.renderRoot.querySelector(`span.${t}`)}setYamlError(t){if(!this.codemirror||!this._loadedCodeMirror)return;let o=[];if(t){var e,i;const r=this.codemirror.state.doc,s=t.mark?Math.min(t.mark.position,r.length):0,a=r.lineAt(s),n=`${t.reason||(null===(e=this._i18n)||void 0===e?void 0:e.localize("ui.components.yaml-editor.error"))||"YAML syntax error"}${t.mark?` (${null===(i=this._i18n)||void 0===i?void 0:i.localize("ui.components.yaml-editor.error_location",{line:t.mark.line+1,column:t.mark.column+1})})`:""}`;o=[{from:s,to:a.to,severity:"error",message:n}]}this.codemirror.dispatch(this._loadedCodeMirror.setDiagnostics(this.codemirror.state,o))}connectedCallback(){super.connectedCallback(),this.classList.toggle("in-dialog",this.inDialog),this.hasUpdated&&this.requestUpdate(),this.addEventListener("keydown",u.d),this.addEventListener("keydown",this._handleKeyDown),this.codemirror&&!1!==this.autofocus&&this.codemirror.focus()}disconnectedCallback(){var t;(0,p.r)(this,"dialog-set-fullscreen",!1),this._clearCompletionInfo(),void 0!==this._completionInfoFrame&&(cancelAnimationFrame(this._completionInfoFrame),this._completionInfoFrame=void 0),null===(t=this._completionInfoPopover)||void 0===t||t.remove(),this._completionInfoPopover=void 0,this._completionInfoContainer=void 0,super.disconnectedCallback(),this.removeEventListener("keydown",u.d),this.removeEventListener("keydown",this._handleKeyDown),this._updateFullscreenState(!1),this.updateComplete.then(()=>{this.codemirror.destroy(),delete this.codemirror})}async scheduleUpdate(){var t;null!==(t=this._loadedCodeMirror)&&void 0!==t||(this._loadedCodeMirror=await Promise.all([e.e(35017),e.e(92700)]).then(e.bind(e,61527))),super.scheduleUpdate()}update(t){if(super.update(t),!this.codemirror)return void this._createCodeMirror();const o=[];t.has("mode")&&o.push({effects:[this._loadedCodeMirror.langCompartment.reconfigure(this._mode),this._loadedCodeMirror.yamlLintCompartment.reconfigure(this.lint&&!this.readOnly?[this._loadedCodeMirror.lintGutter()]:[])]}),t.has("readOnly")&&(o.push({effects:[this._loadedCodeMirror.readonlyCompartment.reconfigure(this._loadedCodeMirror.EditorView.editable.of(!this.readOnly)),this._loadedCodeMirror.yamlLintCompartment.reconfigure(this.lint&&!this.readOnly?[this._loadedCodeMirror.lintGutter()]:[])]}),this._updateToolbarButtons()),t.has("lint")&&o.push({effects:this._loadedCodeMirror.yamlLintCompartment.reconfigure(this.lint&&!this.readOnly?[this._loadedCodeMirror.lintGutter()]:[])}),t.has("linewrap")&&o.push({effects:this._loadedCodeMirror.linewrapCompartment.reconfigure(this.linewrap?this._loadedCodeMirror.EditorView.lineWrapping:[])}),t.has("_value")&&this._value!==this.value&&o.push({changes:{from:0,to:this.codemirror.state.doc.length,insert:this._value}}),o.length>0&&this.codemirror.dispatch(...o),t.has("hasToolbar")&&this._updateToolbar(),t.has("error")&&this.classList.toggle("error-state",this.error),t.has("inDialog")&&this.classList.toggle("in-dialog",this.inDialog),t.has("_isFullscreen")&&(this.classList.toggle("fullscreen",this._isFullscreen),this._updateToolbarButtons()),(t.has("_canCopy")||t.has("_canUndo")||t.has("_canRedo")||t.has("testing"))&&this._updateToolbarButtons(),t.has("disableFullscreen")&&this._updateFullscreenState()}get _mode(){return this._loadedCodeMirror.langs[this.mode]}_createCodeMirror(){var t;if(!this._loadedCodeMirror)throw new Error("Cannot create editor before CodeMirror is loaded");const o=[this._loadedCodeMirror.lineNumbers(),this._loadedCodeMirror.foldGutter(),this._loadedCodeMirror.bracketMatching(),this._loadedCodeMirror.history(),this._loadedCodeMirror.drawSelection(),this._loadedCodeMirror.EditorState.allowMultipleSelections.of(!0),this._loadedCodeMirror.rectangularSelection(),this._loadedCodeMirror.crosshairCursor(),this._loadedCodeMirror.highlightSelectionMatches(),this._loadedCodeMirror.highlightActiveLine(),this._loadedCodeMirror.dropCursor(),this._loadedCodeMirror.indentationMarkers({thickness:0,activeThickness:1,colors:{activeLight:"var(--secondary-text-color)",activeDark:"var(--secondary-text-color)"}}),this._loadedCodeMirror.keymap.of([...this.readOnly?[]:this._loadedCodeMirror.closeBracketsKeymap,...this._loadedCodeMirror.defaultKeymap,...this._loadedCodeMirror.searchKeymap,...this._loadedCodeMirror.historyKeymap,...this._loadedCodeMirror.tabKeyBindings,...this._loadedCodeMirror.lintKeymap,R]),this._loadedCodeMirror.search({top:!0}),this._loadedCodeMirror.langCompartment.of(this._mode),this._loadedCodeMirror.haTheme,this._loadedCodeMirror.haSyntaxHighlighting,this._loadedCodeMirror.yamlScalarHighlighter,this._loadedCodeMirror.yamlScalarHighlightStyle,this._loadedCodeMirror.readonlyCompartment.of(this._loadedCodeMirror.EditorView.editable.of(!this.readOnly)),this._loadedCodeMirror.linewrapCompartment.of(this.linewrap?this._loadedCodeMirror.EditorView.lineWrapping:[]),this._loadedCodeMirror.yamlLintCompartment.of(this.lint&&!this.readOnly?[this._loadedCodeMirror.lintGutter()]:[]),this._loadedCodeMirror.EditorView.updateListener.of(this._onUpdate),this._loadedCodeMirror.tooltips({position:"absolute"}),this._loadedCodeMirror.hoverTooltip((t,o)=>this._loadedCodeMirror.haJinjaHoverSource(t,o,this._config?(0,y.o)(this._config,""):void 0,this._hassArgHoverContext()),{hoverTime:300}),...this.placeholder?[(0,n.qf)(this.placeholder)]:[]];if(!this.readOnly){const t=[this._loadedCodeMirror.haJinjaCompletionSource];this.autocompleteEntities&&t.push(this._entityCompletions.bind(this)),this.autocompleteIcons&&t.push(this._mdiCompletions.bind(this)),o.push(this._loadedCodeMirror.autocompletion({override:t,maxRenderedOptions:10}),this._loadedCodeMirror.closeBrackets(),this._loadedCodeMirror.closeBracketsOverride,this._loadedCodeMirror.closePercentBrace)}this.codemirror=new this._loadedCodeMirror.EditorView({state:this._loadedCodeMirror.EditorState.create({doc:this._value,extensions:o}),parent:this.renderRoot}),this._canCopy=(null===(t=this._value)||void 0===t?void 0:t.length)>0;const e=this.codemirror.dom.querySelector(".cm-scroller");e&&e.classList.add("ha-scrollbar"),this._updateToolbar()}_fullscreenLabel(){var t,o;return this._isFullscreen?(null===(o=this._i18n)||void 0===o?void 0:o.localize("ui.components.yaml-editor.exit_fullscreen"))||"Exit fullscreen":(null===(t=this._i18n)||void 0===t?void 0:t.localize("ui.components.yaml-editor.enter_fullscreen"))||"Enter fullscreen"}_fullscreenIcon(){return this._isFullscreen?H:S}_createEditorToolbar(){const t=document.createElement("ha-icon-button-toolbar");return t.classList.add("code-editor-toolbar"),t.items=[],t}_updateToolbar(){var t;this.classList.toggle("hasToolbar",this.hasToolbar),this._updateFullscreenState(),this.hasToolbar&&(this._editorToolbar||(this._editorToolbar=this._createEditorToolbar()),this._updateToolbarButtons(),null===(t=this.codemirror)||void 0===t||t.dom.appendChild(this._editorToolbar))}_updateToolbarButtons(){var t,o,e,i,r;this._editorToolbar&&(this._editorToolbar.items=[...this.hasTest&&!this._isFullscreen?[{id:"test",label:(null===(t=this._i18n)||void 0===t?void 0:t.localize("ui.components.yaml-editor.test_"+(this.testing?"off":"on")))||"Test",path:this.testing?T:E,action:t=>this._handleTestClick(t)}]:[],{id:"undo",disabled:!this._canUndo,label:(null===(o=this._i18n)||void 0===o?void 0:o.localize("ui.common.undo"))||"Undo",path:P,action:t=>this._handleUndoClick(t)},{id:"redo",disabled:!this._canRedo,label:(null===(e=this._i18n)||void 0===e?void 0:e.localize("ui.common.redo"))||"Redo",path:$,action:t=>this._handleRedoClick(t)},{id:"copy",disabled:!this._canCopy,label:(null===(i=this._i18n)||void 0===i?void 0:i.localize("ui.components.yaml-editor.copy_to_clipboard"))||"Copy to Clipboard",path:V,action:t=>this._handleClipboardClick(t)},{id:"find-replace",label:(null===(r=this._i18n)||void 0===r?void 0:r.localize("ui.components.yaml-editor.find_and_replace"))||"Find and replace",path:A,action:t=>this._handleFindReplaceClick(t)},{id:"fullscreen",disabled:this.disableFullscreen,label:this._fullscreenLabel(),path:this._fullscreenIcon(),action:t=>this._handleFullscreenClick(t)}])}_updateFullscreenState(t=this._isFullscreen){const o=this._isFullscreen;return this.classList.toggle("in-dialog",this.inDialog),this._isFullscreen=t&&!this.disableFullscreen&&this.hasToolbar,o!==this._isFullscreen&&(0,p.r)(this,"dialog-set-fullscreen",this._isFullscreen),this._isFullscreen===t}_hassArgHoverContext(){var t,o,e,i;const r={};for(const a of null!==(s=this._labels)&&void 0!==s?s:[]){var s;r[a.label_id]={name:a.name,description:a.description}}return{states:this._states,devices:null===(t=this._registries)||void 0===t?void 0:t.devices,areas:null===(o=this._registries)||void 0===o?void 0:o.areas,floors:null===(e=this._registries)||void 0===e?void 0:e.floors,entities:null===(i=this._registries)||void 0===i?void 0:i.entities,labels:r,formatEntityState:t=>this._formatters.formatEntityState(this._states[t]),formatEntityName:t=>{var o,e,i,r;const s=null===(o=this._states)||void 0===o?void 0:o[t];return null!==(e=null!==(i=null==s?void 0:s.attributes.friendly_name)&&void 0!==i?i:null===(r=this._registries)||void 0===r||null===(r=r.entities)||void 0===r||null===(r=r[t])||void 0===r?void 0:r.name)&&void 0!==e?e:void 0},formatAttributeName:(t,o)=>this._formatters.formatEntityAttributeName(this._states[t],o),formatAttributeValue:(t,o)=>this._formatters.formatEntityAttributeValue(this._states[t],o),localize:t=>this._i18n.localize(t)}}_ensureCompletionInfoPopover(){return this._completionInfoPopover||(this._completionInfoPopover=document.createElement("wa-popup"),this._completionInfoPopover.classList.add("completion-info-popover"),this._completionInfoPopover.placement="right-start",this._completionInfoPopover.distance=4,this._completionInfoPopover.flip=!0,this._completionInfoPopover.flipFallbackPlacements="left-start bottom-start top-start",this._completionInfoPopover.shift=!0,this._completionInfoPopover.shiftPadding=8,this._completionInfoPopover.autoSize="both",this._completionInfoPopover.autoSizePadding=8,this._completionInfoContainer=document.createElement("div"),this._completionInfoPopover.appendChild(this._completionInfoContainer),this.renderRoot.appendChild(this._completionInfoPopover)),this._completionInfoPopover}_clearCompletionInfo(){var t,o,e;this._completionInfoRequest+=1,this._completionInfoKey=void 0,null===(t=this._completionInfoDestroy)||void 0===t||t.call(this),this._completionInfoDestroy=void 0,null===(o=this._completionInfoContainer)||void 0===o||o.replaceChildren(),null!==(e=this._completionInfoPopover)&&void 0!==e&&e.active&&(this._completionInfoPopover.active=!1)}_renderCompletionInfoContent(t){var o;null===(o=this._completionInfoDestroy)||void 0===o||o.call(this),this._completionInfoDestroy=void 0,this._completionInfoContainer&&(null!==t?"nodeType"in t?this._completionInfoContainer.replaceChildren(t):(this._completionInfoContainer.replaceChildren(t.dom),this._completionInfoDestroy=t.destroy):this._completionInfoContainer.replaceChildren())}get _jinjaFunctionArgTypes(){return this._loadedCodeMirror.JINJA_FUNCTION_ARG_TYPES}_statesDotNotationCompletions(t){var o;if(!this._states)return;const{state:e,pos:i}=t,r=this._loadedCodeMirror.syntaxTree(e).resolveInner(i,-1),s=r.parent;let a;if("PropertyName"===r.name&&"MemberExpression"===(null==s?void 0:s.name))a=r.from;else{if("."!==r.name||"MemberExpression"!==(null==s?void 0:s.name))return;a=i}const n=[];let l=s,d="PropertyName"===r.name;for(;"MemberExpression"===(null===(c=l)||void 0===c?void 0:c.name);){var c;let t=l.lastChild;for(;t&&"PropertyName"!==t.name;)t=t.prevSibling;t&&(d?d=!1:n.unshift(e.doc.sliceString(t.from,t.to)));const o=l.firstChild;if(!o)break;if("VariableName"===o.name){if("states"!==e.doc.sliceString(o.from,o.to))return;break}if("MemberExpression"!==o.name)return;l=o}const h=null===(o=l)||void 0===o?void 0:o.firstChild;if(!h||"VariableName"!==h.name)return;if("states"!==e.doc.sliceString(h.from,h.to))return;switch(n.length){case 0:return{from:a,options:[...new Set(Object.keys(this._states).map(t=>t.split(".")[0]))].sort().map(t=>({label:t,type:"variable"})),validFor:/^\w*$/};case 1:{const[t]=n,o=Object.keys(this._states).filter(o=>o.startsWith(`${t}.`)).map(t=>t.split(".").slice(1).join("."));return o.length?{from:a,options:o.map(t=>({label:t,type:"variable"})),validFor:/^\w*$/}:{from:a,options:[]}}case 2:return{from:a,options:j._STATE_FIELDS.map(t=>({label:t,type:"property"})),validFor:/^\w*$/};case 3:{const[t,o,e]=n;if("attributes"!==e)return{from:a,options:[]};const i=`${t}.${o}`,r=this._states[i];if(!r)return{from:a,options:[]};return{from:a,options:Object.keys(r.attributes).sort().map(t=>({label:t,type:"property"})),validFor:/^\w*$/}}default:return{from:a,options:[]}}}_jinjaStringArgCompletions(t){var o;const{state:e,pos:i}=t,r=this._loadedCodeMirror.syntaxTree(e).resolveInner(i,-1);if("StringLiteral"!==r.name)return;const s=r.parent;if("SubscriptExpression"===(null==s?void 0:s.name)){const t=s.firstChild;if(t&&"states"===e.doc.sliceString(t.from,t.to))return this._completionResultForArgType("entity_id",r)}const a=r.parent;if("ArgumentList"!==(null==a?void 0:a.name))return;const n=a.parent;if("CallExpression"!==(null==n?void 0:n.name))return;const l=n.firstChild;if(!l)return;const d=e.doc.sliceString(l.from,l.to),c=this._jinjaFunctionArgTypes.get(d);if(!c)return;let h=0,p=null===(o=a.firstChild)||void 0===o?void 0:o.nextSibling;for(;p&&")"!==p.name;){if(","!==p.name){if(p.from===r.from)break;h++}p=p.nextSibling}const u=c.get(h);if(u){if("attribute"===u){const t=this._entityIdFromSiblingArg(a,c,e);return this._attributeCompletionResult(r,t)}return this._completionResultForArgType(u,r)}}_entityIdFromSiblingArg(t,o,e){var i;let r;for(const[n,l]of o)if("entity_id"===l){r=n;break}if(void 0===r)return null;let s=0,a=null===(i=t.firstChild)||void 0===i?void 0:i.nextSibling;for(;a&&")"!==a.name;){if(","!==a.name){if(s===r){if("StringLiteral"!==a.name)return null;return e.doc.sliceString(a.from,a.to).slice(1,-1)}s++}a=a.nextSibling}return null}_completionResultForArgType(t,o){var e,i,r,s,a;const n={from:o.from+1,options:[]};switch(t){case"entity_id":return null!==(e=this._entityCompletionResult(o))&&void 0!==e?e:n;case"device_id":return null!==(i=this._deviceCompletionResult(o))&&void 0!==i?i:n;case"area_id":return null!==(r=this._areaCompletionResult(o))&&void 0!==r?r:n;case"floor_id":return null!==(s=this._floorCompletionResult(o))&&void 0!==s?s:n;case"label_id":return null!==(a=this._labelCompletionResult(o))&&void 0!==a?a:n;default:return n}}_attributeCompletionResult(t,o){const e=t.from+1,i={from:e,options:[]};if(!o||!this._states)return i;const r=this._states[o];if(!r)return i;const s=Object.keys(r.attributes).sort();return s.length?{from:e,options:s.map(t=>({label:t,type:"property",info:()=>this._renderAttributeInfo(o,t)})),validFor:/^[\w.]*$/}:i}_entityCompletionResult(t){const o=this._getStates(this._states);if(null==o||!o.length)return null;return{from:t.from+1,options:o,validFor:/^[\w.]*$/}}_deviceCompletionResult(t){var o;if(null===(o=this._registries)||void 0===o||!o.devices)return null;const e=this._getDevices(this._registries.devices);return e.length?{from:t.from+1,options:e,validFor:/^[^"]*$/}:null}_areaCompletionResult(t){var o;if(null===(o=this._registries)||void 0===o||!o.areas)return null;const e=this._getAreas(this._registries.areas);return e.length?{from:t.from+1,options:e,validFor:/^[^"]*$/}:null}_floorCompletionResult(t){var o;if(null===(o=this._registries)||void 0===o||!o.floors)return null;const e=this._getFloors(this._registries.floors);return e.length?{from:t.from+1,options:e,validFor:/^[^"]*$/}:null}_labelCompletionResult(t){var o;if(null===(o=this._labels)||void 0===o||!o.length)return null;const e=this._getLabels(this._labels);return e.length?{from:t.from+1,options:e,validFor:/^[^"]*$/}:null}_entityCompletions(t){if("yaml"===this.mode||"jinja2"===this.mode){const o=this._statesDotNotationCompletions(t);if(void 0!==o)return o;const e=this._jinjaStringArgCompletions(t);if(void 0!==e)return e}if("yaml"===this.mode){const o=t.state.doc.lineAt(t.pos),e=o.text,i=["entity_id","entity","entities","badges","devices","lights","light","group_members","scene","zone","zones"].join("|"),r=new RegExp(`^\\s*(-\\s+)?(${i}):\\s*`),s=e.match(r),a=e.match(/^\s*-\s+/);if(s){const e=o.from+s[0].length,i=e>0&&":"===t.state.doc.sliceString(e-1,e);if(t.pos>=e){const o=this._getStates(this._states);if(!o||!o.length)return null;const r=t.state.sliceDoc(e,t.pos),s=r?o.filter(t=>{var o;return null===(o=t.displayLabel)||void 0===o?void 0:o.toLowerCase().startsWith(r.toLowerCase())}):o;return{from:e,options:i?s.map(t=>Object.assign(Object.assign({},t),{},{apply:` ${t.label}`})):s,validFor:/^[a-z_]*\.?\w*$/}}}else if(a){const e=o.number;for(let r=e-1;r>0&&r>=e-10;r--){const e=t.state.doc.line(r).text;if(e.trim()&&!e.startsWith(" ")&&!e.startsWith("\t"))break;const s=new RegExp(`^\\s*(${i}):\\s*$`);if(e.match(s)){const e=o.from+a[0].length;if(t.pos>=e){const o=this._getStates(this._states);if(!o||!o.length)return null;const i=t.state.sliceDoc(e,t.pos);return{from:e,options:i?o.filter(t=>{var o;return null===(o=t.displayLabel)||void 0===o?void 0:o.toLowerCase().startsWith(i.toLowerCase())}):o,validFor:/^[a-z_]*\.?\w*$/}}}}}const n=["action"].join("|"),l=new RegExp(`^\\s*(-\\s+)?(${n}):\\s*`);if(e.match(l))return null}if("jinja2"===this.mode)return null;const o=t.matchBefore(/[a-z_]{3,}\.\w*/);if(!o||o.from===o.to&&!t.explicit)return null;const e=this._getStates(this._states);return e&&e.length?{from:Number(o.from),options:e,validFor:/^[a-z_]{3,}\.\w*$/}:null}async _mdiCompletions(t){const o=t.matchBefore(/mdi:\S*/);if(!o||o.from===o.to&&!t.explicit)return null;const e=await this._getIconItems();return{from:Number(o.from),options:e,validFor:/^mdi:\S*$/}}static get styles(){return[g.dp,(0,l.AH)(k||(k=F`:host{position:relative;display:block;--code-editor-toolbar-height:28px}:host(.error-state) .cm-gutters{border-color:var(--error-state-color,var(--error-color))!important}:host(.hasToolbar) .cm-gutters{padding-top:0}:host(.hasToolbar) .cm-focused .cm-gutters{padding-top:1px}:host(.error-state) .cm-content{border-color:var(--error-state-color,var(--error-color))!important}:host(.hasToolbar) .cm-content{border:none;border-top:1px solid var(--secondary-text-color)}:host(.hasToolbar) .cm-focused .cm-content{border-top:2px solid var(--primary-color);padding-top:15px}:host(.fullscreen){position:fixed!important;top:calc(var(--header-height,56px) + var(--ha-space-2))!important;left:var(--ha-space-2)!important;right:var(--ha-space-2)!important;bottom:var(--ha-space-2)!important;z-index:6;border-radius:var(--ha-border-radius-lg)!important;box-shadow:0 2px 10px rgba(0,0,0,.3)!important;overflow:hidden!important;background-color:var(--code-editor-background-color,var(--card-background-color))!important;margin:0!important;padding-top:var(--safe-area-inset-top)!important;padding-left:var(--safe-area-inset-left)!important;padding-right:var(--safe-area-inset-right)!important;padding-bottom:var(--safe-area-inset-bottom)!important;box-sizing:border-box!important;display:block!important}:host(.in-dialog.fullscreen){position:absolute!important;top:0!important;left:0!important;right:0!important;bottom:0!important;border-radius:0!important;box-shadow:none!important;padding:0!important}:host(.hasToolbar) .cm-editor{padding-top:var(--code-editor-toolbar-height)}:host(.fullscreen) .cm-editor{height:100%!important;max-height:100%!important;border-radius:var(--ha-border-radius-square)!important}:host(:not(.hasToolbar)) .code-editor-toolbar{display:none!important}.code-editor-toolbar{--icon-button-toolbar-height:var(--code-editor-toolbar-height);--icon-button-toolbar-color:var(
--code-editor-gutter-color,
var(--secondary-background-color, whitesmoke)
);border-top-left-radius:var(--ha-border-radius-sm);border-top-right-radius:var(--ha-border-radius-sm)}.completion-info{display:grid;gap:3px;padding:8px}wa-popup.completion-info-popover{--auto-size-available-width:min(
420px,
calc(var(--safe-width) - var(--ha-space-8))
)}wa-popup.completion-info-popover::part(popup){padding:0;color:var(--primary-text-color);background-color:var(--code-editor-background-color,var(--card-background-color));border:1px solid var(--divider-color);border-radius:var(--mdc-shape-medium,4px);box-shadow:0px 5px 5px -3px rgb(0 0 0 / 20%),0px 8px 10px 1px rgb(0 0 0 / 14%),0px 3px 14px 2px rgb(0 0 0 / 12%)} (max-width:600px){.completion-info,wa-popup.completion-info-popover{display:none}}`))]}constructor(...t){super(...t),this.mode="yaml",this.autofocus=!1,this.readOnly=!1,this.linewrap=!1,this.autocompleteEntities=!1,this.autocompleteIcons=!1,this.error=!1,this.lint=!1,this.disableFullscreen=!1,this.inDialog=!1,this.hasToolbar=!0,this.hasTest=!1,this.testing=!1,this._value="",this._isFullscreen=!1,this._canUndo=!1,this._canRedo=!1,this._canCopy=!1,this._completionInfoRequest=0,this._handleClipboardClick=async t=>{var o;(t.preventDefault(),t.stopPropagation(),this.value)&&(await(0,b.l)(this.value),(0,C.P)(this,{message:(null===(o=this._i18n)||void 0===o?void 0:o.localize("ui.common.copied_clipboard"))||"Copied to clipboard"}))},this._handleTestClick=t=>{t.preventDefault(),t.stopPropagation(),this.codemirror&&(0,p.r)(this,"test-toggle")},this._handleUndoClick=t=>{t.preventDefault(),t.stopPropagation(),this.codemirror&&(0,a.tN)(this.codemirror)},this._handleRedoClick=t=>{t.preventDefault(),t.stopPropagation(),this.codemirror&&(0,a.ZS)(this.codemirror)},this._handleFullscreenClick=t=>{t.preventDefault(),t.stopPropagation(),this._updateFullscreenState(!this._isFullscreen)},this._handleFindReplaceClick=t=>{if(t.preventDefault(),t.stopPropagation(),!this.codemirror||!this._loadedCodeMirror)return;this.codemirror.dom.querySelector(".cm-search")?this._loadedCodeMirror.closeSearchPanel(this.codemirror):this._loadedCodeMirror.openSearchPanel(this.codemirror)},this._handleKeyDown=t=>{("Escape"===t.key&&this._isFullscreen&&this._updateFullscreenState(!1)||"F11"===t.key&&this._updateFullscreenState(!0))&&(t.preventDefault(),t.stopPropagation())},this._renderInfo=t=>{const o="string"==typeof t.apply?t.apply:t.label,e=(0,m.ln)(this._states[o],this._registries.entities,this._registries.devices,this._registries.areas,this._registries.floors),i=document.createElement("div");i.classList.add("completion-info");const r=this._formatters.formatEntityState(this._states[o]),s=[{label:this._i18n.localize("ui.components.entity.entity-state-picker.state"),value:r,subValue:this._states[o].state===r?void 0:this._states[o].state}];return e.device&&e.device.name&&s.push({label:this._i18n.localize("ui.components.device-picker.device"),value:e.device.name}),e.area&&e.area.name&&s.push({label:this._i18n.localize("ui.components.area-picker.area"),value:e.area.name}),e.floor&&e.floor.name&&s.push({label:this._i18n.localize("ui.components.floor-picker.floor"),value:e.floor.name}),(0,l.XX)((0,l.qy)(I||(I=F` <ha-code-editor-completion-items .items="${0}"></ha-code-editor-completion-items> `),s),i),i},this._renderAttributeInfo=(t,o)=>{if(!this._states||!this._formatters)return null;const e=this._states[t];if(!e)return null;const i=this._formatters.formatEntityAttributeName(e,o),r=this._formatters.formatEntityAttributeValue(e,o),s=e.attributes[o],a=null!=s?String(s):void 0,n=[{label:i,value:r,subValue:void 0!==a&&a!==r?a:void 0}],d=document.createElement("div");return d.classList.add("completion-info"),(0,l.XX)((0,l.qy)(L||(L=F` <ha-code-editor-completion-items .items="${0}"></ha-code-editor-completion-items> `),n),d),d},this._getCompletionInfo=t=>this._states&&"string"==typeof t.apply&&t.apply in this._states?this._renderInfo(t):t.label.startsWith("mdi:")?D(t):"function"==typeof t.info?t.info(t):null,this._syncCompletionInfoPopover=()=>{void 0!==this._completionInfoFrame&&cancelAnimationFrame(this._completionInfoFrame),this._completionInfoFrame=requestAnimationFrame(()=>{this._completionInfoFrame=void 0,this._syncCompletionInfoPopoverNow()})},this._syncCompletionInfoPopoverNow=()=>{if(!this.codemirror||!this._loadedCodeMirror)return;if(window.matchMedia("(max-width: 600px)").matches)return void this._clearCompletionInfo();const t=this._loadedCodeMirror.selectedCompletion(this.codemirror.state),o=this.codemirror.dom.querySelector(".cm-tooltip-autocomplete li[aria-selected]");if(!t||!o)return void this._clearCompletionInfo();const e=this._getCompletionInfo(t);if(!e)return void this._clearCompletionInfo();const i=++this._completionInfoRequest,r=t.label,s=this._ensureCompletionInfoPopover();s.anchor=o;const a=async t=>{var o;i===this._completionInfoRequest?(r!==this._completionInfoKey&&(this._renderCompletionInfoContent(t),this._completionInfoKey=r),await s.updateComplete,s.active=!0,s.reposition()):t&&"object"==typeof t&&"destroy"in t&&(null===(o=t.destroy)||void 0===o||o.call(t))};"then"in e?e.then(a).catch(()=>{i===this._completionInfoRequest&&this._clearCompletionInfo()}):a(e).catch(()=>{i===this._completionInfoRequest&&this._clearCompletionInfo()})},this._getStates=(0,c.A)(t=>{if(!t)return[];return Object.keys(t).map(o=>({type:"variable",label:t[o].attributes.friendly_name?`${t[o].attributes.friendly_name} ${o}`:o,displayLabel:o,detail:t[o].attributes.friendly_name,apply:o}))}),this._getDevices=(0,c.A)(t=>Object.values(t).filter(t=>!t.disabled_by).map(t=>{const o=(0,_.xn)(t);return{type:"variable",label:`${o} ${t.id}`,displayLabel:null!=o?o:t.id,detail:t.id,apply:t.id}})),this._getAreas=(0,c.A)(t=>Object.values(t).map(t=>{var o;const e=null!==(o=(0,f.A)(t))&&void 0!==o?o:t.area_id;return{type:"variable",label:`${e} ${t.area_id}`,displayLabel:e,detail:t.area_id,apply:t.area_id}})),this._getFloors=(0,c.A)(t=>Object.values(t).map(t=>{var o;const e=null!==(o=(0,v.X)(t))&&void 0!==o?o:t.floor_id;return{type:"variable",label:`${e} ${t.floor_id}`,displayLabel:e,detail:t.floor_id,apply:t.floor_id}})),this._getLabels=(0,c.A)(t=>t.map(t=>{const o=t.name.trim()||t.label_id;return{type:"variable",label:`${o} ${t.label_id}`,displayLabel:o,detail:t.label_id,apply:t.label_id}})),this._getIconItems=async()=>{if(!this._iconList){const t=(await e.e(81340).then(e.t.bind(e,25143,19))).default;this._iconList=t.map(t=>({type:"variable",label:`mdi:${t.name}`,detail:t.keywords.join(", ")}))}return this._iconList},this._onUpdate=t=>{var o;this._canUndo=!this.readOnly&&(0,a.mk)(t.state)>0,this._canRedo=!this.readOnly&&(0,a.mL)(t.state)>0,this._syncCompletionInfoPopover(),t.docChanged&&(this._value=t.state.doc.toString(),this._canCopy=(null===(o=this._value)||void 0===o?void 0:o.length)>0,(0,p.r)(this,"value-changed",{value:this._value}))}}}j._STATE_FIELDS=["state","attributes","last_changed","last_updated","context","domain","object_id","name","entity_id","state_with_unit"],(0,r.Cg)([(0,d.MZ)()],j.prototype,"mode",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean})],j.prototype,"autofocus",void 0),(0,r.Cg)([(0,d.MZ)({attribute:"read-only",type:Boolean})],j.prototype,"readOnly",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean})],j.prototype,"linewrap",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean,attribute:"autocomplete-entities"})],j.prototype,"autocompleteEntities",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean,attribute:"autocomplete-icons"})],j.prototype,"autocompleteIcons",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean})],j.prototype,"error",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean})],j.prototype,"lint",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean,attribute:"disable-fullscreen"})],j.prototype,"disableFullscreen",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean,attribute:"in-dialog"})],j.prototype,"inDialog",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean,attribute:"has-toolbar"})],j.prototype,"hasToolbar",void 0),(0,r.Cg)([(0,d.MZ)({type:Boolean,attribute:"has-test"})],j.prototype,"hasTest",void 0),(0,r.Cg)([(0,d.MZ)({attribute:!1})],j.prototype,"testing",void 0),(0,r.Cg)([(0,d.MZ)({type:String})],j.prototype,"placeholder",void 0),(0,r.Cg)([(0,d.wk)()],j.prototype,"_value",void 0),(0,r.Cg)([(0,d.wk)()],j.prototype,"_isFullscreen",void 0),(0,r.Cg)([(0,d.wk)()],j.prototype,"_canUndo",void 0),(0,r.Cg)([(0,d.wk)()],j.prototype,"_canRedo",void 0),(0,r.Cg)([(0,d.wk)()],j.prototype,"_canCopy",void 0),(0,r.Cg)([(0,d.wk)(),(0,h.Fg)({context:M.WF,subscribe:!0})],j.prototype,"_config",void 0),(0,r.Cg)([(0,d.wk)(),(0,h.Fg)({context:M.D5,subscribe:!0})],j.prototype,"_i18n",void 0),(0,r.Cg)([(0,d.wk)(),(0,h.Fg)({context:M.HD,subscribe:!0})],j.prototype,"_labels",void 0),(0,r.Cg)([(0,d.wk)(),(0,h.Fg)({context:M.Hd,subscribe:!0})],j.prototype,"_registries",void 0),(0,r.Cg)([(0,d.wk)(),(0,h.Fg)({context:M.p0,subscribe:!0})],j.prototype,"_formatters",void 0),(0,r.Cg)([(0,d.wk)(),(0,h.Fg)({context:M.iN,subscribe:!0})],j.prototype,"_states",void 0),j=(0,r.Cg)([(0,d.EM)("ha-code-editor")],j),i()}catch(k){i(k)}})},39826:function(t,o,e){e.r(o),e.d(o,{HaIconButtonGroup:function(){return d}});var i=e(40445),r=e(5124),s=e(67576);let a,n,l=t=>t;class d extends r.WF{render(){return(0,r.qy)(a||(a=l`<slot></slot>`))}}d.styles=(0,r.AH)(n||(n=l`:host{position:relative;display:flex;flex-direction:row;align-items:center;height:48px;border-radius:var(--ha-border-radius-4xl);background-color:rgba(139,145,151,.1);box-sizing:border-box;width:auto;padding:0}::slotted(.separator){background-color:rgba(var(--rgb-primary-text-color),.15);width:1px;margin:0 1px;height:40px}`)),d=(0,i.Cg)([(0,s.EM)("ha-icon-button-group")],d)},9882:function(t,o,e){e.a(t,async function(t,i){try{e.r(o),e.d(o,{HaIconButtonToolbar:function(){return _}});e(18111),e(22489),e(61701),e(62953);var r=e(40445),s=e(5124),a=e(67576),n=(e(47680),e(26300)),l=(e(39826),e(34127)),d=t([n,l]);[n,l]=d.then?(await d)():d;let c,h,p,u,m=t=>t;class _ extends s.WF{findToolbarButtons(t=""){var o;const e=null===(o=this._buttons)||void 0===o?void 0:o.filter(t=>t.classList.contains("icon-toolbar-button"));if(!e||!e.length)return;if(!t.length)return e;const i=e.filter(o=>o.querySelector(t));return i.length?i:void 0}findToolbarButtonById(t){var o;const e=null===(o=this.shadowRoot)||void 0===o?void 0:o.getElementById(t);if(e&&"ha-icon-button"===e.localName)return e}render(){return(0,s.qy)(c||(c=m` <ha-icon-button-group class="icon-toolbar-buttongroup"> ${0} </ha-icon-button-group> `),this.items.map(t=>{var o,e,i,r;return"string"==typeof t?(0,s.qy)(h||(h=m`<div class="icon-toolbar-divider" role="separator"></div>`)):(0,s.qy)(p||(p=m`<ha-tooltip .disabled="${0}" .for="${0}">${0}</ha-tooltip> <ha-icon-button class="icon-toolbar-button" .id="${0}" ="${0}" .label="${0}" .path="${0}" .disabled="${0}"></ha-icon-button>`),!t.tooltip,null!==(o=t.id)&&void 0!==o?o:"icon-button-"+t.label,null!==(e=t.tooltip)&&void 0!==e?e:"",null!==(i=t.id)&&void 0!==i?i:"icon-button-"+t.label,t.action,t.label,t.path,null!==(r=t.disabled)&&void 0!==r&&r)}))}constructor(...t){super(...t),this.items=[]}}_.styles=(0,s.AH)(u||(u=m`:host{position:absolute;top:0px;width:100%;display:flex;flex-direction:row-reverse;background-color:var(--icon-button-toolbar-color,var(--secondary-background-color,#f5f5f5));--icon-button-toolbar-height:32px;--icon-button-toolbar-button:calc(
var(--icon-button-toolbar-height) - 4px
);--icon-button-toolbar-icon:calc(
var(--icon-button-toolbar-height) - 10px
)}.icon-toolbar-divider{height:var(--icon-button-toolbar-icon);margin:0px 4px;border:.5px solid var(--divider-color,var(--secondary-text-color,transparent))}.icon-toolbar-buttongroup{background-color:transparent;padding-right:4px;height:var(--icon-button-toolbar-height);gap:var(--ha-space-2)}.icon-toolbar-button{color:var(--secondary-text-color);--ha-icon-button-size:var(--icon-button-toolbar-button);--mdc-icon-size:var(--icon-button-toolbar-icon);cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation}`)),(0,r.Cg)([(0,a.MZ)({attribute:!1})],_.prototype,"items",void 0),(0,r.Cg)([(0,a.YG)("ha-icon-button")],_.prototype,"_buttons",void 0),_=(0,r.Cg)([(0,a.EM)("ha-icon-button-toolbar")],_),i()}catch(c){i(c)}})}}]);