UNPKG

iobroker.lovelace

Version:

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

1 lines 7.51 kB
export const __rspack_esm_id=37855;export const __rspack_esm_ids=[37855];export const __webpack_modules__={58548(t,i,e){e.d(i,{A:()=>s});const a=t=>{const i=parseFloat(t);if(isNaN(i))throw new Error(`${t} is not a number`);return i};function s(t){if(!t)return null;try{if(t.endsWith("%"))return{w:100,h:a(t.slice(0,-1))};const i=t.replace(":","x").split("x");return 0===i.length?null:1===i.length?{w:a(i[0]),h:1}:{w:a(i[0]),h:a(i[1])}}catch(t){}return null}},17022(t,i,e){e.d(i,{A1:()=>a,CY:()=>o,Fn:()=>s,Jz:()=>c,St:()=>r,VA:()=>l,WI:()=>g,iY:()=>h,xw:()=>n});const a=(t,i)=>t.callWS({type:"media_source/resolve_media",media_content_id:i}),s=(t,i)=>t.callWS({type:"media_source/browse_media",media_content_id:i}),n="__MANUAL_ENTRY__",o=t=>t.startsWith(n),r=t=>t.startsWith("media-source://"),c=t=>t.startsWith("media-source://media_source"),h=t=>t.startsWith("media-source://image_upload"),l=async(t,i,e)=>{const a=new FormData;a.append("media_content_id",i),a.append("file",e);const s=await t.fetchWithAuth("/api/media_source/local_source/upload",{method:"POST",body:a});if(413===s.status)throw new Error(`Uploaded file is too large (${e.name})`);if(200!==s.status)throw new Error("Unknown error");return s.json()},g=async(t,i)=>t.callWS({type:"media_source/local_source/remove",media_content_id:i})},78602(t,i,e){e.a(t,async function(t,a){try{e.r(i);e(44114),e(18111),e(7588),e(61701);var s=e(62826),n=e(5124),o=e(22441),r=e(6412),c=e(63672),h=e(46190),l=e(42372),g=e(71727),d=e(28978),_=e(47129),f=(e(76776),e(26300)),u=e(93367),m=e(67013),p=e(19037),y=e(13632),b=e(22064),w=e(97176),v=e(784),$=e(20939),x=e(57914),k=e(85979),E=(e(47046),t([f,u,x,k]));[f,u,x,k]=E.then?(await E)():E;class A extends n.WF{static async getConfigElement(){return await Promise.all([e.e(66990),e.e(38076),e.e(13837)]).then(e.bind(e,92469)),document.createElement("hui-picture-glance-card-editor")}static getStubConfig(t,i,e){return{type:"picture-glance",title:"Kitchen",image:"https://demo.home-assistant.io/stub_config/kitchen.png",entities:(0,y.B)(t,2,i,e,["sensor","binary_sensor"])}}getCardSize(){return 3}setConfig(t){if(!t||!t.entities||!Array.isArray(t.entities)||!(t.image||t.image_entity||t.camera_image||t.state_image)||t.state_image&&!t.entity)throw new Error("Invalid configuration");const i=(0,$.L)(t.entities);this._entitiesDialog=[],this._entitiesToggle=[],i.forEach(i=>{t.force_dialog||!h.FD.has((0,g.m)(i.entity))?this._entitiesDialog.push(i):this._entitiesToggle.push(i)}),this._config=t}shouldUpdate(t){if(!this._config||(0,v.LX)(this,t))return!0;if(!t.has("hass"))return!1;const i=t.get("hass");if(!i||i.themes!==this.hass.themes||i.locale!==this.hass.locale)return!0;if(this._config.image_entity&&i.states[this._config.image_entity]!==this.hass.states[this._config.image_entity])return!0;if(this._entitiesDialog)for(const t of this._entitiesDialog)if(i.states[t.entity]!==this.hass.states[t.entity])return!0;if(this._entitiesToggle)for(const t of this._entitiesToggle)if(i.states[t.entity]!==this.hass.states[t.entity])return!0;return!1}updated(t){if(super.updated(t),!this._config||!this.hass)return;const i=t.get("hass"),e=t.get("_config");i&&e&&i.themes===this.hass.themes&&e.theme===this._config.theme||(0,l.Q)(this,this.hass.themes,this._config.theme)}render(){if(!this._config||!this.hass)return n.s6;let t="object"==typeof this._config?.image&&this._config.image.media_content_id||this._config.image;if(this._config.image_entity){const i=this.hass.states[this._config.image_entity];switch((0,g.m)(this._config.image_entity)){case"image":t=(0,m.e)(i);break;case"person":i.attributes.entity_picture&&(t=i.attributes.entity_picture)}}const i="grid"===this.layout&&"number"==typeof this._config.grid_options?.rows,e=(0,w.h)(this._config.tap_action)||Boolean(!this._config.tap_action&&(this._config.camera_image||this._config.image_entity||this._config.entity));return n.qy` <ha-card> <div class="image-container ${(0,r.H)({clickable:e||(0,w.h)(this._config.hold_action)||(0,w.h)(this._config.double_tap_action)})}" @action="${this._handleAction}" .actionHandler="${(0,p.T)({hasTap:e,hasHold:(0,w.h)(this._config.hold_action),hasDoubleClick:(0,w.h)(this._config.double_tap_action)})}" tabindex="${(0,c.J)(e?"0":void 0)}" role="${(0,c.J)(e?"button":void 0)}" .config="${this._config}"> <hui-image .hass="${this.hass}" .image="${t}" .stateImage="${this._config.state_image}" .stateFilter="${this._config.state_filter}" .cameraImage="${this._config.camera_image}" .cameraView="${this._config.camera_view}" .entity="${this._config.entity}" .fitMode="${this._config.fit_mode}" .aspectRatio="${i?void 0:this._config.aspect_ratio}"></hui-image> </div> <div class="box"> ${this._config.title?n.qy`<div class="title">${this._config.title}</div>`:""} <div class="row"> ${this._entitiesDialog.map(t=>this._renderEntity(t,!0))} </div> <div class="row"> ${this._entitiesToggle.map(t=>this._renderEntity(t,!1))} </div> </div> </ha-card> `}_renderEntity(t,i){const e=this.hass.states[t.entity];return t={tap_action:{action:i?"more-info":"toggle"},hold_action:{action:"more-info"},...t},e?n.qy` <div class="wrapper"> <ha-icon-button @action="${this._handleAction}" .actionHandler="${(0,p.T)({hasHold:(0,w.h)(t.hold_action),hasDoubleClick:(0,w.h)(t.double_tap_action)})}" tabindex="${(0,c.J)((0,w.h)(t.tap_action)?void 0:"-1")}" .disabled="${!(0,w.h)(t.tap_action)}" .config="${t}" class="${(0,r.H)({"state-on":(0,_.a)(e)})}" title="${`${(0,d.u)(e)} : ${this.hass.formatEntityState(e)}`}"> <ha-state-icon .icon="${t.icon}" .stateObj="${e}"></ha-state-icon> </ha-icon-button> ${!0!==this._config.show_state&&!0!==t.show_state?n.qy`<div class="state"></div>`:n.qy` <div class="state"> ${t.attribute?n.qy` ${t.prefix}${e.attributes[t.attribute]}${t.suffix} `:this.hass.formatEntityState(e)} </div> `} </div> `:n.qy` <hui-warning-element .label="${(0,k.j)(this.hass,t.entity)}"></hui-warning-element> `}_handleAction(t){const i=t.currentTarget.config;(0,b.$)(this,this.hass,i,t.detail.action)}}A.styles=n.AH`ha-card{position:relative;min-height:48px;overflow:hidden;height:100%;box-sizing:border-box}.image-container{height:100%}.image-container.clickable{cursor:pointer}hui-image{pointer-events:none;height:100%}.box{position:absolute;left:0;right:0;bottom:0;background-color:var(--ha-picture-card-background-color,rgba(0,0,0,.3));padding:4px 8px;display:flex;justify-content:space-between;flex-direction:row}.box .title{font-weight:var(--ha-font-weight-medium);margin-left:8px;margin-inline-start:8px;margin-inline-end:initial;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;font-size:var(--ha-font-size-l);line-height:var(--ha-line-height-expanded);color:var(--ha-picture-card-text-color,#fff);align-self:center}ha-state-icon{font-size:0}ha-icon-button{--ha-icon-button-size:40px;--disabled-text-color:currentColor;color:var(--ha-picture-icon-button-color,#a9a9a9)}ha-icon-button.state-on{color:var(--ha-picture-icon-button-on-color,#fff)}hui-warning-element{padding:0 8px}.state{display:block;font-size:var(--ha-font-size-s);text-align:center;line-height:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--ha-picture-card-text-color,#fff)}.row{display:flex;flex-direction:row}.wrapper{display:flex;flex-direction:column;width:40px}`,(0,s.Cg)([(0,o.MZ)({attribute:!1})],A.prototype,"hass",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],A.prototype,"layout",void 0),(0,s.Cg)([(0,o.wk)()],A.prototype,"_config",void 0),A=(0,s.Cg)([(0,o.EM)("hui-picture-glance-card")],A),a()}catch(t){a(t)}})}};