mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +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.BROWSE_MEDIA
|
||||||
| MediaPlayerEntityFeature.GROUPING
|
| MediaPlayerEntityFeature.GROUPING
|
||||||
| MediaPlayerEntityFeature.PAUSE
|
| MediaPlayerEntityFeature.PAUSE
|
||||||
| MediaPlayerEntityFeature.VOLUME_SET
|
|
||||||
| MediaPlayerEntityFeature.STOP
|
| MediaPlayerEntityFeature.STOP
|
||||||
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
| MediaPlayerEntityFeature.PREVIOUS_TRACK
|
||||||
| MediaPlayerEntityFeature.NEXT_TRACK
|
| MediaPlayerEntityFeature.NEXT_TRACK
|
||||||
@ -104,7 +103,6 @@ class RoonDevice(MediaPlayerEntity):
|
|||||||
| MediaPlayerEntityFeature.VOLUME_MUTE
|
| MediaPlayerEntityFeature.VOLUME_MUTE
|
||||||
| MediaPlayerEntityFeature.PLAY
|
| MediaPlayerEntityFeature.PLAY
|
||||||
| MediaPlayerEntityFeature.PLAY_MEDIA
|
| MediaPlayerEntityFeature.PLAY_MEDIA
|
||||||
| MediaPlayerEntityFeature.VOLUME_STEP
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, server, player_data):
|
def __init__(self, server, player_data):
|
||||||
@ -124,6 +122,8 @@ class RoonDevice(MediaPlayerEntity):
|
|||||||
self._attr_shuffle = False
|
self._attr_shuffle = False
|
||||||
self._attr_media_image_url = None
|
self._attr_media_image_url = None
|
||||||
self._attr_volume_level = 0
|
self._attr_volume_level = 0
|
||||||
|
self._volume_fixed = True
|
||||||
|
self._volume_incremental = False
|
||||||
self.update_data(player_data)
|
self.update_data(player_data)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
@ -190,12 +190,21 @@ class RoonDevice(MediaPlayerEntity):
|
|||||||
"level": 0,
|
"level": 0,
|
||||||
"step": 0,
|
"step": 0,
|
||||||
"muted": False,
|
"muted": False,
|
||||||
|
"fixed": True,
|
||||||
|
"incremental": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
volume_data = player_data["volume"]
|
volume_data = player_data["volume"]
|
||||||
volume_muted = volume_data["is_muted"]
|
except KeyError:
|
||||||
volume_step = convert(volume_data["step"], int, 0)
|
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_max = volume_data["max"]
|
||||||
volume_min = volume_data["min"]
|
volume_min = volume_data["min"]
|
||||||
raw_level = convert(volume_data["value"], float, 0)
|
raw_level = convert(volume_data["value"], float, 0)
|
||||||
@ -204,15 +213,9 @@ class RoonDevice(MediaPlayerEntity):
|
|||||||
volume_percentage_factor = volume_range / 100
|
volume_percentage_factor = volume_range / 100
|
||||||
|
|
||||||
level = (raw_level - volume_min) / volume_percentage_factor
|
level = (raw_level - volume_min) / volume_percentage_factor
|
||||||
volume_level = convert(level, int, 0) / 100
|
volume["level"] = convert(level, int, 0) / 100
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# catch KeyError
|
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
volume["muted"] = volume_muted
|
|
||||||
volume["step"] = volume_step
|
|
||||||
volume["level"] = volume_level
|
|
||||||
|
|
||||||
return volume
|
return volume
|
||||||
|
|
||||||
@ -288,6 +291,16 @@ class RoonDevice(MediaPlayerEntity):
|
|||||||
self._attr_is_volume_muted = volume["muted"]
|
self._attr_is_volume_muted = volume["muted"]
|
||||||
self._attr_volume_step = volume["step"]
|
self._attr_volume_step = volume["step"]
|
||||||
self._attr_volume_level = volume["level"]
|
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)
|
now_playing = self._parse_now_playing(self.player_data)
|
||||||
self._attr_media_title = now_playing["title"]
|
self._attr_media_title = now_playing["title"]
|
||||||
@ -359,11 +372,17 @@ class RoonDevice(MediaPlayerEntity):
|
|||||||
|
|
||||||
def volume_up(self) -> None:
|
def volume_up(self) -> None:
|
||||||
"""Send new volume_level to device."""
|
"""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:
|
def volume_down(self) -> None:
|
||||||
"""Send new volume_level to device."""
|
"""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:
|
def turn_on(self) -> None:
|
||||||
"""Turn on device (if supported)."""
|
"""Turn on device (if supported)."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user