iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 5.3 kB
JavaScript
export const __rspack_esm_id=48412;export const __rspack_esm_ids=[48412];export const __webpack_modules__={58548(t,i,e){e.d(i,{A:()=>s});const o=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:o(t.slice(0,-1))};const i=t.replace(":","x").split("x");return 0===i.length?null:1===i.length?{w:o(i[0]),h:1}:{w:o(i[0]),h:o(i[1])}}catch(t){}return null}},17022(t,i,e){e.d(i,{A1:()=>o,CY:()=>n,Fn:()=>s,Jz:()=>c,St:()=>r,VA:()=>_,WI:()=>d,iY:()=>h,xw:()=>a});const o=(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}),a="__MANUAL_ENTRY__",n=t=>t.startsWith(a),r=t=>t.startsWith("media-source://"),c=t=>t.startsWith("media-source://media_source"),h=t=>t.startsWith("media-source://image_upload"),_=async(t,i,e)=>{const o=new FormData;o.append("media_content_id",i),o.append("file",e);const s=await t.fetchWithAuth("/api/media_source/local_source/upload",{method:"POST",body:o});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()},d=async(t,i)=>t.callWS({type:"media_source/local_source/remove",media_content_id:i})},86063(t,i,e){e.a(t,async function(t,o){try{e.r(i),e.d(i,{STUB_IMAGE:()=>b});e(74423);var s=e(62826),a=e(5124),n=e(22441),r=e(6412),c=e(63672),h=e(42372),_=e(71727),d=(e(76776),e(67013)),g=e(19037),l=e(13632),u=e(22064),f=e(97176),m=e(784),p=e(57914),y=e(85979),w=t([p,y]);[p,y]=w.then?(await w)():w;const b="https://demo.home-assistant.io/stub_config/bedroom.png";class v extends a.WF{static async getConfigElement(){return await e.e(76999).then(e.bind(e,98458)),document.createElement("hui-picture-entity-card-editor")}static getStubConfig(t,i,e){return{type:"picture-entity",entity:(0,l.B)(t,1,i,e,["light","switch"])[0]||"",image:b}}getCardSize(){return 3}setConfig(t){if(!t||!t.entity)throw new Error("Entity must be specified");if(!(["camera","image","person"].includes((0,_.m)(t.entity))||t.image||t.state_image||t.camera_image||t.show_entity_picture))throw new Error("No image source configured");this._config={show_name:!0,show_state:!0,tap_action:{action:"more-info"},...t}}shouldUpdate(t){return(0,m.LX)(this,t)}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,h.Q)(this,this.hass.themes,this._config.theme)}render(){if(!this._config||!this.hass)return a.s6;const t=this.hass.states[this._config.entity];if(!t)return a.qy` <hui-warning .hass="${this.hass}"> ${(0,y.j)(this.hass,this._config.entity)} </hui-warning> `;const i=this.hass.formatEntityName(t,this._config.name),e=this.hass.formatEntityState(t);let o="";this._config.show_name&&this._config.show_state?o=a.qy` <div class="footer both"> <div>${i}</div> <div>${e}</div> </div> `:this._config.show_name?o=a.qy`<div class="footer single">${i}</div>`:this._config.show_state&&(o=a.qy`<div class="footer single">${e}</div>`);const s=(0,_.m)(this._config.entity);let n;if(this._config.show_entity_picture&&(n=t.attributes.entity_picture_local||t.attributes.entity_picture),n||(n="object"==typeof this._config?.image&&this._config.image.media_content_id||this._config.image),!n)switch(s){case"image":n=(0,d.e)(t);break;case"person":t.attributes.entity_picture&&(n=t.attributes.entity_picture)}const h="grid"===this.layout&&"number"==typeof this._config.grid_options?.rows,l=(0,f.h)(this._config.tap_action)||Boolean(!this._config.tap_action&&this._config.entity);return a.qy` <ha-card> <div class="image-container ${(0,r.H)({clickable:l})}" ="${this._handleAction}" .actionHandler="${(0,g.T)({hasHold:(0,f.h)(this._config.hold_action),hasDoubleClick:(0,f.h)(this._config.double_tap_action)})}" tabindex="${(0,c.J)(l?"0":void 0)}" role="${(0,c.J)(l?"0":void 0)}"> <hui-image .hass="${this.hass}" .image="${n}" .stateImage="${this._config.state_image}" .stateFilter="${this._config.state_filter}" .cameraImage="${"camera"===s?this._config.entity:this._config.camera_image}" .cameraView="${this._config.camera_view}" .entity="${this._config.entity}" .aspectRatio="${h?void 0:this._config.aspect_ratio}" .fitMode="${this._config.fit_mode}"></hui-image> </div> ${o} </ha-card> `}_handleAction(t){(0,u.$)(this,this.hass,this._config,t.detail.action)}}v.styles=a.AH`ha-card{min-height:75px;overflow:hidden;position:relative;height:100%;box-sizing:border-box}.image-container{height:100%}.image-container.clickable{cursor:pointer}hui-image{pointer-events:none;height:100%}.footer{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;position:absolute;left:0;right:0;bottom:0;background-color:var(--ha-picture-card-background-color,rgba(0,0,0,.3));padding:16px;font-size:var(--ha-font-size-l);line-height:16px;color:var(--ha-picture-card-text-color,#fff);pointer-events:none}.both{display:flex;justify-content:space-between}.single{text-align:center}`,(0,s.Cg)([(0,n.MZ)({attribute:!1})],v.prototype,"hass",void 0),(0,s.Cg)([(0,n.MZ)({attribute:!1})],v.prototype,"layout",void 0),(0,s.Cg)([(0,n.wk)()],v.prototype,"_config",void 0),v=(0,s.Cg)([(0,n.EM)("hui-picture-entity-card")],v),o()}catch(t){o(t)}})}};