Fix TypeError Exception in AlexaSpeaker (#32318)

* alexa/capabilities.py: Fix TypeError Exception

    - Remove division by zero try/catch -- there is no division
    - Handle TypeError exception when current_volume = None
    - Simplify math and return logic

* Add test for Alexa.Speaker's valid volume range
This commit is contained in:
David Nielsen authored and GitHub committed 2020-03-09 09:38:31 -07:00
1 parent 19faf06ce7
commit 988b400a9c
2 files changed
+34 -6

No files matched your search

@@ -1,6 +1,5 @@
"""Alexa capabilities."""
import logging
import math
from homeassistant.components import (
cover,
@@ -671,11 +670,8 @@ class AlexaSpeaker(AlexaCapability):
current_level = self.entity.attributes.get(
media_player.ATTR_MEDIA_VOLUME_LEVEL
)
try:
current = math.floor(int(current_level * 100))
except ZeroDivisionError:
current = 0
return current
if current_level is not None:
return round(float(current_level) * 100)
if name == "muted":
return bool(