Skip to content

Commit

Permalink
Cast the volume_level of a universal media_player to a float (home-as…
Browse files Browse the repository at this point in the history
…sistant#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
  • Loading branch information
michaelarnauts authored and balloob committed Nov 26, 2019
1 parent 8a413b1 commit cc346e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion homeassistant/components/universal/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ def state(self):
@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):
Expand Down
4 changes: 2 additions & 2 deletions tests/components/universal/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,10 @@ def test_volume_level_children_and_attr(self):

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."""
Expand Down

0 comments on commit cc346e5

Please sign in to comment.