diff --git a/dist/spotify-card.js b/dist/spotify-card.js index 7a52364..8d4cb0d 100644 --- a/dist/spotify-card.js +++ b/dist/spotify-card.js @@ -429,7 +429,7 @@ found at http://polymer.github.io/PATENTS.txt paper-slider { width: auto; } - `}};e([Z({type:Object})],Je.prototype,"hass",void 0),e([J()],Je.prototype,"config",void 0),e([J()],Je.prototype,"_toggle",void 0),e([J()],Je.prototype,"lib",void 0),Je=e([G("spotify-card-editor")],Je);class Ke{constructor(e){this._spotify_installed=!1,this._fetch_time_out=0,this._parent=e,this.hass=e.hass}setConfig(e){return this.config=e,this.config.playlist_type&&!Object.values(ne).includes(this.config.playlist_type.toLowerCase())?"playlist_type":this.config.display_style&&!Object.values(se).includes(this.config.display_style.toLowerCase())?"display_style":""}getDisplayStyle(){var e;return"grid"==(null===(e=this.config.display_style)||void 0===e?void 0:e.toLowerCase())?se.Grid:se.List}getPlayingState(){var e,t;return null!==(t="playing"==(null===(e=this.spotify_state)||void 0===e?void 0:e.state))&&void 0!==t&&t}getShuffleState(){var e,t;return null!==(t=null===(e=this._spotcast_connector.player)||void 0===e?void 0:e.shuffle_state)&&void 0!==t&&t}getSpotifyEntityState(){return this.spotify_state?this.spotify_state.state:""}isSpotcastInstalled(){var e;return!(!(null===(e=this.hass)||void 0===e?void 0:e.connection)||void 0===this.getHassConnection().state.spotcast)}getHassConnection(){return e=this.hass.connection,_e(e,"_srv",Se,Ce);var e}isSpotifyInstalled(){return this._spotify_installed}async requestUpdate(){this.isSpotcastInstalled()&&!this._spotcast_connector.is_loading()&&await this._spotcast_connector.updateState().then(async()=>{await this._spotcast_connector.fetchPlaylists().then(async()=>{await this._parent.requestUpdate()})})}getCurrentPlayer(){return this._spotcast_connector.getCurrentPlayer()}dataAvailable(){return this._spotcast_connector.is_loaded()}updated(e){this.hass=e,this.doSubscribeEntities()}connectedCallback(){this._spotcast_connector=new ke(this),this.doSubscribeEntities(),this.hass&&this.requestUpdate()}disconnectedCallback(){this._unsubscribe_entitites&&(this._unsubscribe_entitites(),this._unsubscribe_entitites=void 0)}doSubscribeEntities(){var e;(null===(e=this.hass)||void 0===e?void 0:e.connection)&&!this._unsubscribe_entitites&&this._parent.isHASSConnected()&&(this._unsubscribe_entitites=$e(this.hass.connection,e=>this.entitiesUpdated(e)))}entitiesUpdated(e){let t=!1;for(const i in e)i.startsWith("media_player")&&((i.startsWith("media_player.spotify")||i==this.config.spotify_entity)&&(this._spotify_installed=!0,this.spotify_state=e[i]),t=!0);t&&!document.hidden&&(this._fetch_time_out&&clearTimeout(this._fetch_time_out),this._fetch_time_out=setTimeout(()=>{this.requestUpdate()},500))}checkIfAllowedToShow(e){var t,i;const s=null!==(i=null===(t=this.config.filter_devices)||void 0===t?void 0:t.map(e=>new RegExp(e+"$")))&&void 0!==i?i:[];for(const t of s)if(t.test("name"in e?e.name:e.friendly_name))return!1;return!0}getDefaultDevice(){let[e,t]=this.getFilteredDevices();if(e=e.filter(e=>e.name==this.config.default_device),t=t.filter(e=>e.friendly_name==this.config.default_device),e.length>0||t.length>0)return this.config.default_device}getFilteredDevices(){return[this._spotcast_connector.devices.filter(this.checkIfAllowedToShow,this),this._spotcast_connector.chromecast_devices.filter(this.checkIfAllowedToShow,this)]}getPlaylists(){return this._spotcast_connector.playlists}isThisPlaylistPlaying(e){var t;return(null===(t=this.spotify_state)||void 0===t?void 0:t.attributes.media_playlist)===e.name}playUri(e,t){const i=e.srcElement;"div"==(null==i?void 0:i.localName)?i.children[1].classList.add("loading"):"svg"==(null==i?void 0:i.localName)?i.parentElement.classList.add("loading"):"path"==(null==i?void 0:i.localName)&&i.parentElement.parentElement.classList.add("loading"),this._spotcast_connector.playUri(t)}onShuffleSelect(){var e,t;"playing"==(null===(e=this.spotify_state)||void 0===e?void 0:e.state)&&this.hass.callService("media_player","shuffle_set",{entity_id:this.spotify_state.entity_id,shuffle:!(null===(t=this._spotcast_connector.player)||void 0===t?void 0:t.shuffle_state)})}handlePlayPauseEvent(e,t){e.stopPropagation(),this.spotify_state&&this.hass.callService("media_player",t,{entity_id:this.spotify_state.entity_id})}spotifyDeviceSelected(e){if(this._spotcast_connector.getCurrentPlayer())return this._spotcast_connector.transferPlaybackToConnectDevice(e.id);const t=this._spotcast_connector.playlists[0];console.log("spotifyDeviceSelected playing first playlist"),this._spotcast_connector.playUriOnConnectDevice(e.id,t.uri)}chromecastDeviceSelected(e){if(this._spotcast_connector.getCurrentPlayer())return this._spotcast_connector.transferPlaybackToCastDevice(e.friendly_name);const t=this._spotcast_connector.playlists[0];console.log("chromecastDeviceSelected playing first playlist"),this._spotcast_connector.playUriOnCastDevice(e.friendly_name,t.uri)}}var Qe;console.info(`%c SPOTIFY-CARD \n%c ${fe("common.version")} 2.1.1 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"spotify-card",name:"Spotify Card",description:fe("common.description"),preview:!0});let Xe=Qe=class extends ie{constructor(){super(),this.lib=new Ke(this)}static async getConfigElement(){return document.createElement("spotify-card-editor")}static getStubConfig(){return{}}setConfig(e){const t=this.lib.setConfig(e);if(e.show_error||""!=t)throw new Error(fe("common.invalid_configuration")+": "+t)}connectedCallback(){super.connectedCallback(),this.lib.connectedCallback()}updated(e){super.updated(e),this.lib.updated(this.hass)}disconnectedCallback(){super.disconnectedCallback(),this.lib.disconnectedCallback()}isHASSConnected(){return this.isConnected}render(){var e,t,i;let s=z``;this.lib.isSpotcastInstalled()||(s=this.showWarning(fe("common.show_missing_spotcast"))),this.lib.isSpotifyInstalled()||(s=this.showWarning(fe("common.show_missing_spotify")));let n=z`
Loading...
`;if(this.lib.dataAvailable())switch(this.lib.getDisplayStyle()){case se.Grid:n=this.generateGridView();break;default:n=this.generateListView()}else this.lib.requestUpdate();return z` + `}};e([Z({type:Object})],Je.prototype,"hass",void 0),e([J()],Je.prototype,"config",void 0),e([J()],Je.prototype,"_toggle",void 0),e([J()],Je.prototype,"lib",void 0),Je=e([G("spotify-card-editor")],Je);class Ke{constructor(e){this._spotify_installed=!1,this._fetch_time_out=0,this._parent=e,this.hass=e.hass}setConfig(e){return this.config=e,this.config.playlist_type&&!Object.values(ne).includes(this.config.playlist_type.toLowerCase())?"playlist_type":this.config.display_style&&!Object.values(se).includes(this.config.display_style.toLowerCase())?"display_style":""}getDisplayStyle(){var e;return"grid"==(null===(e=this.config.display_style)||void 0===e?void 0:e.toLowerCase())?se.Grid:se.List}getPlayingState(){var e,t;return null!==(t="playing"==(null===(e=this.spotify_state)||void 0===e?void 0:e.state))&&void 0!==t&&t}getShuffleState(){var e,t;return null!==(t=null===(e=this._spotcast_connector.player)||void 0===e?void 0:e.shuffle_state)&&void 0!==t&&t}getSpotifyEntityState(){return this.spotify_state?this.spotify_state.state:""}isSpotcastInstalled(){var e;return!(!(null===(e=this.hass)||void 0===e?void 0:e.connection)||void 0===this.getHassConnection().state.spotcast)}getHassConnection(){return e=this.hass.connection,_e(e,"_srv",Se,Ce);var e}isSpotifyInstalled(){return this._spotify_installed}async requestUpdate(){this.isSpotcastInstalled()&&!this._spotcast_connector.is_loading()&&await this._spotcast_connector.updateState().then(async()=>{await this._spotcast_connector.fetchPlaylists().then(async()=>{await this._parent.requestUpdate()})})}getCurrentPlayer(){return this._spotcast_connector.getCurrentPlayer()}dataAvailable(){return this._spotcast_connector.is_loaded()}updated(e){this.hass=e,this.doSubscribeEntities()}connectedCallback(){this._spotcast_connector=new ke(this),this.doSubscribeEntities(),this.hass&&this.requestUpdate()}disconnectedCallback(){this._unsubscribe_entitites&&(this._unsubscribe_entitites(),this._unsubscribe_entitites=void 0)}doSubscribeEntities(){var e;(null===(e=this.hass)||void 0===e?void 0:e.connection)&&!this._unsubscribe_entitites&&this._parent.isHASSConnected()&&(this._unsubscribe_entitites=$e(this.hass.connection,e=>this.entitiesUpdated(e)))}entitiesUpdated(e){let t=!1;for(const i in e)i.startsWith("media_player")&&((i.startsWith("media_player.spotify")||i==this.config.spotify_entity)&&(this._spotify_installed=!0,this.spotify_state=e[i]),t=!0);t&&!document.hidden&&(this._fetch_time_out&&clearTimeout(this._fetch_time_out),this._fetch_time_out=setTimeout(()=>{this.requestUpdate()},500))}checkIfAllowedToShow(e){var t,i;const s=null!==(i=null===(t=this.config.filter_devices)||void 0===t?void 0:t.map(e=>new RegExp(e+"$")))&&void 0!==i?i:[];for(const t of s)if(t.test("name"in e?e.name:e.friendly_name))return!1;return!0}getDefaultDevice(){let[e,t]=this.getFilteredDevices();if(e=e.filter(e=>e.name==this.config.default_device),t=t.filter(e=>e.friendly_name==this.config.default_device),e.length>0||t.length>0)return this.config.default_device}getFilteredDevices(){return[this._spotcast_connector.devices.filter(this.checkIfAllowedToShow,this),this._spotcast_connector.chromecast_devices.filter(this.checkIfAllowedToShow,this)]}getPlaylists(){return this._spotcast_connector.playlists}isThisPlaylistPlaying(e){var t;return(null===(t=this.spotify_state)||void 0===t?void 0:t.attributes.media_playlist)===e.name}playUri(e,t){const i=e.srcElement;"div"==(null==i?void 0:i.localName)?i.children[1].classList.add("loading"):"svg"==(null==i?void 0:i.localName)?i.parentElement.classList.add("loading"):"path"==(null==i?void 0:i.localName)&&i.parentElement.parentElement.classList.add("loading"),this._spotcast_connector.playUri(t)}onShuffleSelect(){var e,t;"playing"==(null===(e=this.spotify_state)||void 0===e?void 0:e.state)&&this.hass.callService("media_player","shuffle_set",{entity_id:this.spotify_state.entity_id,shuffle:!(null===(t=this._spotcast_connector.player)||void 0===t?void 0:t.shuffle_state)})}handlePlayPauseEvent(e,t){e.stopPropagation(),this.spotify_state&&this.hass.callService("media_player",t,{entity_id:this.spotify_state.entity_id})}spotifyDeviceSelected(e){if(this._spotcast_connector.getCurrentPlayer())return this._spotcast_connector.transferPlaybackToConnectDevice(e.id);const t=this._spotcast_connector.playlists[0];console.log("spotifyDeviceSelected playing first playlist"),this._spotcast_connector.playUriOnConnectDevice(e.id,t.uri)}chromecastDeviceSelected(e){if(this._spotcast_connector.getCurrentPlayer())return this._spotcast_connector.transferPlaybackToCastDevice(e.friendly_name);const t=this._spotcast_connector.playlists[0];console.log("chromecastDeviceSelected playing first playlist"),this._spotcast_connector.playUriOnCastDevice(e.friendly_name,t.uri)}}var Qe;console.info(`%c SPOTIFY-CARD \n%c ${fe("common.version")} 2.1.2 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"spotify-card",name:"Spotify Card",description:fe("common.description"),preview:!0});let Xe=Qe=class extends ie{constructor(){super(),this.lib=new Ke(this)}static async getConfigElement(){return document.createElement("spotify-card-editor")}static getStubConfig(){return{}}setConfig(e){const t=this.lib.setConfig(e);if(e.show_error||""!=t)throw new Error(fe("common.invalid_configuration")+": "+t)}connectedCallback(){super.connectedCallback(),this.lib.connectedCallback()}updated(e){super.updated(e),this.lib.updated(this.hass)}disconnectedCallback(){super.disconnectedCallback(),this.lib.disconnectedCallback()}isHASSConnected(){return this.isConnected}render(){var e,t,i;let s=z``;this.lib.isSpotcastInstalled()||(s=this.showWarning(fe("common.show_missing_spotcast"))),this.lib.isSpotifyInstalled()||(s=this.showWarning(fe("common.show_missing_spotify")));let n=z`
Loading...
`;if(this.lib.dataAvailable())switch(this.lib.getDisplayStyle()){case se.Grid:n=this.generateGridView();break;default:n=this.generateListView()}else this.lib.requestUpdate();return z` ${this.lib.config.hide_warning?"":s}