- `}iconItemStyle(t){return yt("media-button",this.config,Object.assign(Object.assign(Object.assign(Object.assign({},this.mediaButtonStyle()),{flexDirection:"column",borderRadius:"var(--sonos-int-border-radius)",justifyContent:"center",backgroundColor:"var(--sonos-int-background-color)"}),(t||this.mediaItem.can_expand)&&{backgroundSize:"contain",backgroundRepeat:"no-repeat",backgroundPosition:"center",position:"relative",paddingBottom:"calc(100% - (var(--sonos-int-border-width) * 2))"}),t&&{backgroundImage:"url("+t+")"}))}titleStyle(t){return yt("media-button-title",this.config,Object.assign({width:"calc(100% - 1rem)",fontSize:"1rem",padding:"0px 0.5rem"},(t||this.mediaItem.can_expand)&&{zIndex:"1",textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"var(--sonos-int-media-button-white-space)",backgroundColor:"var(--sonos-int-player-section-background)",position:"absolute",top:"0rem",left:"0rem"}))}folderStyle(t){return yt("media-button-folder",this.config,Object.assign({marginBottom:"-120%","--mdc-icon-size":"70%"},(!this.mediaItem.can_expand||t)&&{display:"none"}))}}t([tt()],te.prototype,"mediaItem",void 0),t([tt()],te.prototype,"config",void 0),customElements.define("sonos-media-icon-item",te);class ee extends J{constructor(){super(...arguments),this.headerChildStyle={flex:"1","--mdc-icon-size":"1.5rem"}}render(){var t;return j`
-
-
- ${(null===(t=this.currentDir)||void 0===t?void 0:t.can_play)?j` await this.mediaBrowser.playItem(this.currentDir)}"
- >`:""}
-
-
${this.config.mediaTitle?this.config.mediaTitle:"Media"}
-
this.mediaBrowser.browseClicked()}">
-
-
+
+ await this.mediaControlService.volumeDown(e,t)}
+ .path=${Qe}
+ >
+
+ await this.mediaControlService.volumeUp(e,t)}
+ .path=${pe}
+ >
+ this.toggleShowSwitches(e)}
+ .path=${"M12,15.5A3.5,3.5 0 0,1 8.5,12A3.5,3.5 0 0,1 12,8.5A3.5,3.5 0 0,1 15.5,12A3.5,3.5 0 0,1 12,15.5M19.43,12.97C19.47,12.65 19.5,12.33 19.5,12C19.5,11.67 19.47,11.34 19.43,11L21.54,9.37C21.73,9.22 21.78,8.95 21.66,8.73L19.66,5.27C19.54,5.05 19.27,4.96 19.05,5.05L16.56,6.05C16.04,5.66 15.5,5.32 14.87,5.07L14.5,2.42C14.46,2.18 14.25,2 14,2H10C9.75,2 9.54,2.18 9.5,2.42L9.13,5.07C8.5,5.32 7.96,5.66 7.44,6.05L4.95,5.05C4.73,4.96 4.46,5.05 4.34,5.27L2.34,8.73C2.21,8.95 2.27,9.22 2.46,9.37L4.57,11C4.53,11.34 4.5,11.67 4.5,12C4.5,12.33 4.53,12.65 4.57,12.97L2.46,14.63C2.27,14.78 2.21,15.05 2.34,15.27L4.34,18.73C4.46,18.95 4.73,19.03 4.95,18.95L7.44,17.94C7.96,18.34 8.5,18.68 9.13,18.93L9.5,21.58C9.54,21.82 9.75,22 10,22H14C14.25,22 14.46,21.82 14.5,21.58L14.87,18.93C15.5,18.67 16.04,18.34 16.56,17.94L19.05,18.95C19.27,19.03 19.54,18.95 19.66,18.73L21.66,15.27C21.78,15.05 21.73,14.78 21.54,14.63L19.43,12.97Z"}
+ show-switches=${this.showSwitches[e.id]||W}
+ >
- `}headerStyle(){return yt("media-browser-header",this.config,Object.assign({display:"flex",justifyContent:"space-between"},Kt))}titleStyle(){return yt("title",this.config,this.headerChildStyle)}playDirStyle(){return yt("media-browser-play-dir",this.config,Object.assign({textAlign:"left",paddingRight:"-0.5rem",marginLeft:"0.5rem"},this.headerChildStyle))}browseStyle(){return yt("media-browse",this.config,Object.assign({textAlign:"right",paddingRight:"0.5rem",marginLeft:"-0.5rem"},this.headerChildStyle))}static get styles(){return n`
- .hoverable:focus,
- .hoverable:hover {
- color: var(--sonos-int-accent-color);
- }
- `}}function ie(t=[],e){return null==e?void 0:e.filter((e=>-1===["media-source://tts","media-source://camera"].indexOf(e.media_content_id||"")&&-1===t.indexOf(e.title)))}t([tt()],ee.prototype,"hass",void 0),t([tt()],ee.prototype,"config",void 0),t([tt()],ee.prototype,"mediaBrowser",void 0),t([tt()],ee.prototype,"browse",void 0),t([tt()],ee.prototype,"currentDir",void 0),customElements.define("sonos-media-browser-header",ee);class se{constructor(t,e){this.hass=t,this.hassService=e}async getRoot(t,e){return ie(e,(await this.hassService.browseMedia(t)).children)||[]}async getDir(t,e,i){try{return ie(i,(await this.hassService.browseMedia(t,e.media_content_type,e.media_content_id)).children)||[]}catch(t){return console.error(t),[]}}async getAllFavorites(t,e){if(!t.length)return[];let i=(await Promise.all(t.map((t=>this.getFavoritesForPlayer(t,e))))).flatMap((t=>t));return i=this.removeDuplicates(i),i.length?i:this.getFavoritesFromStates(t)}removeDuplicates(t){return t.filter(((t,e,i)=>e===i.findIndex((e=>e.title===t.title))))}async getFavoritesForPlayer(t,e){var i;const s=null===(i=(await this.hassService.browseMedia(t,"favorites","")).children)||void 0===i?void 0:i.map((e=>this.hassService.browseMedia(t,e.media_content_type,e.media_content_id)));return(s?await Promise.all(s):[]).flatMap((t=>ie(e,t.children)||[]))}getFavoritesFromStates(t){console.log("Custom Sonos Card: found no favorites with thumbnails, trying with titles only");let e=t.map((t=>this.hass.states[t])).flatMap((t=>t.attributes.source_list));return e=[...new Set(e)],e.length||console.log("Custom Sonos Card: No favorites found"),e.map((t=>({title:t})))}}class oe extends J{constructor(){super(...arguments),this.mediaItems=[],this.parentDirs=[],this.entityIdListener=t=>{this.entityId=t.detail.entityId}}connectedCallback(){super.connectedCallback(),bt(this.entityIdListener)}disconnectedCallback(){At(this.entityIdListener),super.disconnectedCallback()}setConfig(t){const e=JSON.parse(JSON.stringify(t));wt(e),this.config=e}render(){if(!this.entityId&&this.config.entityId&&(this.entityId=this.config.entityId),this.entityId&&this.hass){this.hassService=new Pt(this.hass),this.mediaBrowseService=new se(this.hass,this.hassService),this.mediaControlService=new Ot(this.hass,this.hassService),this.mediaPlayers=ht(this.config,this.hass);const t=localStorage.getItem("custom-sonos-card_currentDir");t&&(this.currentDir=JSON.parse(t),this.browse=!0);return $t(j`
-
-
- ${""!==this.entityId&&Gt((this.browse?this.loadMediaDir(this.currentDir):this.getAllFavorites()).then((t=>{const e=oe.hasItemsWithImage(t),i=oe.hasFolderItems(t),s=this.getMediaItemWidth(e,i);return j`
- ${t.map((t=>{const i=async()=>await this.onMediaItemClick(t),o=`width: ${s};max-width: ${s};`;return this.config.mediaBrowserItemsAsList?j`
-
- `:j`
-
- `}))}
-
`})))}
+
+
+
+ ${He(this.getAdditionalControls(o,e))}
+
+
`}toggleShowSwitches(e){this.showSwitches[e.id]=!this.showSwitches[e.id],this.requestUpdate()}async getAdditionalControls(e,t){if(e)return;return(await this.hassService.getRelatedEntities(t,"switch","number","sensor")).map((e=>{var A,i,s;return e.attributes.friendly_name=null!==(s=null===(i=null===(A=e.attributes.friendly_name)||void 0===A?void 0:A.replaceAll(t.name,""))||void 0===i?void 0:i.trim())&&void 0!==s?s:"",j`
+
+
- `,this.config)}return ft}getMediaItemWidth(t,e){var i,s;return t||e?this.config.mediaBrowserItemsAsList?mt(this.config,"100%","100%",null===(i=this.config.layout)||void 0===i?void 0:i.mediaItem):mt(this.config,"33%","16%",null===(s=this.config.layout)||void 0===s?void 0:s.mediaItem):"100%"}browseClicked(){this.parentDirs.length?this.setCurrentDir(this.parentDirs.pop()):this.currentDir?this.setCurrentDir(void 0):this.browse=!this.browse}setCurrentDir(t){this.currentDir=t,t?localStorage.setItem("custom-sonos-card_currentDir",JSON.stringify(t)):localStorage.removeItem("custom-sonos-card_currentDir")}async onMediaItemClick(t){t.can_expand?(this.currentDir&&this.parentDirs.push(this.currentDir),this.setCurrentDir(t)):t.can_play&&await this.playItem(t)}async playItem(t){t.media_content_type||t.media_content_id?await this.mediaControlService.playMedia(this.entityId,t):await this.mediaControlService.setSource(this.entityId,t.title)}async getAllFavorites(){var t,e,i,s;let o=await this.mediaBrowseService.getAllFavorites(this.mediaPlayers,this.config.mediaBrowserTitlesToIgnore);return this.config.shuffleFavorites?oe.shuffleArray(o):o=o.sort(((t,e)=>t.title.localeCompare(e.title,"en",{sensitivity:"base"}))),[...(null===(e=null===(t=this.config.customSources)||void 0===t?void 0:t[this.entityId])||void 0===e?void 0:e.map(oe.createSource))||[],...(null===(s=null===(i=this.config.customSources)||void 0===i?void 0:i.all)||void 0===s?void 0:s.map(oe.createSource))||[],...o]}static createSource(t){return Object.assign(Object.assign({},t),{can_play:!0})}static shuffleArray(t){for(let e=t.length-1;e>0;e--){const i=Math.floor(Math.random()*(e+1));[t[e],t[i]]=[t[i],t[e]]}}static hasItemsWithImage(t){return t.some((t=>t.thumbnail))}static hasFolderItems(t){return t.some((t=>t.can_expand))}async loadMediaDir(t){return await(t?this.mediaBrowseService.getDir(this.entityId,t,this.config.mediaBrowserTitlesToIgnore):this.mediaBrowseService.getRoot(this.entityId,this.config.mediaBrowserTitlesToIgnore))}mediaButtonsStyle(t,e){return yt("media-buttons",this.config,Object.assign({padding:"0",display:"flex",flexWrap:"wrap"},!t&&!e&&{flexDirection:"column"}))}static get styles(){return St}}t([tt({attribute:!1})],oe.prototype,"hass",void 0),t([tt()],oe.prototype,"config",void 0),t([et()],oe.prototype,"browse",void 0),t([et()],oe.prototype,"currentDir",void 0),t([et()],oe.prototype,"mediaItems",void 0),t([et()],oe.prototype,"entityId",void 0);const ne=t=>"Sonos"+(t?` (${t})`:""),re=t=>"Media player for your Sonos speakers"+(t?` (${t})`:"");window.customCards.push({type:"sonos-card",name:ne(),description:re(),preview:!0},{type:"sonos-grouping",name:ne("Grouping section"),description:re("Grouping section"),preview:!0},{type:"sonos-groups",name:ne("Groups section"),description:re("Groups section"),preview:!0},{type:"sonos-media-browser",name:ne("Media Browser section"),description:re("Media Browser section"),preview:!0},{type:"sonos-player",name:ne("Player section"),description:"Media player for your Sonos speakers (Player section)",preview:!0}),customElements.define("custom-sonos-card",class extends Qt{setConfig(t){console.error("type: custom:custom-sonos-card is deprecated, please use custom:sonos-card instead"),super.setConfig(t)}}),customElements.define("sonos-card",Qt),customElements.define("sonos-grouping",Zt),customElements.define("sonos-groups",Ft),customElements.define("sonos-media-browser",oe),customElements.define("sonos-player",qt);
+ `}))}static get styles(){return r`
+ .row {
+ display: flex;
+ flex-direction: column;
+ padding-top: 0.3rem;
+ padding-right: 1rem;
+ padding-bottom: 0.2rem;
+ }
+
+ .row:not(:first-child) {
+ border-top: solid var(--secondary-background-color);
+ }
+
+ .row:first-child {
+ padding-top: 1rem;
+ }
+
+ .switches {
+ display: flex;
+ justify-content: center;
+ flex-direction: column;
+ gap: 1rem;
+ }
+
+ .volume-name {
+ flex: 1;
+ overflow: hidden;
+ flex-direction: column;
+ text-align: center;
+ }
+
+ .volume-name-text {
+ flex: 1;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ font-size: 1.1rem;
+ font-weight: bold;
+ min-height: 1rem;
+ }
+
+ .slider-row {
+ display: flex;
+ }
+
+ sonos-volume {
+ flex: 4;
+ }
+
+ *[show-switches] {
+ color: var(--accent-color);
+ }
+
+ *[hide] {
+ display: none;
+ }
+ `}}e([ae({attribute:!1})],pA.prototype,"store",void 0),e([le()],pA.prototype,"showSwitches",void 0),customElements.define("sonos-volumes",pA);class mA extends se{render(){const e=this.store.hass.states[this.store.activePlayer.id];let t=0;this.features.forEach((e=>t+=e));const A=Object.assign(Object.assign({},e),{attributes:Object.assign(Object.assign({},e.attributes),{supported_features:t})});return j`
`}}e([ae({attribute:!1})],mA.prototype,"store",void 0),e([ae({attribute:!1})],mA.prototype,"features",void 0),customElements.define("sonos-ha-player",mA),window.customCards.push({type:"sonos-card",name:"Sonos",description:"Media player for your Sonos speakers",preview:!0}),customElements.define("sonos-card",nA),customElements.define("sonos-grouping",cA),customElements.define("sonos-groups",hA),customElements.define("sonos-media-browser",uA),customElements.define("sonos-player",gt);
+//# sourceMappingURL=custom-sonos-card.js.map