iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 6.59 kB
JavaScript
export const __rspack_esm_id=73842;export const __rspack_esm_ids=[73842];export const __webpack_modules__={84329(t,a,e){e.a(t,async function(t,i){try{e.r(a),e.d(a,{ALARM_MODE_STATE_MAP:()=>E,DEFAULT_STATES:()=>w,filterSupportedAlarmStates:()=>C});e(18111),e(22489),e(61701),e(13579);var s=e(62826),n=e(5124),r=e(22441),o=e(6412),c=e(89784),l=e(42372),h=e(1087),d=e(52658),u=e(82286),_=(e(34296),e(18350)),p=(e(76776),e(93367)),m=e(91485),y=e(9182),g=e(22675),b=e(59241),f=e(13632),v=e(85979),$=t([_,p,m,v]);[_,p,m,v]=$.then?(await $)():$;const k="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z",x=["1","2","3","4","5","6","7","8","9","clear","0",""],w=["arm_home","arm_away"],E={arm_home:"armed_home",arm_away:"armed_away",arm_night:"armed_night",arm_vacation:"armed_vacation",arm_custom_bypass:"armed_custom_bypass"},C=(t,a)=>a.filter(a=>t&&(0,u.$)(t,y.t[E[a]].feature||0));class L extends n.WF{static async getConfigElement(){return await e.e(40731).then(e.bind(e,13654)),document.createElement("hui-alarm-panel-card-editor")}static getStubConfig(t,a,e){const i=(0,f.B)(t,1,a,e,["alarm_control_panel"])[0]||"",s=t.states[i];return{type:"alarm-panel",states:C(s,w),entity:i}}connectedCallback(){super.connectedCallback(),this._subscribeEntityEntry()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeEntityRegistry()}async getCardSize(){if(!this._config||!this.hass)return 10;const t=this.hass.states[this._config.entity];return t&&"number"===t.attributes.code_format?10:4}setConfig(t){if(!t||!t.entity||"alarm_control_panel"!==t.entity.split(".")[0])throw new Error("Invalid configuration");this._config={...t},this._subscribeEntityEntry()}updated(t){if(super.updated(t),!this._config||!this.hass)return;const a=t.get("hass"),e=t.get("_config");a&&e&&a.themes===this.hass.themes&&e.theme===this._config.theme||(0,l.Q)(this,this.hass.themes,this._config.theme)}shouldUpdate(t){if(t.has("_config"))return!0;const a=t.get("hass");return!a||a.themes!==this.hass.themes||a.locale!==this.hass.locale||a.states[this._config.entity]!==this.hass.states[this._config.entity]}async _unsubscribeEntityRegistry(){this._unsubEntityRegistry&&(this._unsubEntityRegistry(),this._unsubEntityRegistry=void 0)}async _subscribeEntityEntry(){if(this._config?.entity)try{this._unsubEntityRegistry=(0,b.Bz)(this.hass.connection,async t=>{t.some(t=>t.entity_id===this._config.entity)&&(this._entry=await(0,b.v)(this.hass,this._config.entity))})}catch(t){this._entry=null}}render(){if(!this._config||!this.hass)return n.s6;const t=this.hass.states[this._config.entity],a=this._config.states||C(t,w);if(!t)return n.qy` <hui-warning .hass="${this.hass}"> ${(0,v.j)(this.hass,this._config.entity)} </hui-warning> `;const e=this._stateDisplay(t.state),i=this._entry?.options?.alarm_control_panel?.default_code,s=this.hass.formatEntityName(t,this._config.name);return n.qy` <ha-card> <h1 class="card-header"> ${s} <ha-assist-chip filled style="${(0,c.W)({"--alarm-state-color":(0,d.Se)(t)})}" class="${(0,o.H)({[t.state]:!0})}" ="${this._handleMoreInfo}" .label="${e}"> <ha-state-icon slot="icon" .stateObj="${t}"></ha-state-icon> </ha-assist-chip> </h1> <div id="armActions" class="actions"> ${("disarmed"===t.state?a:["disarm"]).map(t=>n.qy` <ha-button .action="${t}" ="${this._handleActionClick}" appearance="filled" size="small" variant="${"disarm"===t?"danger":"brand"}"> ${this._actionDisplay(t)} </ha-button> `)} </div> ${!t.attributes.code_format||i?n.s6:n.qy` <ha-input .value="${this._value||""}" ="${this._handleInput}" .label="${this.hass.localize("ui.card.alarm_control_panel.code")}" type="password" .inputmode="${"number"===t.attributes.code_format?"numeric":"text"}"></ha-input> `} ${"number"!==t.attributes.code_format||i?n.s6:n.qy` <div class="keypad"> ${x.map(t=>""===t?n.qy`<span></span>`:"clear"===t?n.qy` <ha-control-button ="${this._handlePadClick}" class="clear" .value="${t}" .disabled="${!this._value}" .label="${this.hass.localize("ui.common.clear")}"> <ha-svg-icon path="${k}"></ha-svg-icon> </ha-control-button> `:n.qy` <ha-control-button .value="${t}" ="${this._handlePadClick}" .label="${t}"> ${t} </ha-control-button> `)} </div> `} </ha-card> `}_actionDisplay(t){return this.hass.localize(`ui.card.alarm_control_panel.${t}`)}_stateDisplay(t){return t===g.Hh?this.hass.localize("state.default.unavailable"):this.hass.localize(`component.alarm_control_panel.entity_component._.state.${t}`)||t}_handleInput(t){this._value=t.currentTarget.value}_handlePadClick(t){const a=t.currentTarget.value;this._value="clear"===a?"":(this._value||"")+a}_handleActionClick(t){(0,y.kF)(this.hass,this._config.entity,t.currentTarget.action,this._value||void 0),this._value=void 0}_handleMoreInfo(){(0,h.r)(this,"hass-more-info",{entityId:this._config.entity})}}L.styles=n.AH`ha-card{padding-bottom:16px;position:relative;height:100%;display:flex;flex-direction:column;align-items:center;box-sizing:border-box;--alarm-state-color:var(--state-inactive-color)}ha-assist-chip{--ha-assist-chip-filled-container-color:var(--alarm-state-color);--primary-text-color:var(--text-primary-color)}.card-header{display:flex;justify-content:space-between;align-items:center;width:100%;box-sizing:border-box}.arming,.pending,.triggered{animation:pulse 1s infinite} pulse{0%{opacity:1}50%{opacity:0}100%{opacity:1}}ha-input{margin:var(--ha-space-2);max-width:150px;text-align:center;--ha-input-padding-bottom:0}.state{margin-left:var(--ha-space-4);margin-inline-start:var(--ha-space-4);margin-inline-end:initial;position:relative;bottom:var(--ha-space-4);color:var(--alarm-state-color);animation:none}.keypad{--keypad-columns:3;padding:var(--ha-space-3);display:grid;grid-template-columns:repeat(var(--keypad-columns),auto);grid-auto-rows:auto;grid-gap:var(--ha-space-4);justify-items:center;align-items:center;direction:ltr}ha-control-button{width:56px;height:56px;--control-button-border-radius:var(--ha-border-radius-4xl);--mdc-icon-size:24px;font-size:var(--ha-font-size-2xl)}.clear{--control-button-background-color:var(--red-color);--control-button-icon-color:var(--red-color)}.actions{margin:0;display:flex;flex-wrap:wrap;justify-content:center;align-items:center}.actions ha-button{margin:var(--ha-space-1)}`,(0,s.Cg)([(0,r.MZ)({attribute:!1})],L.prototype,"hass",void 0),(0,s.Cg)([(0,r.wk)()],L.prototype,"_config",void 0),(0,s.Cg)([(0,r.wk)()],L.prototype,"_entry",void 0),(0,s.Cg)([(0,r.wk)()],L.prototype,"_value",void 0),L=(0,s.Cg)([(0,r.EM)("hui-alarm-panel-card")],L),i()}catch(t){i(t)}})}};