Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set volume #46

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions custom_components/yoto/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ async def async_resume_player(self, player_id: str) -> None:
async def async_stop_player(self, player_id: str) -> None:
await self.async_check_and_refresh_token()
await self.hass.async_add_executor_job(self.yoto_manager.stop_player, player_id)

async def async_set_volume(self, player_id: str, volume: float) -> None:
volume = volume * 100
volume = int(round(volume, 0))
await self.async_check_and_refresh_token()
await self.hass.async_add_executor_job(
self.yoto_manager.set_volume, player_id, volume
)
5 changes: 5 additions & 0 deletions custom_components/yoto/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(
self._attr_name = "Media Player"
self._attr_device_class = MediaPlayerDeviceClass.SPEAKER
self._currently_playing: dict | None = {}
self._attr_volume_step = 0.0625
self._restricted_device: bool = False

async def async_media_pause(self) -> None:
Expand All @@ -67,13 +68,17 @@ async def async_media_play(self) -> None:
async def async_media_stop(self) -> None:
await self.coordinator.async_stop_player(self.player.id)

async def async_set_volume_level(self, volume: float) -> None:
await self.coordinator.async_set_volume(self.player.id, volume)

@property
def supported_features(self) -> MediaPlayerEntityFeature:
"""Return the supported features."""
return (
MediaPlayerEntityFeature.PAUSE
| MediaPlayerEntityFeature.PLAY
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.VOLUME_SET
)

@property
Expand Down
Loading