UNPKG

iobroker.lovelace

Version:

With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI

1 lines 7.03 kB
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[4994],{43908:function(t,e,i){i.a(t,async function(t,e){try{i(49255),i(16280),i(62953);var s=i(40445),n=i(5124),r=i(67576),o=i(1087),h=(i(67094),i(91263)),a=i(42678),l=i(14487),d=i(21018),c=i(34128),f=t([h,d,l]);[h,d,l]=f.then?(await f)():f;class u extends((0,h.M)(n.mN)){load(){if(!this.config)throw new Error("Cannot build badge without config");this._loadElement(this.config)}createRenderRoot(){return this}disconnectedCallback(){super.disconnectedCallback()}connectedCallback(){super.connectedCallback(),this._updateVisibility()}_updateElement(t){this._element&&(this._element.setConfig(t),this._elementConfig=t,(0,o.r)(this,"badge-updated"))}_loadElement(t){for(this._element=(0,d.YH)(t),this._elementConfig=t,this.hass&&(this._element.hass=this.hass),this._element.addEventListener("badge-visibility-changed",t=>{t.stopPropagation(),this._updateVisibility()}),this._element.addEventListener("ll-upgrade",t=>{t.stopPropagation(),this.hass&&(this._element.hass=this.hass),(0,o.r)(this,"badge-updated")},{once:!0}),this._element.addEventListener("ll-rebuild",e=>{e.stopPropagation(),this._loadElement(t),(0,o.r)(this,"badge-updated")},{once:!0});this.lastChild;)this.removeChild(this.lastChild);this._updateVisibility()}willUpdate(t){super.willUpdate(t),t.has("config")&&(this._conditionContext=Object.assign(Object.assign({},this._conditionContext),{},{entity_id:this.config?(0,a.r)(this.config):void 0})),this._element||this.load()}update(t){if(super.update(t),this._element){if(t.has("config")){const t=this._elementConfig;if(this.config!==t&&this.config){var e;(null===(e=this.config)||void 0===e?void 0:e.type)!==(null==t?void 0:t.type)?this._loadElement(this.config):this._updateElement(this.config)}}if(t.has("hass"))try{this.hass&&(this._element.hass=this.hass)}catch(i){this._loadElement((0,c.G9)(i.message,null))}}(t.has("hass")||t.has("preview"))&&this._updateVisibility()}_updateVisibility(t){var e,i;if(!this._element||!this.hass)return;if(this._element.hidden)return void this._setElementVisibility(!1);if(this.preview)return void this._setElementVisibility(!0);if(null!==(e=this.config)&&void 0!==e&&e.disabled)return void this._setElementVisibility(!1);const s=null!=t?t:!(null!==(i=this.config)&&void 0!==i&&i.visibility)||(0,l.XH)(this.config.visibility,this.hass,this._conditionContext);this._setElementVisibility(s)}_setElementVisibility(t){this._element&&(this.hidden!==!t&&(this.style.setProperty("display",t?"":"none"),this.toggleAttribute("hidden",!t),(0,o.r)(this,"badge-visibility-changed",{value:t})),!0===this._element.connectedWhileHidden?this._element.parentElement||this.appendChild(this._element):!t&&this._element.parentElement?this.removeChild(this._element):t&&!this._element.parentElement&&this.appendChild(this._element))}constructor(...t){super(...t),this.preview=!1}}(0,s.Cg)([(0,r.MZ)({type:Boolean})],u.prototype,"preview",void 0),(0,s.Cg)([(0,r.MZ)({attribute:!1})],u.prototype,"config",void 0),(0,s.Cg)([(0,r.MZ)({attribute:!1})],u.prototype,"hass",void 0),u=(0,s.Cg)([(0,r.EM)("hui-badge")],u),e()}catch(u){e(u)}})},95417:function(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{HuiEntityFilterBadge:function(){return f}});i(16280),i(44114),i(18111),i(81148),i(22489),i(61701),i(13579),i(62953);var n=i(40445),r=i(5124),o=i(67576),h=i(68289),a=i(20939),l=i(14487),d=i(43908),c=t([d,l]);[d,l]=c.then?(await c)():c;class f extends r.mN{setConfig(t){if(!t.entities.length||!Array.isArray(t.entities))throw new Error("Entities must be specified");if(!(t.conditions&&Array.isArray(t.conditions)||t.state_filter&&Array.isArray(t.state_filter)||t.entities.every(t=>"object"==typeof t&&t.state_filter&&Array.isArray(t.state_filter))))throw new Error("Incorrect filter config");for(;this.lastChild;)this.removeChild(this.lastChild);this._elements=void 0,this._configEntities=(0,a.L)(t.entities),this._oldEntities=void 0,this._config=t}createRenderRoot(){return this}shouldUpdate(t){return!!(t.has("_config")||t.has("hass")&&this._haveEntitiesChanged(t.get("hass")))}update(t){if(super.update(t),!this.hass||!this._configEntities)return;if(this._elements)for(const i of this._elements)i.hass=this.hass;const e=this._configEntities.filter(t=>{var e,i;const s=this.hass.states[t.entity];if(!s)return!1;const n=null!==(e=t.conditions)&&void 0!==e?e:this._config.conditions;if(n){const e=n.map(e=>(0,l.lB)(e,t.entity));return(0,l.XH)(e,this.hass,{})}const r=null!==(i=t.state_filter)&&void 0!==i?i:this._config.state_filter;return!!r&&r.some(t=>(0,h.J)(s,t))});if(0===e.length)return this.style.display="none",void(this._oldEntities=e);if(!(this._oldEntities&&e.length===this._oldEntities.length&&e.every((t,e)=>t===this._oldEntities[e]))){this._elements=[];for(const t of e){const e=document.createElement("hui-badge");e.hass=this.hass,e.preview=this.preview,e.config=Object.assign({type:"entity"},t),e.load(),this._elements.push(e)}this._oldEntities=e}if(this._elements){for(;this.lastChild;)this.removeChild(this.lastChild);for(const t of this._elements)this.appendChild(t);this.style.display="flex",this.style.flexWrap="wrap",this.style.justifyContent="center",this.style.gap="8px"}}_haveEntitiesChanged(t){var e;if(!t)return!0;if(!this._oldEntities||this.hass.localize!==t.localize)return!0;for(const s of this._configEntities){if(this.hass.states[s.entity]!==t.states[s.entity])return!0;if(s.conditions){const e=(0,l.Wx)(s.conditions);for(const i of e)if(this.hass.states[i]!==t.states[i])return!0}}if(null!==(e=this._config)&&void 0!==e&&e.conditions){var i;const e=(0,l.Wx)(null===(i=this._config)||void 0===i?void 0:i.conditions);for(const i of e)if(this.hass.states[i]!==t.states[i])return!0}return!1}constructor(...t){super(...t),this.preview=!1}}(0,n.Cg)([(0,o.MZ)({attribute:!1})],f.prototype,"preview",void 0),(0,n.Cg)([(0,o.MZ)({attribute:!1})],f.prototype,"hass",void 0),(0,n.Cg)([(0,o.wk)()],f.prototype,"_config",void 0),f=(0,n.Cg)([(0,o.EM)("hui-entity-filter-badge")],f),s()}catch(f){s(f)}})},68289:function(t,e,i){i.d(e,{J:function(){return s}});i(74423),i(18111),i(61701),i(33110),i(84864),i(57465),i(27495),i(42762);const s=(t,e)=>{let i,s,n;if("object"==typeof e?(i=e.operator,s=e.value,n=e.attribute?t.attributes[e.attribute]:t.state):(i="==",s=e,n=t.state),"=="===i||"!="===i){const t="number"==typeof s||"string"==typeof s&&s.trim()&&!isNaN(Number(s)),e="number"==typeof n||"string"==typeof n&&n.trim()&&!isNaN(Number(n));t&&e&&(s=Number(s),n=Number(n))}switch(i){case"==":return n===s;case"<=":return n<=s;case"<":return n<s;case">=":return n>=s;case">":return n>s;case"!=":return n!==s;case"in":return!(!Array.isArray(s)&&"string"!=typeof s)&&(Array.isArray(s)&&(s=s.map(t=>`${t}`)),s.includes(n));case"not in":return!(!Array.isArray(s)&&"string"!=typeof s)&&(Array.isArray(s)&&(s=s.map(t=>`${t}`)),!s.includes(n));case"regex":return"string"==typeof s&&(null!==n&&"object"==typeof n?RegExp(s).test(JSON.stringify(n)):RegExp(s).test(n));default:return!1}}}}]);