core/tests/components/alexa/test_entities.py

47 lines
1.4 KiB
Python
Raw Normal View History

"""Test Alexa entity representation."""
2021-01-01 21:31:56 +00:00
from unittest.mock import patch
from homeassistant.components.alexa import smart_home
from . import DEFAULT_CONFIG, get_new_request
async def test_unsupported_domain(hass):
"""Discovery ignores entities of unknown domains."""
2019-07-31 19:25:30 +00:00
request = get_new_request("Alexa.Discovery", "Discover")
2019-07-31 19:25:30 +00:00
hass.states.async_set("woz.boop", "on", {"friendly_name": "Boop Woz"})
2019-07-31 19:25:30 +00:00
msg = await smart_home.async_handle_message(hass, DEFAULT_CONFIG, request)
2019-07-31 19:25:30 +00:00
assert "event" in msg
msg = msg["event"]
2019-07-31 19:25:30 +00:00
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
)