iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 28.1 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[99143],{13062:function(t,e,i){i.a(t,async function(t,e){try{i(3362),i(62953);var s=i(40445),a=i(5124),o=i(67576),r=i(75751),n=i(89784),h=i(58888),l=i(22786),d=i(28978),c=i(82286),p=i(10897),_=i(92639),g=i(71608),m=t([_,g]);[_,g]=m.then?(await m)():m;let v,y,u,b,C,f=t=>t;const I="mjpeg";class S extends a.WF{willUpdate(t){var e,i;const s=t.has("stateObj")&&this.stateObj&&(null===(e=t.get("stateObj"))||void 0===e?void 0:e.entity_id)!==this.stateObj.entity_id,a=t.get("hass"),o=t.has("hass")&&this.hass&&this.stateObj&&a&&this.hass.config.state===h.St&&(null===(i=a.config)||void 0===i?void 0:i.state)!==h.St;(s||o)&&(this._getCapabilities(),this._getPosterUrl())}connectedCallback(){super.connectedCallback(),this._connected=!0}disconnectedCallback(){super.disconnectedCallback(),this._connected=!1}render(){var t;if(!this.stateObj)return a.s6;const e=this._streams(null===(t=this._capabilities)||void 0===t?void 0:t.frontend_stream_types,this._hlsStreams,this._webRtcStreams,this.muted);return(0,a.qy)(v||(v=f`${0}`),(0,r.u)(e,t=>t.type+this.stateObj.entity_id,t=>this._renderStream(t)))}_renderStream(t){if(!this.stateObj)return a.s6;if(t.type===I){const t=this._connected?(0,p.CK)(this.stateObj):this._posterUrl;return t?(0,a.qy)(y||(y=f`<img .src="${0}" style="${0}" alt="${0}">`),t,(0,n.W)({aspectRatio:this.aspectRatio,objectFit:this.fitMode}),`Preview of the ${(0,d.u)(this.stateObj)} camera.`):a.s6}return"hls"===t.type?(0,a.qy)(u||(u=f`<ha-hls-player autoplay playsinline .allowExoPlayer="${0}" .muted="${0}" .controls="${0}" .hass="${0}" .entityid="${0}" .posterUrl="${0}" ="${0}" class="${0}" .aspectRatio="${0}" .fitMode="${0}"></ha-hls-player>`),this.allowExoPlayer,this.muted,this.controls,this.hass,this.stateObj.entity_id,this._posterUrl,this._handleHlsStreams,t.visible?"":"hidden",this.aspectRatio,this.fitMode):t.type===p.zS?(0,a.qy)(b||(b=f`<ha-web-rtc-player autoplay playsinline .muted="${0}" .controls="${0}" .hass="${0}" .entityid="${0}" .posterUrl="${0}" ="${0}" class="${0}" .aspectRatio="${0}" .fitMode="${0}"></ha-web-rtc-player>`),this.muted,this.controls,this.hass,this.stateObj.entity_id,this._posterUrl,this._handleWebRtcStreams,t.visible?"":"hidden",this.aspectRatio,this.fitMode):a.s6}async _getCapabilities(){this._capabilities=void 0,this._hlsStreams=void 0,this._webRtcStreams=void 0,(0,c.$)(this.stateObj,2)?this._capabilities=await(0,p._Z)(this.hass,this.stateObj.entity_id):this._capabilities={frontend_stream_types:[]}}async _getPosterUrl(){try{this._posterUrl=await(0,p.C4)(this.hass,this.stateObj.entity_id,this.clientWidth,this.clientHeight)}catch(t){this._posterUrl=void 0}}_handleHlsStreams(t){this._hlsStreams=t.detail}_handleWebRtcStreams(t){this._webRtcStreams=t.detail}constructor(...t){super(...t),this.controls=!1,this.muted=!1,this.allowExoPlayer=!1,this._connected=!1,this._streams=(0,l.A)((t,e,i,s)=>{if(!t)return[];if(0===t.length)return[{type:I,visible:!0}];if(1===t.length)return"hls"===t[0]&&!1===(null==e?void 0:e.hasVideo)||t[0]===p.zS&&!1===(null==i?void 0:i.hasVideo)?[{type:I,visible:!0}]:[{type:t[0],visible:!0}];if(e&&i)return e.hasVideo&&e.hasAudio&&!i.hasAudio&&!s?[{type:"hls",visible:!0}]:i.hasVideo?[{type:p.zS,visible:!0}]:[{type:I,visible:!0}];if((null==e?void 0:e.hasVideo)!==(null==i?void 0:i.hasVideo)){if(null!=e&&e.hasVideo)return[{type:"hls",visible:!0},{type:p.zS,visible:!1}];if(!1===(null==e?void 0:e.hasVideo))return[{type:p.zS,visible:!0}];if(null!=i&&i.hasVideo)return[{type:p.zS,visible:!0},{type:"hls",visible:!1}];if(!1===(null==i?void 0:i.hasVideo))return[{type:"hls",visible:!0}]}return[{type:"hls",visible:!0},{type:p.zS,visible:!1}]})}}S.styles=(0,a.AH)(C||(C=f`:host,img{display:block}img{width:100%}ha-web-rtc-player{width:100%;height:100%}ha-hls-player{width:100%;height:100%}.hidden{display:none}`)),(0,s.Cg)([(0,o.MZ)({attribute:!1})],S.prototype,"hass",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],S.prototype,"stateObj",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],S.prototype,"aspectRatio",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],S.prototype,"fitMode",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"controls"})],S.prototype,"controls",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"muted"})],S.prototype,"muted",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"allow-exoplayer"})],S.prototype,"allowExoPlayer",void 0),(0,s.Cg)([(0,o.wk)()],S.prototype,"_posterUrl",void 0),(0,s.Cg)([(0,o.wk)()],S.prototype,"_connected",void 0),(0,s.Cg)([(0,o.wk)()],S.prototype,"_capabilities",void 0),(0,s.Cg)([(0,o.wk)()],S.prototype,"_hlsStreams",void 0),(0,s.Cg)([(0,o.wk)()],S.prototype,"_webRtcStreams",void 0),S=(0,s.Cg)([(0,o.EM)("ha-camera-stream")],S),e()}catch(v){e(v)}})},92639:function(t,e,i){i.a(t,async function(t,e){try{i(74423),i(3362),i(27495),i(62953),i(3296),i(27208),i(48408),i(14603),i(47566),i(98721);var s=i(40445),a=i(5124),o=i(67576),r=i(89784),n=i(36312),h=i(1087),l=i(12587),d=i(10897),c=i(38962),p=t([c]);c=(p.then?(await p)():p)[0];let _,g,m,v,y=t=>t;class u extends a.WF{connectedCallback(){super.connectedCallback(),u.streamCount+=1,this.hasUpdated&&(this._resetError(),this._startHls()),document.addEventListener("visibilitychange",this._handleVisibilityChange)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("visibilitychange",this._handleVisibilityChange),u.streamCount-=1,this._cleanUp()}render(){return(0,a.qy)(_||(_=y` ${0} ${0} `),this._error?(0,a.qy)(g||(g=y`<ha-alert alert-type="error" class="${0}"> ${0} </ha-alert>`),this._errorIsFatal?"fatal":"retry",this._error):"",this._errorIsFatal?"":(0,a.qy)(m||(m=y`<video .poster="${0}" ?autoplay="${0}" .muted="${0}" ?playsinline="${0}" ?controls="${0}" ="${0}" style="${0}"></video>`),this.posterUrl,this.autoPlay,this.muted,this.playsInline,this.controls,this._loadedData,(0,r.W)({height:null==this.aspectRatio?"100%":"auto",aspectRatio:this.aspectRatio,objectFit:this.fitMode})))}updated(t){super.updated(t);const e=t.has("entityid"),i=t.has("url");e?this._getStreamUrlFromEntityId():i&&this.url&&(this._cleanUp(),this._resetError(),this._url=this.url,this._startHls())}async _getStreamUrlFromEntityId(){if(this._cleanUp(),this._resetError(),(0,n.x)(this.hass.config,"stream")){if(this.entityid)try{const{url:t}=await(0,d.wv)(this.hass,this.entityid);this._url=this.hass.hassUrl(t),this._cleanUp(),this._resetError(),this._startHls()}catch(t){console.error(t),(0,h.r)(this,"streams",{hasAudio:!1,hasVideo:!1})}}else this._setFatalError("Streaming component is not loaded.")}async _startHls(){var t;const e=fetch(this._url),s=(await i.e(29091).then(i.bind(i,10318))).default;if(!this.isConnected)return;let a=s.isSupported();if(a||(a=""!==this._videoEl.canPlayType("application/vnd.apple.mpegurl")),!a)return void this._setFatalError(this.hass.localize("ui.components.media-browser.video_not_supported"));const o=this.allowExoPlayer&&(null===(t=this.hass.auth.external)||void 0===t?void 0:t.config.hasExoPlayer),r=await(await e).text();if(!this.isConnected)return;const n=/#EXT-X-STREAM-INF:.*?(?:CODECS=".*?([^.]*)?\..*?,([^.]*)?\..*?".*?)?(?:\n|\r\n)(.+)/g,h=n.exec(r),l=n.exec(r);let d;d=null!==h&&null===l?new URL(h[3],this._url).href:this._url;const c=h?`${h[1]},${h[2]}`:void 0;this._reportStreams(c),o&&(null!=c&&c.includes("hevc")||null!=c&&c.includes("hev1"))?this._renderHLSExoPlayer(d):s.isSupported()?this._renderHLSPolyfill(this._videoEl,s,d):this._renderHLSNative(this._videoEl,d)}async _renderHLSExoPlayer(t){this._exoPlayer=!0,window.addEventListener("resize",this._resizeExoPlayer),this.updateComplete.then(()=>(0,l.E)()).then(this._resizeExoPlayer),this._videoEl.style.visibility="hidden",await this.hass.auth.external.fireMessage({type:"exoplayer/play_hls",payload:{url:t,muted:this.muted}})}_isLLHLSSupported(){if(u.streamCount<=2)return!0;if(!("performance"in window)||0===performance.getEntriesByType("resource").length)return!1;const t=performance.getEntriesByType("resource")[0];return"nextHopProtocol"in t&&"h2"===t.nextHopProtocol}async _renderHLSPolyfill(t,e,i){const s=new e({backBufferLength:60,fragLoadingTimeOut:3e4,manifestLoadingTimeOut:3e4,levelLoadingTimeOut:3e4,maxLiveSyncPlaybackRate:2,lowLatencyMode:this._isLLHLSSupported()});this._hlsPolyfillInstance=s,s.attachMedia(t),s.on(e.Events.MEDIA_ATTACHED,()=>{this._resetError(),s.loadSource(i)}),s.on(e.Events.FRAG_LOADED,(t,e)=>{this._resetError()}),s.on(e.Events.ERROR,(t,i)=>{if(i.fatal)if(i.type===e.ErrorTypes.NETWORK_ERROR){switch(i.details){case e.ErrorDetails.MANIFEST_LOAD_ERROR:{let t="Error starting stream, see logs for details";void 0!==i.response&&void 0!==i.response.code&&(i.response.code>=500?t+=" (Server failure)":i.response.code>=400?t+=" (Stream never started)":t+=` (${i.response.code})`),this._setRetryableError(t);break}case e.ErrorDetails.MANIFEST_LOAD_TIMEOUT:this._setRetryableError("Timeout while starting stream");break;default:this._setRetryableError("Stream network error")}s.startLoad()}else i.type===e.ErrorTypes.MEDIA_ERROR?(this._setRetryableError("Error with media stream contents"),s.recoverMediaError()):this._setFatalError("Error playing stream")})}async _renderHLSNative(t,e){t.src=e,t.addEventListener("loadedmetadata",()=>{t.play()})}_cleanUp(){this._hlsPolyfillInstance&&(this._hlsPolyfillInstance.destroy(),this._hlsPolyfillInstance=void 0),this._exoPlayer&&(window.removeEventListener("resize",this._resizeExoPlayer),this.hass.auth.external.fireMessage({type:"exoplayer/stop"}),this._exoPlayer=!1),this._videoEl&&(this._videoEl.removeAttribute("src"),this._videoEl.load())}_resetError(){this._error=void 0,this._errorIsFatal=!1}_setFatalError(t){this._error=t,this._errorIsFatal=!0,(0,h.r)(this,"streams",{hasAudio:!1,hasVideo:!1})}_setRetryableError(t){this._error=t,this._errorIsFatal=!1,(0,h.r)(this,"streams",{hasAudio:!1,hasVideo:!1})}_reportStreams(t){var e;const i=null==t?void 0:t.split(",");(0,h.r)(this,"streams",{hasAudio:null!==(e=null==i?void 0:i.includes("mp4a"))&&void 0!==e&&e,hasVideo:null!=i&&i.includes("mp4a")?(null==i?void 0:i.length)>1:Boolean(null==i?void 0:i.length)})}_loadedData(){(0,h.r)(this,"load")}constructor(...t){super(...t),this.controls=!1,this.muted=!1,this.autoPlay=!1,this.playsInline=!1,this.allowExoPlayer=!1,this._errorIsFatal=!1,this._exoPlayer=!1,this._handleVisibilityChange=()=>{document.pictureInPictureElement||(document.hidden?this._cleanUp():(this._resetError(),this._startHls()))},this._resizeExoPlayer=()=>{if(!this._videoEl)return;const t=this._videoEl.getBoundingClientRect();this.hass.auth.external.fireMessage({type:"exoplayer/resize",payload:{left:t.left,top:t.top,right:t.right,bottom:t.bottom}})}}}u.streamCount=0,u.styles=(0,a.AH)(v||(v=y`:host,video{display:block}video{width:100%;max-height:var(--video-max-height,calc(100vh - 97px))}.fatal{display:block;padding:100px 16px}.retry{display:block}`)),(0,s.Cg)([(0,o.MZ)({attribute:!1})],u.prototype,"hass",void 0),(0,s.Cg)([(0,o.MZ)()],u.prototype,"entityid",void 0),(0,s.Cg)([(0,o.MZ)()],u.prototype,"url",void 0),(0,s.Cg)([(0,o.MZ)({attribute:"poster-url"})],u.prototype,"posterUrl",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],u.prototype,"aspectRatio",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],u.prototype,"fitMode",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"controls"})],u.prototype,"controls",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"muted"})],u.prototype,"muted",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"autoplay"})],u.prototype,"autoPlay",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"playsinline"})],u.prototype,"playsInline",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"allow-exoplayer"})],u.prototype,"allowExoPlayer",void 0),(0,s.Cg)([(0,o.P)("video")],u.prototype,"_videoEl",void 0),(0,s.Cg)([(0,o.wk)()],u.prototype,"_error",void 0),(0,s.Cg)([(0,o.wk)()],u.prototype,"_errorIsFatal",void 0),(0,s.Cg)([(0,o.wk)()],u.prototype,"_url",void 0),u=(0,s.Cg)([(0,o.EM)("ha-hls-player")],u),e()}catch(_){e(_)}})},71608:function(t,e,i){i.a(t,async function(t,e){try{i(74423),i(44114),i(18111),i(7588),i(3362),i(62953);var s=i(40445),a=i(5124),o=i(67576),r=i(63672),n=i(89784),h=i(1087),l=i(10897),d=i(38962),c=t([d]);d=(c.then?(await c)():c)[0];let p,_,g,m=t=>t;class v extends a.WF{render(){return this._error?(0,a.qy)(p||(p=m`<ha-alert alert-type="error">${0}</ha-alert>`),this._error):(0,a.qy)(_||(_=m` <video id="remote-stream" ?autoplay="${0}" .muted="${0}" ?playsinline="${0}" ?controls="${0}" poster="${0}" ="${0}" style="${0}"></video> `),this.autoPlay,this.muted,this.playsInline,this.controls,(0,r.J)(this.posterUrl),this._loadedData,(0,n.W)({height:null==this.aspectRatio?"100%":"auto",aspectRatio:this.aspectRatio,objectFit:this.fitMode}))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this.entityid&&this._startWebRtc(),document.addEventListener("visibilitychange",this._handleVisibilityChange)}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener("visibilitychange",this._handleVisibilityChange),this._cleanUp()}willUpdate(t){super.willUpdate(t),t.has("entityid")&&this._startWebRtc()}async _startWebRtc(){if(this._cleanUp(),"undefined"==typeof RTCPeerConnection)return this._error="WebRTC is not supported in this browser",void(0,h.r)(this,"streams",{hasAudio:!1,hasVideo:!1});this.hass&&this.entityid&&(this._error=void 0,this._startTimer(),this._logEvent("start clientConfig"),this._clientConfig=await(0,l.bT)(this.hass,this.entityid),this._logEvent("end clientConfig",this._clientConfig),this._peerConnection=new RTCPeerConnection(this._clientConfig.configuration),this._clientConfig.dataChannel&&this._peerConnection.createDataChannel(this._clientConfig.dataChannel),this._peerConnection.onnegotiationneeded=this._startNegotiation,this._peerConnection.onicecandidate=this._handleIceCandidate,this._peerConnection.oniceconnectionstatechange=this._iceConnectionStateChanged,this._peerConnection.onsignalingstatechange=t=>{if("stable"===t.target.signalingState)this._logEvent("ICE negotiation complete");else this._logEvent("Signaling state changed",t.target.signalingState)},this._remoteStream=new MediaStream,this._peerConnection.ontrack=this._addTrack,this._peerConnection.addTransceiver("audio",{direction:"recvonly"}),this._peerConnection.addTransceiver("video",{direction:"recvonly"}))}async _handleOfferEvent(t){if(this.entityid){if("session"===t.type&&(this._sessionId=t.session_id,this._candidatesList.forEach(e=>(0,l.UC)(this.hass,this.entityid,t.session_id,e.toJSON())),this._candidatesList=[]),"answer"===t.type&&(this._logEvent("answer",t.answer),this._handleAnswer(t)),"candidate"===t.type){this._logEvent("remote ice candidate",t.candidate);try{var e;const i=t.candidate.sdpMid||null!=t.candidate.sdpMLineIndex?new RTCIceCandidate(t.candidate):new RTCIceCandidate({candidate:t.candidate.candidate,sdpMid:"0"});await(null===(e=this._peerConnection)||void 0===e?void 0:e.addIceCandidate(i))}catch(i){console.error(i)}}"error"===t.type&&(this._error="Failed to start WebRTC stream: "+t.message,this._cleanUp())}}async _handleAnswer(t){var e;if(null===(e=this._peerConnection)||void 0===e||!e.signalingState||["stable","closed"].includes(this._peerConnection.signalingState))return;const i=new RTCSessionDescription({type:"answer",sdp:t.answer});try{this._logEvent("start setRemoteDescription",i),await this._peerConnection.setRemoteDescription(i)}catch(s){this._error="Failed to connect WebRTC stream: "+s.message,this._cleanUp()}this._logEvent("end setRemoteDescription")}_cleanUp(){var t;this._remoteStream&&(this._remoteStream.getTracks().forEach(t=>{t.stop()}),this._remoteStream=void 0);const e=this._videoEl;e&&(e.removeAttribute("src"),e.load()),this._peerConnection&&(this._peerConnection.close(),this._peerConnection.onnegotiationneeded=null,this._peerConnection.onicecandidate=null,this._peerConnection.oniceconnectionstatechange=null,this._peerConnection.onicegatheringstatechange=null,this._peerConnection.ontrack=null,this._peerConnection.onsignalingstatechange=null,this._peerConnection=void 0,this._logEvent("stopped"),this._stopTimer()),null===(t=this._unsub)||void 0===t||t.then(t=>t()),this._unsub=void 0,this._sessionId=void 0,this._candidatesList=[]}_loadedData(){const t=this._videoEl.srcObject,e={hasAudio:Boolean(null==t?void 0:t.getAudioTracks().length),hasVideo:Boolean(null==t?void 0:t.getVideoTracks().length)};(0,h.r)(this,"load"),(0,h.r)(this,"streams",e),this._logEvent("loadedData",e),this._stopTimer()}_startTimer(){}_stopTimer(){}_logEvent(t,...e){}constructor(...t){super(...t),this.controls=!1,this.muted=!1,this.autoPlay=!1,this.playsInline=!1,this._candidatesList=[],this._handleVisibilityChange=()=>{document.pictureInPictureElement||(document.hidden?this._cleanUp():this._startWebRtc())},this._startNegotiation=async()=>{if(!this._peerConnection)return;const t={offerToReceiveAudio:!0,offerToReceiveVideo:!0};this._logEvent("start createOffer",t);const e=await this._peerConnection.createOffer(t);if(!this._peerConnection)return;if(this._logEvent("end createOffer",e),this._logEvent("start setLocalDescription"),await this._peerConnection.setLocalDescription(e),!this._peerConnection||!this.entityid)return;this._logEvent("end setLocalDescription");let i="";for(;this._candidatesList.length;){const t=this._candidatesList.pop();t&&(i+=`a=${t}\r\n`)}const s=e.sdp+i;this._logEvent("start webRtcOffer",s);try{this._unsub=(0,l.w8)(this.hass,this.entityid,s,t=>this._handleOfferEvent(t))}catch(a){this._error="Failed to start WebRTC stream: "+a.message,this._cleanUp()}},this._iceConnectionStateChanged=()=>{var t,e;this._logEvent("ice connection state change",null===(t=this._peerConnection)||void 0===t?void 0:t.iceConnectionState),"failed"===(null===(e=this._peerConnection)||void 0===e?void 0:e.iceConnectionState)&&this._peerConnection.restartIce()},this._handleIceCandidate=t=>{var e,i,s;this.entityid&&null!==(e=t.candidate)&&void 0!==e&&e.candidate&&(this._logEvent("local ice candidate",null===(i=t.candidate)||void 0===i?void 0:i.candidate,null===(s=t.candidate)||void 0===s?void 0:s.sdpMLineIndex),this._sessionId?(0,l.UC)(this.hass,this.entityid,this._sessionId,t.candidate.toJSON()):this._candidatesList.push(t.candidate))},this._addTrack=async t=>{this._remoteStream&&("audio"===t.track.kind&&this.muted||(this._remoteStream.addTrack(t.track),this.hasUpdated||await this.updateComplete,this._videoEl.srcObject=this._remoteStream))}}}v.styles=(0,a.AH)(g||(g=m`:host,video{display:block}video{width:100%;max-height:var(--video-max-height,calc(100vh - 97px))}`)),(0,s.Cg)([(0,o.MZ)({attribute:!1})],v.prototype,"hass",void 0),(0,s.Cg)([(0,o.MZ)()],v.prototype,"entityid",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],v.prototype,"aspectRatio",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],v.prototype,"fitMode",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"controls"})],v.prototype,"controls",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"muted"})],v.prototype,"muted",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"autoplay"})],v.prototype,"autoPlay",void 0),(0,s.Cg)([(0,o.MZ)({type:Boolean,attribute:"playsinline"})],v.prototype,"playsInline",void 0),(0,s.Cg)([(0,o.MZ)({attribute:"poster-url"})],v.prototype,"posterUrl",void 0),(0,s.Cg)([(0,o.wk)()],v.prototype,"_error",void 0),(0,s.Cg)([(0,o.P)("#remote-stream")],v.prototype,"_videoEl",void 0),v=(0,s.Cg)([(0,o.EM)("ha-web-rtc-player")],v),e()}catch(p){e(p)}})},67013:function(t,e,i){i.d(e,{e:function(){return s}});const s=t=>t.attributes.access_token?`/api/image_proxy/${t.entity_id}?token=${t.attributes.access_token}&state=${t.state}`:void 0},57914:function(t,e,i){i.a(t,async function(t,e){try{i(74423),i(18111),i(22489),i(7588),i(3362),i(62953);var s=i(40445),a=i(5124),o=i(67576),r=i(6412),n=i(89784),h=i(46190),l=i(71727),d=i(58548),c=i(13062),p=i(65829),_=i(10897),g=i(22675),m=i(67013),v=i(17022),y=t([c,p]);[c,p]=y.then?(await y)():y;let u,b,C,f,I,S,E=t=>t;const w=1e4,M="grayscale(100%)",k=640,$=9/16;class R extends a.WF{connectedCallback(){super.connectedCallback(),void 0===this._loadState&&(this._loadState=1),this.cameraImage&&"live"!==this.cameraView&&this._startIntersectionObserverOrUpdates()}disconnectedCallback(){super.disconnectedCallback(),this._stopUpdateCameraInterval(),this._stopIntersectionObserver(),this._imageVisible=void 0}handleIntersectionCallback(t){this._imageVisible=t[0].isIntersecting}willUpdate(t){if(t.has("hass")){const e=t.get("hass");this._shouldStartCameraUpdates(e)?this._startIntersectionObserverOrUpdates():this.hass.connected||(this._stopUpdateCameraInterval(),this._stopIntersectionObserver(),this._loadState=1,this._cameraImageSrc=void 0,this._loadedImageSrc=void 0)}t.has("_imageVisible")&&(this._imageVisible?this._shouldStartCameraUpdates()&&this._startUpdateCameraInterval():this._stopUpdateCameraInterval()),t.has("aspectRatio")&&(this._ratio=this.aspectRatio?(0,d.A)(this.aspectRatio):null),1!==this._loadState||this.cameraImage||(this._loadState=2);const e=t.has("hass")&&!t.get("hass");this.hass&&(t.has("image")||e)&&(this.image&&(0,v.St)(this.image)?(0,v.A1)(this.hass,this.image).then(t=>{this._resolvedImageSrc=t.url}):this._resolvedImageSrc=this.image),this.hass&&(t.has("darkModeImage")||e)&&(this.darkModeImage&&(0,v.St)(this.darkModeImage)?(0,v.A1)(this.hass,this.darkModeImage).then(t=>{this._resolvedDarkModeImageSrc=t.url}):this._resolvedDarkModeImageSrc=this.darkModeImage),(t.has("stateImage")||e)&&(this._resolvedStateImages={},Object.entries(this.stateImage||{}).forEach(t=>{const e=t[0],i=t[1],s="object"==typeof i&&i.media_content_id||i;(0,v.St)(s)?(0,v.A1)(this.hass,s).then(t=>{this._resolvedStateImages=Object.assign(Object.assign({},this._resolvedStateImages),{},{[e]:t.url})}):this._resolvedStateImages[e]=s}))}render(){if(!this.hass)return a.s6;const t=Boolean(this._ratio&&this._ratio.w>0&&this._ratio.h>0),e=this.entity?this.hass.states[this.entity]:void 0,i=e?e.state:g.Hh;let s,o,d=!this.stateImage;if(this.cameraImage)"live"===this.cameraView?o=this.hass.states[this.cameraImage]:s=this._cameraImageSrc;else if(this.stateImage){const t=this._resolvedStateImages[i];t?s=t:(s=this._resolvedImageSrc,d=!0)}else s=this.darkModeImage&&this.hass.themes.darkMode?this._resolvedDarkModeImageSrc:e&&"image"===(0,l.m)(e.entity_id)?(0,m.e)(e):this._resolvedImageSrc;s&&(s=this.hass.hassUrl(s));let c=this.filter||"";if(this.hass.themes.darkMode&&this.darkModeFilter&&(c+=this.darkModeFilter),this.stateFilter&&this.stateFilter[i]&&(c+=this.stateFilter[i]),!c&&this.entity){c=(!e||h.jj.includes(i))&&d?M:""}return(0,a.qy)(u||(u=E` <div style="${0}" class="container ${0}"> ${0} ${0} </div> `),(0,n.W)({paddingBottom:t?`${(100*this._ratio.h/this._ratio.w).toFixed(2)}%`:void 0===this._lastImageHeight?"56.25%":void 0,backgroundImage:t&&this._loadedImageSrc?`url("${this._loadedImageSrc}")`:void 0,filter:2===this._loadState||"live"===this.cameraView?c:void 0}),(0,r.H)({ratio:t||void 0===this._lastImageHeight,contain:"contain"===this.fitMode,fill:"fill"===this.fitMode}),this.cameraImage&&"live"===this.cameraView?(0,a.qy)(b||(b=E` <ha-camera-stream muted .hass="${0}" .stateObj="${0}" .fitMode="${0}" .aspectRatio="${0}" ="${0}"></ha-camera-stream> `),this.hass,o,this.fitMode,this._ratio?this._ratio.w/this._ratio.h:void 0,this._onVideoLoad):void 0===s?a.s6:(0,a.qy)(C||(C=E` <img id="image" src="${0}" alt="${0}" ="${0}" ="${0}" style="${0}"> `),s,this.entity||"",this._onImageError,this._onImageLoad,(0,n.W)({display:t||2===this._loadState?"block":"none"})),3===this._loadState?(0,a.qy)(f||(f=E`<div id="brokenImage" style="${0}"></div>`),(0,n.W)({height:t?void 0:this._lastImageHeight?`${this._lastImageHeight}px`:"100%"})):"live"===this.cameraView||void 0!==s&&1!==this._loadState?"":(0,a.qy)(I||(I=E`<div class="progress-container" style="${0}"> <ha-spinner class="render-spinner" size="small"></ha-spinner> </div>`),(0,n.W)({height:t?void 0:this._lastImageHeight?`${this._lastImageHeight}px`:"100%"})))}_shouldStartCameraUpdates(t){return!(t&&t.connected===this.hass.connected||!this.hass.connected||"live"===this.cameraView)}_startIntersectionObserverOrUpdates(){"IntersectionObserver"in window?(this._intersectionObserver||(this._intersectionObserver=new IntersectionObserver(this.handleIntersectionCallback.bind(this))),this._intersectionObserver.observe(this)):(this._imageVisible=!0,this._startUpdateCameraInterval())}_stopIntersectionObserver(){this._intersectionObserver&&this._intersectionObserver.disconnect()}_startUpdateCameraInterval(){this._stopUpdateCameraInterval(),this._updateCameraImageSrc(),this.cameraImage&&this.isConnected&&(this._cameraUpdater=window.setInterval(()=>this._updateCameraImageSrcAtInterval(),w))}_stopUpdateCameraInterval(){this._cameraUpdater&&(clearInterval(this._cameraUpdater),this._cameraUpdater=void 0)}_onImageError(){this._loadState=3}async _onImageLoad(t){this._loadState=2;const e=t.target;this._ratio&&this._ratio.w>0&&this._ratio.h>0&&(this._loadedImageSrc=e.src),await this.updateComplete,this._lastImageHeight=e.offsetHeight}async _onVideoLoad(t){this._loadState=2;const e=t.currentTarget;await this.updateComplete,this._lastImageHeight=e.offsetHeight}async _updateCameraImageSrcAtInterval(){return 1===this._loadState&&this._onImageError(),this._updateCameraImageSrc()}async _updateCameraImageSrc(){if(!this.hass||!this.cameraImage)return;if(!this.hass.states[this.cameraImage])return void this._onImageError();const t=this.clientWidth||k;let e,i=Math.ceil(t*devicePixelRatio);this._lastImageHeight?e=Math.ceil(this._lastImageHeight*devicePixelRatio):this._ratio&&this._ratio.w>0&&this._ratio.h>0?e=Math.ceil(i*(this._ratio.h/this._ratio.w)):(i*=2,e=Math.ceil(i*$)),this._cameraImageSrc=await(0,_.C4)(this.hass,this.cameraImage,i,e),void 0===this._cameraImageSrc&&this._onImageError()}constructor(...t){super(...t),this._imageVisible=!1,this._resolvedStateImages={},this._ratio=null}}R.styles=(0,a.AH)(S||(S=E`:host{display:block}.container{transition:filter .2s linear;height:100%}img{display:block;height:100%;width:100%;object-fit:cover}ha-camera-stream{display:block;height:100%;width:100%}.progress-container{display:flex;justify-content:center;align-items:center}.ratio{position:relative;width:100%;height:0;background-position:center;background-size:cover}.ratio.fill{background-size:100% 100%}.ratio.contain{background-size:contain;background-repeat:no-repeat}.fill img{object-fit:fill}.contain img{object-fit:contain}.ratio div,.ratio img{position:absolute;top:0;left:0;width:100%;height:100%}.ratio img{visibility:hidden}#brokenImage{background:grey url("/static/images/image-broken.svg") center/36px no-repeat}`)),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"hass",void 0),(0,s.Cg)([(0,o.MZ)()],R.prototype,"entity",void 0),(0,s.Cg)([(0,o.MZ)()],R.prototype,"image",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"stateImage",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"cameraImage",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"cameraView",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"aspectRatio",void 0),(0,s.Cg)([(0,o.MZ)()],R.prototype,"filter",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"stateFilter",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"darkModeImage",void 0),(0,s.Cg)([(0,o.MZ)({attribute:!1})],R.prototype,"darkModeFilter",void 0),(0,s.Cg)([(0,o.MZ)({attribute:"fit-mode",type:String})],R.prototype,"fitMode",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_imageVisible",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_loadState",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_cameraImageSrc",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_loadedImageSrc",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_resolvedImageSrc",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_resolvedDarkModeImageSrc",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_resolvedStateImages",void 0),(0,s.Cg)([(0,o.wk)()],R.prototype,"_lastImageHeight",void 0),R=(0,s.Cg)([(0,o.EM)("hui-image")],R),e()}catch(u){e(u)}})}}]);