Do not break Alexa sync when encounter bad entity (#39380)
This commit is contained in:
parent
b4db9f615d
commit
ba75856f2b
4 changed files with 107 additions and 29 deletions
|
@ -33,6 +33,7 @@ from . import (
|
|||
reported_properties,
|
||||
)
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_mock_service
|
||||
|
||||
|
||||
|
@ -756,3 +757,25 @@ async def test_report_image_processing(hass):
|
|||
"humanPresenceDetectionState",
|
||||
{"value": "DETECTED"},
|
||||
)
|
||||
|
||||
|
||||
async def test_get_property_blowup(hass, caplog):
|
||||
"""Test we handle a property blowing up."""
|
||||
hass.states.async_set(
|
||||
"climate.downstairs",
|
||||
climate.HVAC_MODE_AUTO,
|
||||
{
|
||||
"friendly_name": "Climate Downstairs",
|
||||
"supported_features": 91,
|
||||
climate.ATTR_CURRENT_TEMPERATURE: 34,
|
||||
ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
|
||||
},
|
||||
)
|
||||
with patch(
|
||||
"homeassistant.components.alexa.capabilities.float",
|
||||
side_effect=Exception("Boom Fail"),
|
||||
):
|
||||
properties = await reported_properties(hass, "climate.downstairs")
|
||||
properties.assert_not_has_property("Alexa.ThermostatController", "temperature")
|
||||
|
||||
assert "Boom Fail" in caplog.text
|
||||
|
|
|
@ -3,6 +3,8 @@ from homeassistant.components.alexa import smart_home
|
|||
|
||||
from . import DEFAULT_CONFIG, get_new_request
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
async def test_unsupported_domain(hass):
|
||||
"""Discovery ignores entities of unknown domains."""
|
||||
|
@ -16,3 +18,29 @@ async def test_unsupported_domain(hass):
|
|||
msg = msg["event"]
|
||||
|
||||
assert not msg["payload"]["endpoints"]
|
||||
|
||||
|
||||
async def test_serialize_discovery_recovers(hass, caplog):
|
||||
"""Test we handle an interface raising unexpectedly during serialize discovery."""
|
||||
request = get_new_request("Alexa.Discovery", "Discover")
|
||||
|
||||
hass.states.async_set("switch.bla", "on", {"friendly_name": "Boop Woz"})
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.alexa.capabilities.AlexaPowerController.serialize_discovery",
|
||||
side_effect=TypeError,
|
||||
):
|
||||
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request)
|
||||
|
||||
assert "event" in msg
|
||||
msg = msg["event"]
|
||||
|
||||
interfaces = {
|
||||
ifc["interface"] for ifc in msg["payload"]["endpoints"][0]["capabilities"]
|
||||
}
|
||||
|
||||
assert "Alexa.PowerController" not in interfaces
|
||||
assert (
|
||||
f"Error serializing Alexa.PowerController discovery for {hass.states.get('switch.bla')}"
|
||||
in caplog.text
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue