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:
Michaël Arnauts 2019-11-26 03:01:24 +01:00 committed by Paulus Schoutsen
parent 8a413b152d
commit cc346e57e6
2 changed files with 6 additions and 3 deletions

View File

@ -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):

View File

@ -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."""