Protect for unknown state attributes. (#31354)

This commit is contained in:
ochlocracy 2020-01-31 17:14:43 -05:00 committed by GitHub
parent 06efe3a2f6
commit fa2e409abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1326,10 +1326,16 @@ class AlexaRangeController(AlexaCapability):
if name != "rangeValue":
raise UnsupportedProperty(name)
# Return None for unavailable and unknown states.
# Allows the Alexa.EndpointHealth Interface to handle the unavailable state in a stateReport.
if self.entity.state in (STATE_UNAVAILABLE, STATE_UNKNOWN, None):
return None
# Fan Speed
if self.instance == f"{fan.DOMAIN}.{fan.ATTR_SPEED}":
speed_list = self.entity.attributes[fan.ATTR_SPEED_LIST]
speed = self.entity.attributes[fan.ATTR_SPEED]
speed_list = self.entity.attributes.get(fan.ATTR_SPEED_LIST)
speed = self.entity.attributes.get(fan.ATTR_SPEED)
if speed_list is not None and speed is not None:
speed_index = next(
(i for i, v in enumerate(speed_list) if v == speed), None
)
@ -1349,8 +1355,9 @@ class AlexaRangeController(AlexaCapability):
# Vacuum Fan Speed
if self.instance == f"{vacuum.DOMAIN}.{vacuum.ATTR_FAN_SPEED}":
speed_list = self.entity.attributes[vacuum.ATTR_FAN_SPEED_LIST]
speed = self.entity.attributes[vacuum.ATTR_FAN_SPEED]
speed_list = self.entity.attributes.get(vacuum.ATTR_FAN_SPEED_LIST)
speed = self.entity.attributes.get(vacuum.ATTR_FAN_SPEED)
if speed_list is not None and speed is not None:
speed_index = next(
(i for i, v in enumerate(speed_list) if v == speed), None
)