Skip to content

Commit

Permalink
feature: show power button if supported by device
Browse files Browse the repository at this point in the history
  • Loading branch information
punxaphil committed Apr 8, 2024
1 parent ac144de commit ee9d6f9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { css, html, LitElement, nothing } from 'lit';
import { property } from 'lit/decorators.js';
import MediaControlService from '../services/media-control-service';
import Store from '../model/store';
import { CardConfig } from '../types';
import { CardConfig, MediaPlayerEntityFeature } from '../types';
import { mdiVolumeHigh, mdiVolumeMute } from '@mdi/js';
import { MediaPlayer } from '../model/media-player';

const { TURN_ON, TURN_OFF } = MediaPlayerEntityFeature;

class Volume extends LitElement {
@property({ attribute: false }) store!: Store;
private config!: CardConfig;
Expand All @@ -24,6 +26,9 @@ class Volume extends LitElement {

const muteIcon = this.player.isMuted(this.updateMembers) ? mdiVolumeMute : mdiVolumeHigh;
const disabled = this.player.ignoreVolume;
const supportsTurnOn = (this.player.attributes.supported_features || 0) & TURN_ON;
const showPowerButton = supportsTurnOn && nothing;

return html`
<div class="volume" slim=${this.slim || nothing}>
<ha-icon-button .disabled=${disabled} @click=${this.mute} .path=${muteIcon}> </ha-icon-button>
Expand All @@ -40,6 +45,11 @@ class Volume extends LitElement {
<div style="flex: ${max - volume};text-align: right">${max}%</div>
</div>
</div>
<sonos-ha-player
hide=${showPowerButton}
.store=${this.store}
.features=${[TURN_ON, TURN_OFF]}
></sonos-ha-player>
</div>
`;
}
Expand Down Expand Up @@ -102,6 +112,9 @@ class Volume extends LitElement {
font-weight: bold;
font-size: 12px;
}
*[hide] {
display: none;
}
`;
}
}
Expand Down

0 comments on commit ee9d6f9

Please sign in to comment.