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

Add repeat to roon media player #88851

Merged
merged 3 commits into from
Mar 5, 2023
Merged
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
23 changes: 22 additions & 1 deletion homeassistant/components/roon/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MediaPlayerEntity,
MediaPlayerEntityFeature,
MediaPlayerState,
RepeatMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_DEFAULT_NAME
Expand All @@ -35,6 +36,16 @@

ATTR_TRANSFER = "transfer_id"

REPEAT_MODE_MAPPING_TO_HA = {
"loop": RepeatMode.ALL,
"disabled": RepeatMode.OFF,
"loop_one": RepeatMode.ONE,
}

REPEAT_MODE_MAPPING_TO_ROON = {
value: key for key, value in REPEAT_MODE_MAPPING_TO_HA.items()
}


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -84,6 +95,7 @@ class RoonDevice(MediaPlayerEntity):
| MediaPlayerEntityFeature.STOP
| MediaPlayerEntityFeature.PREVIOUS_TRACK
| MediaPlayerEntityFeature.NEXT_TRACK
| MediaPlayerEntityFeature.REPEAT_SET
| MediaPlayerEntityFeature.SHUFFLE_SET
| MediaPlayerEntityFeature.SEEK
| MediaPlayerEntityFeature.TURN_ON
Expand Down Expand Up @@ -262,6 +274,9 @@ def update_state(self):
self._attr_unique_id = self.player_data["dev_id"]
self._zone_id = self.player_data["zone_id"]
self._output_id = self.player_data["output_id"]
self._attr_repeat = REPEAT_MODE_MAPPING_TO_HA.get(
self.player_data["settings"]["loop"]
)
self._attr_shuffle = self.player_data["settings"]["shuffle"]
self._attr_name = self.player_data["display_name"]

Expand Down Expand Up @@ -331,7 +346,7 @@ def media_seek(self, position: float) -> None:

def set_volume_level(self, volume: float) -> None:
"""Send new volume_level to device."""
volume = int(volume * 100)
volume = volume * 100
self._server.roonapi.set_volume_percent(self.output_id, volume)

def mute_volume(self, mute=True):
Expand Down Expand Up @@ -373,6 +388,12 @@ def set_shuffle(self, shuffle: bool) -> None:
"""Set shuffle state."""
self._server.roonapi.shuffle(self.output_id, shuffle)

def set_repeat(self, repeat: RepeatMode) -> None:
"""Set repeat mode."""
if repeat not in REPEAT_MODE_MAPPING_TO_ROON:
raise ValueError(f"Unsupported repeat mode: {repeat}")
self._server.roonapi.repeat(self.output_id, REPEAT_MODE_MAPPING_TO_ROON[repeat])

def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None:
"""Send the play_media command to the media player."""

Expand Down