iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
2 lines • 19 kB
JavaScript
/*! For license information please see 23331.2fb66c34d2009045.js.LICENSE.txt */
export const __rspack_esm_id=23331;export const __rspack_esm_ids=[23331];export const __webpack_modules__={65522(e,t,i){i.d(t,{A:()=>o});const o=e=>e.name?.trim()},55931(e,t,i){i.d(t,{X:()=>o});const o=e=>e.name?.trim()},78978(e,t,i){i.d(t,{_:()=>r});i(44114),i(33110);var o=i(63533);const r=(e,t)=>{if(!(t instanceof o.C5))return{warnings:[t.message],errors:void 0};const i=[],r=[];for(const o of t.failures())if(void 0===o.value)i.push(e.localize("ui.errors.config.key_missing",{key:o.path.join(".")}));else if("never"===o.type)r.push(e.localize("ui.errors.config.key_not_expected",{key:o.path.join(".")}));else{if("union"===o.type)continue;"enums"===o.type?r.push(e.localize("ui.errors.config.key_wrong_type",{key:o.path.join("."),type_correct:o.message.replace("Expected ","").split(", ")[0],type_wrong:JSON.stringify(o.value)})):r.push(e.localize("ui.errors.config.key_wrong_type",{key:o.path.join("."),type_correct:o.refinement||o.type,type_wrong:JSON.stringify(o.value)}))}return{warnings:r,errors:i}}},63130(e,t,i){i.d(t,{l:()=>r});var o=i(50248);const r=async(e,t)=>{if(navigator.clipboard)try{return void await navigator.clipboard.writeText(e)}catch{}const i=t||(0,o.n)()?.getRootNode()||document.body,r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.opacity="0",i.appendChild(r),r.select(),document.execCommand("copy"),i.removeChild(r)}},19459(e,t,i){i.d(t,{b:()=>o});i(45367),i(92731),i(69479),i(17642),i(58004),i(33853),i(45876),i(32475),i(15024),i(31698);const o=(e,t,i)=>{if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;let r,s;if(Array.isArray(e)){if(s=e.length,s!==t.length)return!1;for(r=s;0!==r--;)if(!o(e[r],t[r],i))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;for(r of e.entries())if(!o(r[1],t.get(r[0]),i))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(s=e.length,s!==t.length)return!1;for(r=s;0!==r--;)if(e[r]!==t[r])return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();const a=Object.keys(e);if(s=a.length,s!==Object.keys(t).length)return!1;for(r=s;0!==r--;)if(!Object.prototype.hasOwnProperty.call(t,a[r]))return!1;for(r=s;0!==r--;){const s=a[r];if(!o(e[s],t[s],i))return!1}if(i?.compareSymbols){const r=Object.getOwnPropertySymbols(e),s=Object.getOwnPropertySymbols(t);if(r.length!==s.length)return!1;for(const s of r){if(!Object.prototype.hasOwnProperty.call(t,s))return!1;if(!o(e[s],t[s],i))return!1}}return!0}return e!=e&&t!=t}},10763(e,t,i){i.a(e,async function(e,t){try{var o=i(62826),r=i(53289),s=i(5124),a=i(22441),n=i(35211),l=i(1087),d=i(63130),h=i(14503),c=i(81619),g=i(18350),u=i(15717),p=i(22792),y=e([g,u]);[g,u]=y.then?(await y)():y;const f=e=>{if("object"!=typeof e||null===e)return!1;for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0};class m extends s.WF{setValue(e){try{this._yaml=f(e)?"":(0,r.dump)(e,{schema:this.yamlSchema,quotingType:'"',noRefs:!0})}catch(t){console.error(t,e),alert(`There was an error converting to YAML: ${t}`)}}firstUpdated(){void 0!==this.defaultValue&&this.setValue(this.defaultValue)}willUpdate(e){super.willUpdate(e),this.autoUpdate&&e.has("value")&&this.setValue(this.value)}focus(){this._codeEditor?.codemirror&&this._codeEditor?.codemirror.focus()}disableCodeEditorFullscreen(){this.disableFullscreen=!0,this._codeEditor&&(this._codeEditor.disableFullscreen=!0)}render(){return void 0===this._yaml?s.s6:s.qy` ${this.label?s.qy`<p>${this.label}${this.required?" *":""}</p>`:s.s6} <ha-code-editor .value="${this._yaml}" .readOnly="${this.readOnly}" .disableFullscreen="${this.disableFullscreen}" .inDialog="${this.inDialog}" mode="yaml" lint autocomplete-entities autocomplete-icons .error="${!1===this.isValid}" -changed="${this._onChange}" -save="${this._onEditorSave}" dir="ltr"></ha-code-editor> ${this.copyClipboard||this.hasExtraActions?s.qy` <div class="card-actions"> ${this.copyClipboard?s.qy` <ha-button appearance="plain" ="${this._copyYaml}"> ${this._i18n.localize("ui.components.yaml-editor.copy_to_clipboard")} </ha-button> `:s.s6} <slot name="extra-actions"></slot> </div> `:s.s6} `}_onChange(e){let t;e.stopPropagation(),this._yaml=e.detail.value;let i,o=!0,s=null;if(this._yaml)try{t=(0,r.Hh)(this._yaml,{schema:this.yamlSchema})}catch(e){o=!1,s=e,i=`${this._i18n.localize("ui.components.yaml-editor.error",{reason:e.reason})}${e.mark?` (${this._i18n.localize("ui.components.yaml-editor.error_location",{line:e.mark.line+1,column:e.mark.column+1})})`:""}`}else t={};this._codeEditor?.setYamlError(s),this.value=t,this.isValid=o,(0,l.r)(this,"value-changed",{value:t,isValid:o,errorMsg:i})}get yaml(){return this._yaml}get codemirror(){return this._codeEditor?.codemirror}get hasComments(){return this._codeEditor?.hasComments??!1}_onEditorSave(e){(0,l.r)(this,"editor-save"),e.stopPropagation()}async _copyYaml(){this.yaml&&(await(0,d.l)(this.yaml),(0,c.P)(this,{message:this._i18n.localize("ui.common.copied_clipboard")}))}static get styles(){return[h.RF,s.AH`.card-actions{border-radius:var(--actions-border-radius,var(--ha-border-radius-square) var(--ha-border-radius-square) var(--ha-card-border-radius,var(--ha-border-radius-lg)) var(--ha-card-border-radius,var(--ha-border-radius-lg)));border:1px solid var(--divider-color);padding:5px 16px}ha-code-editor{flex-grow:1;min-height:0}`]}constructor(...e){super(...e),this.yamlSchema=r.my,this.isValid=!0,this.autoUpdate=!1,this.readOnly=!1,this.disableFullscreen=!1,this.inDialog=!1,this.required=!1,this.copyClipboard=!1,this.hasExtraActions=!1,this._yaml=""}}(0,o.Cg)([(0,a.MZ)()],m.prototype,"value",void 0),(0,o.Cg)([(0,a.MZ)({attribute:!1})],m.prototype,"yamlSchema",void 0),(0,o.Cg)([(0,a.MZ)({attribute:!1})],m.prototype,"defaultValue",void 0),(0,o.Cg)([(0,a.MZ)({attribute:"is-valid",type:Boolean})],m.prototype,"isValid",void 0),(0,o.Cg)([(0,a.MZ)()],m.prototype,"label",void 0),(0,o.Cg)([(0,a.MZ)({attribute:"auto-update",type:Boolean})],m.prototype,"autoUpdate",void 0),(0,o.Cg)([(0,a.MZ)({attribute:"read-only",type:Boolean})],m.prototype,"readOnly",void 0),(0,o.Cg)([(0,a.MZ)({type:Boolean,attribute:"disable-fullscreen"})],m.prototype,"disableFullscreen",void 0),(0,o.Cg)([(0,a.MZ)({type:Boolean,attribute:"in-dialog"})],m.prototype,"inDialog",void 0),(0,o.Cg)([(0,a.MZ)({type:Boolean})],m.prototype,"required",void 0),(0,o.Cg)([(0,a.MZ)({attribute:"copy-clipboard",type:Boolean})],m.prototype,"copyClipboard",void 0),(0,o.Cg)([(0,a.MZ)({attribute:"has-extra-actions",type:Boolean})],m.prototype,"hasExtraActions",void 0),(0,o.Cg)([(0,a.wk)()],m.prototype,"_yaml",void 0),(0,o.Cg)([(0,a.wk)(),(0,n.Fg)({context:p.D5,subscribe:!0})],m.prototype,"_i18n",void 0),(0,o.Cg)([(0,a.P)("ha-code-editor")],m.prototype,"_codeEditor",void 0),m=(0,o.Cg)([(0,a.EM)("ha-yaml-editor")],m),t()}catch(e){t(e)}})},35632(e,t,i){i.a(e,async function(e,o){try{i.r(t),i.d(t,{DialogLovelaceDashboardConfigureStrategy:()=>u});var r=i(62826),s=i(5124),a=i(22441),n=i(1087),l=i(18350),d=(i(93444),i(72554)),h=i(14503),c=i(5106),g=e([l,d,c]);[l,d,c]=g.then?(await g)():g;class u extends s.WF{showDialog(e){this._params=e,this._data=e.config.strategy,this._open=!0}closeDialog(){this._open=!1}_dialogClosed(){this._params=void 0,this._data=void 0,(0,n.r)(this,"dialog-closed",{dialog:this.localName})}render(){return this._params&&this._data?s.qy` <ha-dialog .open="${this._open}" prevent-scrim-close header-title="${this.hass.localize("ui.panel.config.lovelace.dashboards.detail.new_dashboard")}" ="${this._dialogClosed}"> <div> <hui-dashboard-strategy-element-editor .hass="${this.hass}" .lovelace="${this._params.config}" .value="${this._data}" -changed="${this._handleConfigChanged}" autofocus></hui-dashboard-strategy-element-editor> </div> <ha-dialog-footer slot="footer"> <ha-button slot="primaryAction" ="${this._save}" .disabled="${this._submitting}"> ${this.hass.localize("ui.common.next")} </ha-button> </ha-dialog-footer> </ha-dialog> `:s.s6}_handleConfigChanged(e){this._data=e.detail.config}async _save(){this._data&&(this._submitting=!0,await this._params.saveConfig({...this._params.config,strategy:this._data}),this._submitting=!1,this.closeDialog())}static get styles(){return[h.nA,s.AH``]}constructor(...e){super(...e),this._open=!1,this._submitting=!1}}(0,r.Cg)([(0,a.MZ)({attribute:!1})],u.prototype,"hass",void 0),(0,r.Cg)([(0,a.wk)()],u.prototype,"_params",void 0),(0,r.Cg)([(0,a.wk)()],u.prototype,"_open",void 0),(0,r.Cg)([(0,a.wk)()],u.prototype,"_submitting",void 0),(0,r.Cg)([(0,a.wk)()],u.prototype,"_data",void 0),u=(0,r.Cg)([(0,a.EM)("dialog-lovelace-dashboard-configure-strategy")],u),o()}catch(e){o(e)}})},5106(e,t,i){i.a(e,async function(e,t){try{var o=i(62826),r=i(22441),s=i(15656),a=i(63277),n=e([a]);a=(n.then?(await n)():n)[0];class l extends a.U{async getConfigElement(){const e=await(0,s.Nu)("dashboard",this.configElementType);if(e&&e.getConfigElement)return e.getConfigElement()}}l=(0,o.Cg)([(0,r.EM)("hui-dashboard-strategy-element-editor")],l),t()}catch(e){t(e)}})},39039(e,t,i){i.d(t,{r:()=>o});class o extends Error{constructor(e,t,i){super(e),this.name="GUISupportError",this.warnings=t,this.errors=i}}},91322(e,t,i){i.a(e,async function(e,o){try{i.d(t,{m:()=>f});i(18111),i(7588),i(61701);var r=i(62826),s=i(5124),a=i(22441),n=i(74985),l=i(1087),d=i(78978),h=i(19459),c=i(38962),g=i(65829),u=i(10763),p=i(39039),y=e([c,g,u]);[c,g,u]=y.then?(await y)():y;class f extends s.WF{get value(){return this._config}set value(e){this._config&&(0,h.b)(e,this._config,{compareSymbols:!0})||(this._config=e,this._errors=void 0,this._setConfig())}_setConfig(){if(!this._errors&&!this._yamlError)try{this._updateConfigElement()}catch(e){this._errors=[e.message]}this.updateComplete.then(()=>{(0,l.r)(this,"config-changed",{config:this.value,error:this._errors?.join(", "),guiModeAvailable:!(this.hasWarning||this.hasError||!1===this._guiSupported)})})}get hasWarning(){return void 0!==this._warnings&&this._warnings.length>0}get hasError(){return this._yamlError||void 0!==this._errors&&this._errors.length>0}get GUImode(){return this._guiMode}set GUImode(e){this._guiMode=e,this.updateComplete.then(()=>{(0,l.r)(this,"GUImode-changed",{guiMode:e,guiModeAvailable:!(this.hasWarning||this.hasError||!1===this._guiSupported)})})}toggleMode(){this.GUImode||this._yamlEditor?.disableCodeEditorFullscreen(),this.GUImode=!this.GUImode}focusYamlEditor(){this._configElement?.focusYamlEditor&&this._configElement.focusYamlEditor(),this._yamlEditor&&this._yamlEditor.focus()}async getConfigElement(){}async getConfigForm(){}renderConfigElement(){return s.qy`${this._configElement}`}_renderSubElement(){return s.qy` <hui-sub-element-editor .hass="${this.hass}" .config="${this._subElementEditorConfig}" -back="${this._goBack}" -changed="${this._subElementChanged}"> </hui-sub-element-editor> `}_subElementChanged(e){e.stopPropagation();const t=e.detail.config;this._subElementEditorConfig={...this._subElementEditorConfig,elementConfig:t},this._subElementEditorConfig.saveElementConfig?.(t)}_goBack(e){e.stopPropagation(),this._subElementEditorConfig=void 0}async _editSubElement(e){e.stopPropagation(),await Promise.all([i.e(92769),i.e(3283),i.e(80131),i.e(70183),i.e(67218),i.e(58416),i.e(99788),i.e(58303),i.e(21543),i.e(22398),i.e(46601),i.e(51455),i.e(26092),i.e(8851),i.e(59704),i.e(25322),i.e(90790),i.e(59532),i.e(55076),i.e(36332),i.e(77563),i.e(15862),i.e(99143),i.e(97500),i.e(12009),i.e(66990),i.e(20282),i.e(87857),i.e(92363),i.e(84240)]).then(i.bind(i,81287)),this._subElementEditorConfig={type:e.detail.type,elementConfig:e.detail.config,context:e.detail.context,saveElementConfig:e.detail.saveConfig}}render(){return s.qy` <div class="wrapper"> ${this.GUImode?s.qy` <div class="gui-editor" -sub-element="${this._editSubElement}"> ${this._loading?s.qy` <ha-spinner class="center margin-bot"></ha-spinner> `:(0,n.P)(this._subElementEditorConfig?this._renderSubElement():this.renderConfigElement())} </div> `:s.qy` <div class="yaml-editor"> <ha-yaml-editor .defaultValue="${this._config}" autofocus .inDialog="${this.inDialog}" -changed="${this._handleYAMLChanged}" ="${this._ignoreKeydown}" dir="ltr"></ha-yaml-editor> </div> `} ${!1===this._guiSupported&&!1===this._loading?s.qy` <ha-alert alert-type="info" .title="${this.hass.localize("ui.errors.config.visual_editor_not_supported")}"> ${this.hass.localize("ui.errors.config.visual_editor_not_supported_reason_type")} <br> ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")} </ha-alert> `:s.s6} ${this._errors?.length?s.qy` <ha-alert alert-type="error" .title="${this.hass.localize("ui.errors.config.configuration_error")}"> <ul> ${this._errors.map(e=>s.qy`<li>${e}</li>`)} </ul> </ha-alert> `:s.s6} ${this.hasWarning?s.qy` <ha-alert alert-type="warning" .title="${this.hass.localize("ui.errors.config.visual_editor_not_supported")}"> <ul> ${this._warnings.map(e=>s.qy`<li>${e}</li>`)} </ul> ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")} </ha-alert> `:s.s6} </div> `}updated(e){super.updated(e),this._configElement&&e.has("hass")&&(this._configElement.hass=this.hass),this._configElement&&"lovelace"in this._configElement&&e.has("lovelace")&&(this._configElement.lovelace=this.lovelace),this._configElement&&e.has("context")&&(this._configElement.context=this.context)}_handleUIConfigChanged(e){if(e.stopPropagation(),!this.GUImode)return;const t=e.detail.config;Object.keys(t).forEach(e=>{void 0===t[e]&&delete t[e]}),this.value=t}_handleYAMLChanged(e){e.stopPropagation(),e.detail.isValid?(this._config=e.detail.value,this._errors=void 0,this._yamlError=!1):this._yamlError=!0,this._setConfig()}async unloadConfigElement(){this._configElement=void 0,this._guiSupported=void 0}async loadConfigElement(){if(this._configElement)return;let e=await this.getConfigElement();if(!e){const t=await this.getConfigForm();if(t){await i.e(15106).then(i.bind(i,15737)),e=document.createElement("hui-form-editor");const{schema:o,assertConfig:r,computeLabel:s,computeHelper:a}=t;e.schema=o,s&&(e.computeLabel=s),a&&(e.computeHelper=a),r&&(e.assertConfig=r)}}e?(e.hass=this.hass,"lovelace"in e&&(e.lovelace=this.lovelace),e.context=this.context,e.addEventListener("config-changed",e=>this._handleUIConfigChanged(e)),this._guiSupported=!0):this._guiSupported=!1,this._configElement=e}async _updateConfigElement(){if(!this.value)return;const e=++this._loadCount;try{if(this._errors=void 0,this._warnings=void 0,await this.loadConfigElement(),this._configElement)try{this._configElement.setConfig(this.value)}catch(e){const t=(0,d._)(this.hass,e);throw new p.r("Config is not supported",t.warnings,t.errors)}else this._guiSupported=!1,this.GUImode=!1}catch(t){if(e!==this._loadCount)return;t instanceof p.r?(this._warnings=t.warnings??[t.message],this._errors=t.errors||void 0):this._errors=[t.message],this.GUImode=!1}finally{this._loading=!1}}_ignoreKeydown(e){e.stopPropagation()}constructor(...e){super(...e),this.inDialog=!1,this._guiMode=!0,this._loading=!1,this._yamlError=!1,this._loadCount=0}}f.styles=s.AH`:host{display:flex}.wrapper{width:100%}.gui-editor,.yaml-editor{padding:8px 0px}ha-code-editor{--code-mirror-max-height:calc(100vh - 245px)}ha-spinner{display:block;margin:auto}`,(0,r.Cg)([(0,a.MZ)({attribute:!1})],f.prototype,"hass",void 0),(0,r.Cg)([(0,a.MZ)({attribute:!1})],f.prototype,"lovelace",void 0),(0,r.Cg)([(0,a.MZ)({attribute:!1})],f.prototype,"context",void 0),(0,r.Cg)([(0,a.MZ)({type:Boolean,attribute:"in-dialog"})],f.prototype,"inDialog",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_config",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_configElement",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_subElementEditorConfig",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_guiMode",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_errors",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_warnings",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_guiSupported",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_loading",void 0),(0,r.Cg)([(0,a.wk)()],f.prototype,"_yamlError",void 0),(0,r.Cg)([(0,a.P)("ha-yaml-editor")],f.prototype,"_yamlEditor",void 0),o()}catch(e){o(e)}})},63277(e,t,i){i.a(e,async function(e,o){try{i.d(t,{U:()=>l});var r=i(62826),s=i(22441),a=i(91322),n=e([a]);a=(n.then?(await n)():n)[0];class l extends a.m{get configElementType(){return this.value?this.value.type:void 0}async loadConfigElement(){if(this._configElementType!==this.configElementType){if(this.unloadConfigElement(),!this.configElementType)throw new Error(this.hass.localize("ui.errors.config.no_type_provided"));this._configElementType=this.configElementType}return super.loadConfigElement()}}(0,r.Cg)([(0,s.wk)()],l.prototype,"_configElementType",void 0),o()}catch(e){o(e)}})},36918(e,t,i){i.d(t,{o:()=>o});const o=(e,t)=>`https://www.iobroker.net/#${e.language&&e.language.split("-")[0]||"en"}/adapters/adapterref/iobroker.lovelace/README.md#`},65213(e,t,i){var o=i(44576),r=i(79039),s=o.RegExp,a=!r(function(){var e=!0;try{s(".","d")}catch(t){e=!1}var t={},i="",o=e?"dgimsy":"gimsy",r=function(e,o){Object.defineProperty(t,e,{get:function(){return i+=o,!0}})},a={dotAll:"s",global:"g",ignoreCase:"i",multiline:"m",sticky:"y"};for(var n in e&&(a.hasIndices="d"),a)r(n,a[n]);return Object.getOwnPropertyDescriptor(s.prototype,"flags").get.call(t)!==o||i!==o});e.exports={correct:a}},67979(e,t,i){var o=i(28551);e.exports=function(){var e=o(this),t="";return e.hasIndices&&(t+="d"),e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.unicodeSets&&(t+="v"),e.sticky&&(t+="y"),t}},69479(e,t,i){var o=i(43724),r=i(62106),s=i(65213),a=i(67979);o&&!s.correct&&(r(RegExp.prototype,"flags",{configurable:!0,get:a}),s.correct=!0)},74985(e,t,i){i.d(t,{P:()=>n});i(88454),i(29452);var o=i(5055),r=i(42017),s=i(63937);const a=e=>(0,s.ps)(e)?e._$litType$.h:e.strings,n=(0,r.u$)(class extends r.WL{render(e){return[e]}update(e,[t]){const i=(0,s.qb)(this.it)?a(this.it):null,r=(0,s.qb)(t)?a(t):null;if(null!==i&&(null===r||i!==r)){const t=(0,s.cN)(e).pop();let r=this.et.get(i);if(void 0===r){const e=document.createDocumentFragment();r=(0,o.XX)(o.s6,e),r.setConnected(!1),this.et.set(i,r)}(0,s.mY)(r,[t]),(0,s.Dx)(r,void 0,t)}if(null!==r){if(null===i||i!==r){const t=this.et.get(r);if(void 0!==t){const i=(0,s.cN)(t).pop();(0,s.Jz)(e),(0,s.Dx)(e,void 0,i),(0,s.mY)(e,[i])}}this.it=t}else this.it=void 0;return this.render(t)}constructor(e){super(e),this.et=new WeakMap}})}};