iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 8.45 kB
JavaScript
export const __rspack_esm_id=71508;export const __rspack_esm_ids=[71508];export const __webpack_modules__={34370(e,t,s){s(18111),s(7588),e.exports=function e(t){return Object.freeze(t),Object.getOwnPropertyNames(t).forEach(function(s){!t.hasOwnProperty(s)||null===t[s]||"object"!=typeof t[s]&&"function"!=typeof t[s]||Object.isFrozen(t[s])||e(t[s])}),t}},99680(e,t,s){s.d(t,{eX:()=>n});s(18111),s(81148),s(22489),s(61701);var i=s(28918),o=s(35952),a=s(91984);const n=e=>{if((0,o.Wu)(e))return e;const t={...e};return t.views&&(t.views=t.views.map(h)),t},h=e=>{if((0,a.R6)(e))return e;const t={...e};return t.badges&&!t.badges.every(Boolean)&&(t.badges=t.badges.filter(Boolean)),t.sections&&(t.sections=t.sections.map(l)),t},l=e=>{const t={...e};if(e.title){if(!(0,i.H)(t)){const e={type:"heading",heading:t.title};t.cards=[e,...t.cards||[]]}delete t.title}return t}},15020(e,t,s){s.a(e,async function(e,i){try{s.r(t),s.d(t,{LovelacePanel:()=>z});s(18111),s(20116);var o=s(62826),a=s(34370),n=s.n(a),h=s(5124),l=s(22441),r=s(22786),c=s(91926),d=s(51758),g=s(6030),f=s(9899),u=s(19459),_=s(18350),p=s(95350),v=s(99129),C=s(35952),w=s(25612),y=s(28794),m=s(23296),b=s(81619),N=s(99680),U=s(35697),P=s(1412),S=s(29994),$=s(15656),E=s(693),M=s(71730),L=e([_,y,m,S]);[_,y,m,S]=L.then?(await L)():L,window.loadCardHelpers=()=>Promise.all([s.e(99143),s.e(66990),s.e(86538)]).then(s.bind(s,33963));let k=!1,x=!1;class z extends h.WF{connectedCallback(){super.connectedCallback(),this.lovelace&&this.hass&&this.lovelace.locale!==this.hass.locale?this._setLovelaceConfig(this.lovelace.config,this.lovelace.rawConfig,this.lovelace.mode):this._fetchConfigOnConnect&&this._fetchConfig(!1),window.addEventListener("connection-status",this._handleConnectionStatus)}disconnectedCallback(){super.disconnectedCallback(),null!==this.urlPath&&this._unsubUpdates&&(this._unsubUpdates.then(e=>e()),this._unsubUpdates=void 0),window.removeEventListener("connection-status",this._handleConnectionStatus)}render(){const e=this._panelState;return"loaded"===e?h.qy` <hui-root .panel="${this.panel}" .hass="${this.hass}" .lovelace="${this.lovelace}" .route="${this.route}" .narrow="${this.narrow}" -refresh="${this._forceFetchConfig}" -config-changed="${this._strategyConfigChanged}"></hui-root> `:"error"===e?h.qy` <hass-error-screen .hass="${this.hass}" title="${(0,p.p$)(this.hass.localize,"lovelace")}" .error="${this._errorMsg}"> <ha-button ="${this._forceFetchConfig}"> ${this.hass.localize("ui.panel.lovelace.reload_lovelace")} </ha-button> </hass-error-screen> `:"yaml-editor"===e?h.qy` <hui-editor .narrow="${this.narrow}" .hass="${this.hass}" .lovelace="${this.lovelace}" .closeEditor="${this._closeEditor}"></hui-editor> `:h.qy` <hass-loading-screen rootnav .hass="${this.hass}" .narrow="${this.narrow}"></hass-loading-screen> `}willUpdate(e){super.willUpdate(e),this.lovelace||"error"===this._panelState||this._loading||this._fetchConfig(!1)}firstUpdated(e){super.firstUpdated(e),this._unsubUpdates||this._subscribeUpdates()}updated(e){if(super.updated(e),!e.has("hass"))return;const t=e.get("hass");t&&this.hass&&this.lovelace&&(0,C.Wu)(this.lovelace.rawConfig)&&(t.entities===this.hass.entities&&t.devices===this.hass.devices&&t.areas===this.hass.areas&&t.floors===this.hass.floors||"RUNNING"===this.hass.config.state&&this._debounceRegistriesChanged(),"RUNNING"===this.hass.config.state&&"RUNNING"!==t.config.state&&this._regenerateStrategyConfig())}async _regenerateStrategyConfig(){if(!this.hass||!this.lovelace)return;const e=this.lovelace.rawConfig;if((0,C.Wu)(e))try{const t=await(0,$.uN)(e,this.hass);this._setLovelaceConfig(t,e,"generated")}catch(e){console.error(e)}}async _subscribeUpdates(){this._unsubUpdates=(0,v.EG)(this.hass.connection,this.urlPath,()=>this._lovelaceChanged())}_lovelaceChanged(){this._ignoreNextUpdateEvent?this._ignoreNextUpdateEvent=!1:this.isConnected?this.lovelace?.editMode||"yaml-editor"===this._panelState?(0,b.P)(this,{message:this.hass.localize("ui.panel.lovelace.externally_updated_toast.message"),action:{action:()=>this._fetchConfig(!1),text:this.hass.localize("ui.common.refresh")},duration:-1,dismissable:!1}):this._fetchConfig(!1):this._fetchConfigOnConnect=!0}get urlPath(){return this.panel.url_path}_forceFetchConfig(){this._fetchConfig(!0)}async _fetchConfig(e){let t,s;this._loading=!0;const i=this.panel.config?.mode;if(!i)return void(0,c.oo)("/home",{replace:!0});let o;const a=window;a.llConfProm&&(o=a.llConfProm,a.llConfProm=void 0),x||(x=!0,(a.llResProm||(0,w.kZ)(this.hass.connection)).then(e=>(0,U.n)(e,this.hass))),null===this.urlPath&&o||(this.lovelace&&"yaml"===this.lovelace.mode&&(this._ignoreNextUpdateEvent=!0),o=(0,C.Dz)(this.hass.connection,this.urlPath,e));try{if(s=await o,(0,C.Wu)(s)){if(!this.hass?.entities||!this.hass.devices||!this.hass.areas)return;t=await(0,$.uN)(s,this.hass)}else t=s}catch(e){if("config_not_found"!==e.code)return console.log(e),this._panelState="error",void(this._errorMsg=e.message);if("lovelace"===this.urlPath){if(!(await(0,M.SJ)(this.hass)).find(e=>"lovelace"===e.url_path))return void(0,c.oo)("/home",{replace:!0})}t=this._generateDefaultConfig(this.hass.localize),s=t}finally{this._loading=!1,this.lovelace&&"yaml"===this.lovelace.mode&&setTimeout(()=>{this._ignoreNextUpdateEvent=!1},2e3)}this._panelState="yaml-editor"===this._panelState?this._panelState:"loaded",this._setLovelaceConfig(t,s,i)}_checkLovelaceConfig(e){const t=(0,N.eX)(e);return n()(t)}_setLovelaceConfig(e,t,i){e=this._checkLovelaceConfig(e);const o=this.urlPath;this.lovelace={config:e,rawConfig:t,mode:i,urlPath:this.urlPath,editMode:!!this.lovelace&&this.lovelace.editMode,locale:this.hass.locale,enableFullEditMode:()=>{k||(k=!0,s.e(36584).then(s.bind(s,5435))),this._panelState="yaml-editor"},setEditMode:e=>{"generated"===this.lovelace.mode&&e&&this.panel?.config?(0,P.z)(this,{lovelace:this.lovelace,mode:this.panel.config.mode,narrow:this.narrow}):(0,C.Wu)(this.lovelace.rawConfig)&&e?this.lovelace.enableFullEditMode():this._updateLovelace({editMode:e})},saveConfig:async e=>{const{config:t,rawConfig:s,mode:i}=this.lovelace;let a;e=this._checkLovelaceConfig(e),a=(0,C.Wu)(e)?await(0,$.uN)(e,this.hass):e;try{this._updateLovelace({config:a,rawConfig:e,mode:"storage"}),this._ignoreNextUpdateEvent=!0,await(0,C.ql)(this.hass,o,e)}catch(e){throw console.error(e),this._updateLovelace({config:t,rawConfig:s,mode:i}),e}},deleteConfig:async()=>{const{config:e,rawConfig:t,mode:s}=this.lovelace;try{const e=this._generateDefaultConfig(this.hass.localize);this._updateLovelace({config:e,rawConfig:e,mode:"storage"}),this._ignoreNextUpdateEvent=!0,await(0,C.ql)(this.hass,o,e)}catch(i){throw console.error(i),this._updateLovelace({config:e,rawConfig:t,mode:s}),i}},showToast:e=>(0,b.P)(this,e)}}_updateLovelace(e){this.lovelace={...this.lovelace,...e},"editMode"in e&&window.history.replaceState(null,"",(0,d.Z)(e.editMode?(0,g.$X)({edit:"1"}):(0,g.s8)("edit")))}constructor(...e){super(...e),this.narrow=!1,this._panelState="loading",this._ignoreNextUpdateEvent=!1,this._fetchConfigOnConnect=!1,this._loading=!1,this._debounceRegistriesChanged=(0,f.s)(()=>this._registriesChanged(),200),this._registriesChanged=async()=>{if(!this.hass||!this.lovelace)return;const e=this.lovelace.rawConfig;if(!(0,C.Wu)(e))return;const t=this.lovelace.config,s=await(0,$.uN)(e,this.hass),i=(0,N.eX)(s);(0,u.b)(i,t)||this._regenerateStrategyConfig()},this._strategyConfigChanged=e=>{e.stopPropagation(),this._regenerateStrategyConfig()},this._handleConnectionStatus=e=>{"connected"===e.detail&&this._fetchConfig(!1)},this._closeEditor=()=>{this._panelState="loaded"},this._generateDefaultConfig=(0,r.A)(e=>({views:[(0,E.c)(e,!0)]}))}}(0,o.Cg)([(0,l.MZ)({attribute:!1})],z.prototype,"panel",void 0),(0,o.Cg)([(0,l.MZ)({attribute:!1})],z.prototype,"hass",void 0),(0,o.Cg)([(0,l.MZ)({type:Boolean})],z.prototype,"narrow",void 0),(0,o.Cg)([(0,l.MZ)({attribute:!1})],z.prototype,"route",void 0),(0,o.Cg)([(0,l.wk)()],z.prototype,"_panelState",void 0),(0,o.Cg)([(0,l.wk)()],z.prototype,"_errorMsg",void 0),(0,o.Cg)([(0,l.wk)()],z.prototype,"lovelace",void 0),z=(0,o.Cg)([(0,l.EM)("ha-panel-lovelace")],z),i()}catch(e){i(e)}})},31481(e,t,s){s.d(t,{Y:()=>i});const i=(e,t)=>({type:"grid",cards:t?[{type:"heading",heading:e("ui.panel.lovelace.editor.section.default_section_title")}]:[]})},693(e,t,s){s.d(t,{c:()=>o});var i=s(31481);const o=(e,t)=>({type:"sections",sections:[(0,i.Y)(e,t)]})}};