mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Improve handling of roon media players with fixed and incremental volume (#99819)
This commit is contained in:
parent
d676d95901
commit
dcb3dc254d
@ -92,7 +92,6 @@ class RoonDevice(MediaPlayerEntity):
|
||||
MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||
| MediaPlayerEntityFeature.GROUPING
|
||||
| MediaPlayerEntityFeature.PAUSE
|
||||
| MediaPlayerEntityFeature.VOLUME_SET
|
||||
| MediaPlayerEntityFeature.STOP
|
||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||
| MediaPlayerEntityFeature.NEXT_TRACK
|
||||
@ -104,7 +103,6 @@ class RoonDevice(MediaPlayerEntity):
|
||||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||
| MediaPlayerEntityFeature.PLAY
|
||||
| MediaPlayerEntityFeature.PLAY_MEDIA
|
||||
| MediaPlayerEntityFeature.VOLUME_STEP
|
||||
)
|
||||
|
||||
def __init__(self, server, player_data):
|
||||
@ -124,6 +122,8 @@ class RoonDevice(MediaPlayerEntity):
|
||||
self._attr_shuffle = False
|
||||
self._attr_media_image_url = None
|
||||
self._attr_volume_level = 0
|
||||
self._volume_fixed = True
|
||||
self._volume_incremental = False
|
||||
self.update_data(player_data)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
@ -190,12 +190,21 @@ class RoonDevice(MediaPlayerEntity):
|
||||
"level": 0,
|
||||
"step": 0,
|
||||
"muted": False,
|
||||
"fixed": True,
|
||||
"incremental": False,
|
||||
}
|
||||
|
||||
try:
|
||||
volume_data = player_data["volume"]
|
||||
volume_muted = volume_data["is_muted"]
|
||||
volume_step = convert(volume_data["step"], int, 0)
|
||||
except KeyError:
|
||||
return volume
|
||||
|
||||
volume["fixed"] = False
|
||||
volume["incremental"] = volume_data["type"] == "incremental"
|
||||
volume["muted"] = volume_data.get("is_muted", False)
|
||||
volume["step"] = convert(volume_data.get("step"), int, 0)
|
||||
|
||||
try:
|
||||
volume_max = volume_data["max"]
|
||||
volume_min = volume_data["min"]
|
||||
raw_level = convert(volume_data["value"], float, 0)
|
||||
@ -204,15 +213,9 @@ class RoonDevice(MediaPlayerEntity):
|
||||
volume_percentage_factor = volume_range / 100
|
||||
|
||||
level = (raw_level - volume_min) / volume_percentage_factor
|
||||
volume_level = convert(level, int, 0) / 100
|
||||
|
||||
volume["level"] = convert(level, int, 0) / 100
|
||||
except KeyError:
|
||||
# catch KeyError
|
||||
pass
|
||||
else:
|
||||
volume["muted"] = volume_muted
|
||||
volume["step"] = volume_step
|
||||
volume["level"] = volume_level
|
||||
|
||||
return volume
|
||||
|
||||
@ -288,6 +291,16 @@ class RoonDevice(MediaPlayerEntity):
|
||||
self._attr_is_volume_muted = volume["muted"]
|
||||
self._attr_volume_step = volume["step"]
|
||||
self._attr_volume_level = volume["level"]
|
||||
self._volume_fixed = volume["fixed"]
|
||||
self._volume_incremental = volume["incremental"]
|
||||
if not self._volume_fixed:
|
||||
self._attr_supported_features = (
|
||||
self._attr_supported_features | MediaPlayerEntityFeature.VOLUME_STEP
|
||||
)
|
||||
if not self._volume_incremental:
|
||||
self._attr_supported_features = (
|
||||
self._attr_supported_features | MediaPlayerEntityFeature.VOLUME_SET
|
||||
)
|
||||
|
||||
now_playing = self._parse_now_playing(self.player_data)
|
||||
self._attr_media_title = now_playing["title"]
|
||||
@ -359,11 +372,17 @@ class RoonDevice(MediaPlayerEntity):
|
||||
|
||||
def volume_up(self) -> None:
|
||||
"""Send new volume_level to device."""
|
||||
self._server.roonapi.change_volume_percent(self.output_id, 3)
|
||||
if self._volume_incremental:
|
||||
self._server.roonapi.change_volume_raw(self.output_id, 1, "relative_step")
|
||||
else:
|
||||
self._server.roonapi.change_volume_percent(self.output_id, 3)
|
||||
|
||||
def volume_down(self) -> None:
|
||||
"""Send new volume_level to device."""
|
||||
self._server.roonapi.change_volume_percent(self.output_id, -3)
|
||||
if self._volume_incremental:
|
||||
self._server.roonapi.change_volume_raw(self.output_id, -1, "relative_step")
|
||||
else:
|
||||
self._server.roonapi.change_volume_percent(self.output_id, -3)
|
||||
|
||||
def turn_on(self) -> None:
|
||||
"""Turn on device (if supported)."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user