mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 23:07:09 +00:00
Cast the volume_level of a universal media_player to a float (#29045)
* Make sure to cast the volume_level of a universal media_player to a float * Fix test that expects the wrong bahaviour * Catch exception instead of checking for None
This commit is contained in:
parent
8a413b152d
commit
cc346e57e6
@ -255,7 +255,10 @@ class UniversalMediaPlayer(MediaPlayerDevice):
|
||||
@property
|
||||
def volume_level(self):
|
||||
"""Volume level of entity specified in attributes or active child."""
|
||||
return self._override_or_child_attr(ATTR_MEDIA_VOLUME_LEVEL)
|
||||
try:
|
||||
return float(self._override_or_child_attr(ATTR_MEDIA_VOLUME_LEVEL))
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_volume_muted(self):
|
||||
|
@ -539,10 +539,10 @@ class TestMediaPlayer(unittest.TestCase):
|
||||
|
||||
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
||||
|
||||
assert "0" == ump.volume_level
|
||||
assert 0 == ump.volume_level
|
||||
|
||||
self.hass.states.set(self.mock_volume_id, 100)
|
||||
assert "100" == ump.volume_level
|
||||
assert 100 == ump.volume_level
|
||||
|
||||
def test_is_volume_muted_children_and_attr(self):
|
||||
"""Test is volume muted property w/ children and attrs."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user