mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Clean up exposed domains (#118753)
* Remove lock and script * Add media player * Fix tests
This commit is contained in:
parent
35a1ecea27
commit
0257aa4839
@ -35,9 +35,8 @@ DEFAULT_EXPOSED_DOMAINS = {
|
||||
"fan",
|
||||
"humidifier",
|
||||
"light",
|
||||
"lock",
|
||||
"media_player",
|
||||
"scene",
|
||||
"script",
|
||||
"switch",
|
||||
"todo",
|
||||
"vacuum",
|
||||
|
@ -72,15 +72,23 @@ async def test_hidden_entities_skipped(
|
||||
async def test_exposed_domains(hass: HomeAssistant, init_components) -> None:
|
||||
"""Test that we can't interact with entities that aren't exposed."""
|
||||
hass.states.async_set(
|
||||
"media_player.test", "off", attributes={ATTR_FRIENDLY_NAME: "Test Media Player"}
|
||||
"lock.front_door", "off", attributes={ATTR_FRIENDLY_NAME: "Front Door"}
|
||||
)
|
||||
hass.states.async_set(
|
||||
"script.my_script", "off", attributes={ATTR_FRIENDLY_NAME: "My Script"}
|
||||
)
|
||||
|
||||
# These are match failures instead of handle failures because the domains
|
||||
# aren't exposed by default.
|
||||
result = await conversation.async_converse(
|
||||
hass, "unlock front door", None, Context(), None
|
||||
)
|
||||
assert result.response.response_type == intent.IntentResponseType.ERROR
|
||||
assert result.response.error_code == intent.IntentResponseErrorCode.NO_VALID_TARGETS
|
||||
|
||||
result = await conversation.async_converse(
|
||||
hass, "turn on test media player", None, Context(), None
|
||||
hass, "run my script", None, Context(), None
|
||||
)
|
||||
|
||||
# This is a match failure instead of a handle failure because the media
|
||||
# player domain is not exposed.
|
||||
assert result.response.response_type == intent.IntentResponseType.ERROR
|
||||
assert result.response.error_code == intent.IntentResponseErrorCode.NO_VALID_TARGETS
|
||||
|
||||
@ -806,7 +814,6 @@ async def test_error_wrong_state(hass: HomeAssistant, init_components) -> None:
|
||||
media_player.STATE_IDLE,
|
||||
{ATTR_FRIENDLY_NAME: "test player"},
|
||||
)
|
||||
expose_entity(hass, "media_player.test_player", True)
|
||||
|
||||
result = await conversation.async_converse(
|
||||
hass, "pause test player", None, Context(), None
|
||||
@ -829,7 +836,6 @@ async def test_error_feature_not_supported(
|
||||
{ATTR_FRIENDLY_NAME: "test player"},
|
||||
# missing VOLUME_SET feature
|
||||
)
|
||||
expose_entity(hass, "media_player.test_player", True)
|
||||
|
||||
result = await conversation.async_converse(
|
||||
hass, "set test player volume to 100%", None, Context(), None
|
||||
|
@ -57,9 +57,12 @@ def entities_unique_id(entity_registry: er.EntityRegistry) -> dict[str, str]:
|
||||
entry_sensor_temperature = entity_registry.async_get_or_create(
|
||||
"sensor",
|
||||
"test",
|
||||
"unique2",
|
||||
"unique3",
|
||||
original_device_class="temperature",
|
||||
)
|
||||
entry_media_player = entity_registry.async_get_or_create(
|
||||
"media_player", "test", "unique4", original_device_class="media_player"
|
||||
)
|
||||
return {
|
||||
"blocked": entry_blocked.entity_id,
|
||||
"lock": entry_lock.entity_id,
|
||||
@ -67,6 +70,7 @@ def entities_unique_id(entity_registry: er.EntityRegistry) -> dict[str, str]:
|
||||
"door_sensor": entry_binary_sensor_door.entity_id,
|
||||
"sensor": entry_sensor.entity_id,
|
||||
"temperature_sensor": entry_sensor_temperature.entity_id,
|
||||
"media_player": entry_media_player.entity_id,
|
||||
}
|
||||
|
||||
|
||||
@ -78,10 +82,12 @@ def entities_no_unique_id(hass: HomeAssistant) -> dict[str, str]:
|
||||
door_sensor = "binary_sensor.door"
|
||||
sensor = "sensor.test"
|
||||
sensor_temperature = "sensor.temperature"
|
||||
media_player = "media_player.test"
|
||||
hass.states.async_set(binary_sensor, "on", {})
|
||||
hass.states.async_set(door_sensor, "on", {"device_class": "door"})
|
||||
hass.states.async_set(sensor, "on", {})
|
||||
hass.states.async_set(sensor_temperature, "on", {"device_class": "temperature"})
|
||||
hass.states.async_set(media_player, "idle", {})
|
||||
return {
|
||||
"blocked": blocked,
|
||||
"lock": lock,
|
||||
@ -89,6 +95,7 @@ def entities_no_unique_id(hass: HomeAssistant) -> dict[str, str]:
|
||||
"door_sensor": door_sensor,
|
||||
"sensor": sensor,
|
||||
"temperature_sensor": sensor_temperature,
|
||||
"media_player": media_player,
|
||||
}
|
||||
|
||||
|
||||
@ -409,8 +416,8 @@ async def test_should_expose(
|
||||
# Blocked entity is not exposed
|
||||
assert async_should_expose(hass, "cloud.alexa", entities["blocked"]) is False
|
||||
|
||||
# Lock is exposed
|
||||
assert async_should_expose(hass, "cloud.alexa", entities["lock"]) is True
|
||||
# Lock is not exposed
|
||||
assert async_should_expose(hass, "cloud.alexa", entities["lock"]) is False
|
||||
|
||||
# Binary sensor without device class is not exposed
|
||||
assert async_should_expose(hass, "cloud.alexa", entities["binary_sensor"]) is False
|
||||
@ -426,6 +433,9 @@ async def test_should_expose(
|
||||
async_should_expose(hass, "cloud.alexa", entities["temperature_sensor"]) is True
|
||||
)
|
||||
|
||||
# Media player is exposed
|
||||
assert async_should_expose(hass, "cloud.alexa", entities["media_player"]) is True
|
||||
|
||||
# The second time we check, it should load it from storage
|
||||
assert (
|
||||
async_should_expose(hass, "cloud.alexa", entities["temperature_sensor"]) is True
|
||||
|
Loading…
x
Reference in New Issue
Block a user