mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Protect for unknown state attributes. (#31354)
This commit is contained in:
parent
06efe3a2f6
commit
fa2e409abd
@ -1326,10 +1326,16 @@ class AlexaRangeController(AlexaCapability):
|
|||||||
if name != "rangeValue":
|
if name != "rangeValue":
|
||||||
raise UnsupportedProperty(name)
|
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
|
# Fan Speed
|
||||||
if self.instance == f"{fan.DOMAIN}.{fan.ATTR_SPEED}":
|
if self.instance == f"{fan.DOMAIN}.{fan.ATTR_SPEED}":
|
||||||
speed_list = self.entity.attributes[fan.ATTR_SPEED_LIST]
|
speed_list = self.entity.attributes.get(fan.ATTR_SPEED_LIST)
|
||||||
speed = self.entity.attributes[fan.ATTR_SPEED]
|
speed = self.entity.attributes.get(fan.ATTR_SPEED)
|
||||||
|
if speed_list is not None and speed is not None:
|
||||||
speed_index = next(
|
speed_index = next(
|
||||||
(i for i, v in enumerate(speed_list) if v == speed), None
|
(i for i, v in enumerate(speed_list) if v == speed), None
|
||||||
)
|
)
|
||||||
@ -1349,8 +1355,9 @@ class AlexaRangeController(AlexaCapability):
|
|||||||
|
|
||||||
# Vacuum Fan Speed
|
# Vacuum Fan Speed
|
||||||
if self.instance == f"{vacuum.DOMAIN}.{vacuum.ATTR_FAN_SPEED}":
|
if self.instance == f"{vacuum.DOMAIN}.{vacuum.ATTR_FAN_SPEED}":
|
||||||
speed_list = self.entity.attributes[vacuum.ATTR_FAN_SPEED_LIST]
|
speed_list = self.entity.attributes.get(vacuum.ATTR_FAN_SPEED_LIST)
|
||||||
speed = self.entity.attributes[vacuum.ATTR_FAN_SPEED]
|
speed = self.entity.attributes.get(vacuum.ATTR_FAN_SPEED)
|
||||||
|
if speed_list is not None and speed is not None:
|
||||||
speed_index = next(
|
speed_index = next(
|
||||||
(i for i, v in enumerate(speed_list) if v == speed), None
|
(i for i, v in enumerate(speed_list) if v == speed), None
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user