iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
10 lines • 17 kB
JavaScript
export const __rspack_esm_id=26295;export const __rspack_esm_ids=[26295];export const __webpack_modules__={47129(e,t,i){i.d(t,{a:()=>r});i(74423);var a=i(22675),o=i(71727);function r(e,t){const i=(0,o.m)(e.entity_id),r=void 0!==t?t:e?.state;if(["button","event","infrared","input_button","radio_frequency","scene"].includes(i))return r!==a.Hh;if(r===a.Hh||r===a.HV)return!1;if("off"===r&&"alert"!==i)return!1;switch(i){case"alarm_control_panel":return"disarmed"!==r;case"alert":return"idle"!==r;case"cover":case"valve":return"closed"!==r;case"device_tracker":case"person":return"not_home"!==r;case"lawn_mower":return!["docked","paused"].includes(r);case"lock":return"locked"!==r;case"media_player":return"standby"!==r;case"vacuum":return!["idle","docked","paused"].includes(r);case"plant":return"problem"===r;case"group":return["on","home","open","locked","problem"].includes(r);case"timer":return"active"===r;case"camera":return"streaming"===r}return!0}},67258(e,t,i){i.d(t,{d:()=>a});const a=e=>{switch(e.language){case"cs":case"de":case"fi":case"fr":case"sk":case"sv":return" ";default:return""}}},41060(e,t,i){i.a(e,async function(e,t){try{i(18111),i(61701);var a=i(62826),o=i(5124),r=i(22441),s=i(6412),n=i(44537),l=i(1087),d=i(67258),c=i(46187),p=i(18350),h=i(26300),u=i(94355),g=e([p,h,u]);[p,h,u]=g.then?(await g)():g;const v="M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z",m="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M13.5,16V19H10.5V16H8L12,12L16,16H13.5M13,9V3.5L18.5,9H13Z";class b extends o.WF{firstUpdated(e){super.firstUpdated(e),this.autoOpenFileDialog&&this._openFilePicker()}get _name(){if(void 0===this.value)return"";if("string"==typeof this.value)return this.value;return(this.value instanceof FileList?Array.from(this.value):(0,n.e)(this.value)).map(e=>e.name).join(", ")}render(){const e=this.localize||this.hass.localize;return o.qy` ${this.uploading?o.qy`<div class="container"> <div class="uploading"> <span class="header">${this.uploadingLabel||(this.value?e("ui.components.file-upload.uploading_name",{name:this._name}):e("ui.components.file-upload.uploading"))}</span> ${this.progress?o.qy`<div class="progress"> ${this.progress}${this.hass&&(0,d.d)(this.hass.locale)}% </div>`:o.s6} </div> <ha-progress-bar .indeterminate="${!this.progress}" .value="${this.progress}" loading></ha-progress-bar> </div>`:o.qy`<label for="${this.value?"":"input"}" class="container ${(0,s.H)({dragged:this._drag,multiple:this.multiple,value:Boolean(this.value)})}" ="${this._handleDrop}" ="${this._handleDragStart}" ="${this._handleDragStart}" ="${this._handleDragEnd}" ="${this._handleDragEnd}">${this.value?"string"==typeof this.value?o.qy`<div class="row"> <div class="value" ="${this._openFilePicker}"> <ha-svg-icon .path="${this.icon||m}"></ha-svg-icon> ${this.value} </div> <ha-icon-button ="${this._clearValue}" .label="${this.deleteLabel||e("ui.common.delete")}" .path="${v}"></ha-icon-button> </div>`:(this.value instanceof FileList?Array.from(this.value):(0,n.e)(this.value)).map(t=>o.qy`<div class="row"> <div class="value" ="${this._openFilePicker}"> <ha-svg-icon .path="${this.icon||m}"></ha-svg-icon> ${t.name} - ${(0,c.A)(t.size)} </div> <ha-icon-button ="${this._clearValue}" .label="${this.deleteLabel||e("ui.common.delete")}" .path="${v}"></ha-icon-button> </div>`):o.qy`<ha-button size="small" appearance="filled" ="${this._openFilePicker}"> <ha-svg-icon slot="start" .path="${this.icon||m}"></ha-svg-icon> ${this.label||e("ui.components.file-upload.label")} </ha-button> <span class="secondary">${this.secondary||e("ui.components.file-upload.secondary")}</span> <span class="supports">${this.supports}</span>`} <input id="input" type="file" class="file" .accept="${this.accept}" .multiple="${this.multiple}" ="${this._handleFilePicked}"></label>`} `}_openFilePicker(){this._input?.click()}_handleDrop(e){e.preventDefault(),e.stopPropagation(),e.dataTransfer?.files&&(0,l.r)(this,"file-picked",{files:this.multiple||1===e.dataTransfer.files.length?Array.from(e.dataTransfer.files):[e.dataTransfer.files[0]]}),this._drag=!1}_handleDragStart(e){e.preventDefault(),e.stopPropagation(),this._drag=!0}_handleDragEnd(e){e.preventDefault(),e.stopPropagation(),this._drag=!1}_handleFilePicked(e){0!==e.target.files.length&&(this.value=e.target.files,(0,l.r)(this,"file-picked",{files:e.target.files}))}_clearValue(e){e.preventDefault(),this._input.value="",this.value=void 0,(0,l.r)(this,"change"),(0,l.r)(this,"files-cleared")}constructor(...e){super(...e),this.multiple=!1,this.disabled=!1,this.uploading=!1,this.autoOpenFileDialog=!1,this._drag=!1}}b.styles=o.AH`:host{display:block;height:240px}:host([disabled]){pointer-events:none;color:var(--disabled-text-color)}.container{position:relative;display:flex;flex-direction:column;justify-content:center;align-items:center;border:solid 1px var(--mdc-text-field-idle-line-color,rgba(0,0,0,.42));border-radius:var(--mdc-shape-small,var(--ha-border-radius-sm));height:100%}.row{display:flex;align-items:center}label.container{border:dashed 1px var(--mdc-text-field-idle-line-color,rgba(0,0,0,.42));cursor:pointer}.container .uploading{display:flex;flex-direction:column;width:100%;align-items:flex-start;padding:0 32px;box-sizing:border-box}:host([disabled]) .container{border-color:var(--disabled-color)}label.dragged,label:hover{border-style:solid}label.dragged{border-color:var(--primary-color)}.dragged:before{position:absolute;top:0;right:0;bottom:0;left:0;background-color:var(--primary-color);content:"";opacity:var(--dark-divider-opacity);pointer-events:none;border-radius:var(--mdc-shape-small,4px)}label.value{cursor:default}label.value.multiple{justify-content:unset;overflow:auto}.highlight{color:var(--primary-color)}ha-button{margin-bottom:8px}.supports{color:var(--secondary-text-color);font-size:var(--ha-font-size-s)}:host([disabled]) .secondary{color:var(--disabled-text-color)}input.file{display:none}.value{cursor:pointer}.value ha-svg-icon{margin-right:8px;margin-inline-end:8px;margin-inline-start:initial}ha-button{--mdc-button-outline-color:var(--primary-color);--ha-icon-button-size:24px}ha-progress-bar{width:100%;padding:8px 32px;box-sizing:border-box}.header{font-weight:var(--ha-font-weight-medium)}.progress{color:var(--secondary-text-color)}button.link{background:0 0;border:none;padding:0;font-size:var(--ha-font-size-m);color:var(--primary-color);text-decoration:underline;cursor:pointer}`,(0,a.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"hass",void 0),(0,a.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"localize",void 0),(0,a.Cg)([(0,r.MZ)()],b.prototype,"accept",void 0),(0,a.Cg)([(0,r.MZ)()],b.prototype,"icon",void 0),(0,a.Cg)([(0,r.MZ)()],b.prototype,"label",void 0),(0,a.Cg)([(0,r.MZ)()],b.prototype,"secondary",void 0),(0,a.Cg)([(0,r.MZ)({attribute:"uploading-label"})],b.prototype,"uploadingLabel",void 0),(0,a.Cg)([(0,r.MZ)({attribute:"delete-label"})],b.prototype,"deleteLabel",void 0),(0,a.Cg)([(0,r.MZ)()],b.prototype,"supports",void 0),(0,a.Cg)([(0,r.MZ)({type:Object})],b.prototype,"value",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean})],b.prototype,"multiple",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean,reflect:!0})],b.prototype,"disabled",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean})],b.prototype,"uploading",void 0),(0,a.Cg)([(0,r.MZ)({type:Number})],b.prototype,"progress",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean,attribute:"auto-open-file-dialog"})],b.prototype,"autoOpenFileDialog",void 0),(0,a.Cg)([(0,r.wk)()],b.prototype,"_drag",void 0),(0,a.Cg)([(0,r.P)("#input")],b.prototype,"_input",void 0),b=(0,a.Cg)([(0,r.EM)("ha-file-upload")],b),t()}catch(e){t(e)}})},44002(e,t,i){i.a(e,async function(e,t){try{i(74423);var a=i(62826),o=i(5124),r=i(22441),s=i(1087),n=i(14503),l=i(3129),d=i(65063),c=i(4658),p=i(18350),h=i(41060),u=i(95287),g=e([p,h]);[p,h]=g.then?(await g)():g;const v="M18 15V18H15V20H18V23H20V20H23V18H20V15H18M13.3 21H5C3.9 21 3 20.1 3 19V5C3 3.9 3.9 3 5 3H19C20.1 3 21 3.9 21 5V13.3C20.4 13.1 19.7 13 19 13C17.9 13 16.8 13.3 15.9 13.9L14.5 12L11 16.5L8.5 13.5L5 18H13.1C13 18.3 13 18.7 13 19C13 19.7 13.1 20.4 13.3 21Z";class m extends o.WF{render(){if(!this.value){const e=this.secondary||(this.selectMedia?o.qy`${this.hass.localize("ui.components.picture-upload.secondary",{select_media:o.qy`<button class="link" ="${this._chooseMedia}"> ${this.hass.localize("ui.components.picture-upload.select_media")} </button>`})}`:void 0);return o.qy` <ha-file-upload .hass="${this.hass}" .icon="${v}" .label="${this.label||this.hass.localize("ui.components.picture-upload.label")}" .secondary="${e}" .supports="${this.supports||this.hass.localize("ui.components.picture-upload.supported_formats")}" .uploading="${this._uploading}" -picked="${this._handleFilePicked}" ="${this._handleFileCleared}" accept="image/png, image/jpeg, image/gif"></ha-file-upload> `}return o.qy`<div class="center-vertical"> <div class="value"> <img .src="${this.value}" alt="${this.currentImageAltText||this.hass.localize("ui.components.picture-upload.current_image_alt")}"> <div> <ha-button appearance="plain" size="small" variant="danger" ="${this._handleChangeClick}"> ${this.hass.localize("ui.components.picture-upload.clear_picture")} </ha-button> </div> </div> </div>`}_handleChangeClick(){this.value=null,(0,s.r)(this,"change")}async _handleFilePicked(e){const t=e.detail.files[0];this.crop?this._cropFile(t):this._uploadFile(t)}async _handleFileCleared(){this.value=null}async _cropFile(e,t){["image/png","image/jpeg","image/gif"].includes(e.type)?(0,c.Q)(this,{file:e,options:this.cropOptions||{round:!1,aspectRatio:NaN},croppedCallback:i=>{t&&i===e?(this.value=(0,l.Q0)(t,this.size,this.original),(0,s.r)(this,"change")):this._uploadFile(i)}}):(0,d.showAlertDialog)(this,{text:this.hass.localize("ui.components.picture-upload.unsupported_format")})}async _uploadFile(e){if(["image/png","image/jpeg","image/gif"].includes(e.type)){this._uploading=!0;try{const t=await(0,l.mF)(this.hass,e);if(this.fullMedia){const e={media_content_id:`${l.AP}/${t.id}`,media_content_type:t.content_type,title:t.name,media_class:"image",can_play:!0,can_expand:!1,can_search:!1,thumbnail:(0,l.Q0)(t.id,256)},i=[{},{media_content_type:"app",media_content_id:l.AP}];(0,s.r)(this,"media-picked",{item:e,navigateIds:i})}else this.value=(0,l.Q0)(t.id,this.size,this.original),(0,s.r)(this,"change")}catch(e){(0,d.showAlertDialog)(this,{text:e.toString()})}finally{this._uploading=!1}}else(0,d.showAlertDialog)(this,{text:this.hass.localize("ui.components.picture-upload.unsupported_format")})}static get styles(){return[n.RF,o.AH`:host{display:block;height:240px}ha-file-upload{height:100%}.center-vertical{display:flex;align-items:center;height:100%}.value{width:100%;display:flex;flex-direction:column;align-items:center}img{max-width:100%;max-height:200px;margin-bottom:4px;border-radius:var(--file-upload-image-border-radius);transition:opacity .3s;opacity:var(--picture-opacity, 1)}img:hover{opacity:1}`]}constructor(...e){super(...e),this.value=null,this.crop=!1,this.selectMedia=!1,this.fullMedia=!1,this.original=!1,this.size=512,this._uploading=!1,this._chooseMedia=()=>{(0,u.O)(this,{action:"pick",entityId:"browser",accept:["image/*"],navigateIds:this.fullMedia?void 0:[{media_content_id:void 0,media_content_type:void 0},{media_content_id:l.AP,media_content_type:"app"}],minimumNavigateLevel:this.fullMedia?void 0:2,hideContentType:!0,contentIdHelper:this.contentIdHelper,mediaPickedCallback:async e=>{if(this.fullMedia)return void(0,s.r)(this,"media-picked",e);const t=(0,l.pD)(e.item.media_content_id);if(t)if(this.crop){const i=(0,l.Q0)(t,void 0,!0);let a;try{a=await(0,l.M5)(this.hass,i)}catch(e){return void(0,d.showAlertDialog)(this,{text:e.toString()})}const o={type:e.item.media_content_type},r=new File([a],e.item.title,o);this._cropFile(r,t)}else this.value=(0,l.Q0)(t,this.size,this.original),(0,s.r)(this,"change")}})}}}(0,a.Cg)([(0,r.MZ)()],m.prototype,"value",void 0),(0,a.Cg)([(0,r.MZ)()],m.prototype,"label",void 0),(0,a.Cg)([(0,r.MZ)()],m.prototype,"secondary",void 0),(0,a.Cg)([(0,r.MZ)()],m.prototype,"supports",void 0),(0,a.Cg)([(0,r.MZ)({attribute:!1})],m.prototype,"currentImageAltText",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean})],m.prototype,"crop",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean,attribute:"select-media"})],m.prototype,"selectMedia",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean,attribute:"full-media"})],m.prototype,"fullMedia",void 0),(0,a.Cg)([(0,r.MZ)({attribute:!1})],m.prototype,"contentIdHelper",void 0),(0,a.Cg)([(0,r.MZ)({attribute:!1})],m.prototype,"cropOptions",void 0),(0,a.Cg)([(0,r.MZ)({type:Boolean})],m.prototype,"original",void 0),(0,a.Cg)([(0,r.MZ)({type:Number})],m.prototype,"size",void 0),(0,a.Cg)([(0,r.wk)()],m.prototype,"_uploading",void 0),m=(0,a.Cg)([(0,r.EM)("ha-picture-upload")],m),t()}catch(e){t(e)}})},95287(e,t,i){i.d(t,{O:()=>o});var a=i(1087);const o=(e,t)=>{(0,a.r)(e,"show-dialog",{dialogTag:"dialog-media-player-browse",dialogImport:()=>Promise.all([i.e(39763),i.e(32450),i.e(46095),i.e(7305),i.e(92769),i.e(34995),i.e(3283),i.e(80131),i.e(70183),i.e(99812),i.e(78198),i.e(26092),i.e(8851),i.e(91845),i.e(8283),i.e(71486)]).then(i.bind(i,93565)),dialogParams:t})}},94355(e,t,i){i.a(e,async function(e,t){try{var a=i(62826),o=i(88590),r=i(5124),s=i(22441),n=e([o]);o=(n.then?(await n)():n)[0];class l extends o.A{static get styles(){return[o.A.styles,r.AH`:host{--indicator-color:var(
--ha-progress-bar-indicator-color,
var(--ha-color-on-primary-normal)
);--track-color:var(
--ha-progress-bar-track-color,
var(--ha-color-fill-neutral-normal-hover)
);--track-height:var(--ha-progress-bar-track-height, 12px);--wa-transition-slow:var(--ha-animation-duration-slow);position:relative}.progress-bar{border-radius:var(--ha-progress-bar-border-radius,var(--ha-border-radius-pill))}.indicator{background:var(--ha-progress-bar-indicator-background,var(--indicator-color))}:host([indeterminate]) .indicator{animation:wa-progress-indeterminate var(--ha-progress-bar-animation-duration,2.5s) infinite cubic-bezier(.37,0,.63,1)} slide-highlight{0%{transform:translateX(-200%)}100%{transform:translateX(200%)}}:host([loading]:not([indeterminate])) .progress-bar::after{content:"";position:absolute;inset:0;background:linear-gradient(90deg,transparent 0%,oklch(from var(--indicator-color) 85% c h) 50%,transparent 100%);opacity:.5;animation:slide-highlight var(--ha-progress-bar-animation-duration,2.5s) infinite cubic-bezier(.37,0,.63,1);width:50%}:host::after{--width:var(
--ha-progress-bar-indicator-highlight-width,
calc(var(--track-height) * 2)
);width:var(--width);height:var(--ha-progress-bar-indicator-highlight-height,calc(var(--track-height) * 2));content:"";position:absolute;inset-inline-start:clamp(var(--width)/ 2,var(--percentage,0%),calc(100% - var(--width)/ 2));top:50%;transform:translate(-50%,-50%);background-image:var(--ha-progress-bar-indicator-highlight-image);background-size:contain;background-repeat:no-repeat;background-position:center;pointer-events:none;transition:inset-inline-start var(--wa-transition-slow, 200ms) var(--wa-transition-easing, ease)}:host([indeterminate])::after{display:none}`]}constructor(...e){super(...e),this.loading=!1}}(0,a.Cg)([(0,s.MZ)({type:Boolean,reflect:!0})],l.prototype,"loading",void 0),l=(0,a.Cg)([(0,s.EM)("ha-progress-bar")],l),t()}catch(e){t(e)}})},22675(e,t,i){i.d(t,{HV:()=>r,Hh:()=>o});var a=i(23832);const o="unavailable",r="unknown",s=[o,r,"off"];(0,a.g)(s)},3129(e,t,i){i.d(t,{AP:()=>o,M5:()=>d,Q0:()=>s,mF:()=>n,pD:()=>r,vS:()=>l});const a="/api/image/serve/",o="media-source://image_upload",r=e=>{let t;if(e.startsWith(a)){t=e.substring(17);const i=t.indexOf("/");i>=0&&(t=t.substring(0,i))}else e.startsWith(o)&&(t=e.substring(o.length+1));return t},s=(e,t,i=!1)=>{if(!i&&!t)throw new Error("Size must be provided if original is false");return i?`/api/image/serve/${e}/original`:`/api/image/serve/${e}/${t}x${t}`},n=async(e,t)=>{const i=new FormData;i.append("file",t);const a=await e.fetchWithAuth("/api/image/upload",{method:"POST",body:i});if(413===a.status)throw new Error(`Uploaded image is too large (${t.name})`);if(200!==a.status)throw new Error("Unknown error");return a.json()},l=(e,t)=>e.callWS({type:"image/delete",image_id:t}),d=async(e,t)=>{const i=await fetch(e.hassUrl(t));if(!i.ok)throw new Error(`Failed to fetch image: ${i.statusText?i.statusText:i.status}`);return i.blob()}},4658(e,t,i){i.d(t,{Q:()=>r});var a=i(1087);const o=()=>Promise.all([i.e(78661),i.e(77673)]).then(i.bind(i,97424)),r=(e,t)=>{(0,a.r)(e,"show-dialog",{dialogTag:"image-cropper-dialog",dialogImport:o,dialogParams:t})}},46187(e,t,i){i.d(t,{A:()=>a});const a=(e=0,t=2)=>{if(0===e)return"0 Bytes";t=t<0?0:t;const i=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/1024**i).toFixed(t))} ${["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}`}}};