Clean up exposed domains (#118753)

* Remove lock and script

* Add media player

* Fix tests
This commit is contained in:
Michael Hansen 2024-06-03 21:26:40 -05:00 committed by GitHub
parent 35a1ecea27
commit 0257aa4839
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 12 deletions

View file

@ -35,9 +35,8 @@ DEFAULT_EXPOSED_DOMAINS = {
"fan", "fan",
"humidifier", "humidifier",
"light", "light",
"lock", "media_player",
"scene", "scene",
"script",
"switch", "switch",
"todo", "todo",
"vacuum", "vacuum",

View file

@ -72,15 +72,23 @@ async def test_hidden_entities_skipped(
async def test_exposed_domains(hass: HomeAssistant, init_components) -> None: async def test_exposed_domains(hass: HomeAssistant, init_components) -> None:
"""Test that we can't interact with entities that aren't exposed.""" """Test that we can't interact with entities that aren't exposed."""
hass.states.async_set( 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( 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.response_type == intent.IntentResponseType.ERROR
assert result.response.error_code == intent.IntentResponseErrorCode.NO_VALID_TARGETS 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, media_player.STATE_IDLE,
{ATTR_FRIENDLY_NAME: "test player"}, {ATTR_FRIENDLY_NAME: "test player"},
) )
expose_entity(hass, "media_player.test_player", True)
result = await conversation.async_converse( result = await conversation.async_converse(
hass, "pause test player", None, Context(), None hass, "pause test player", None, Context(), None
@ -829,7 +836,6 @@ async def test_error_feature_not_supported(
{ATTR_FRIENDLY_NAME: "test player"}, {ATTR_FRIENDLY_NAME: "test player"},
# missing VOLUME_SET feature # missing VOLUME_SET feature
) )
expose_entity(hass, "media_player.test_player", True)
result = await conversation.async_converse( result = await conversation.async_converse(
hass, "set test player volume to 100%", None, Context(), None hass, "set test player volume to 100%", None, Context(), None

View file

@ -57,9 +57,12 @@ def entities_unique_id(entity_registry: er.EntityRegistry) -> dict[str, str]:
entry_sensor_temperature = entity_registry.async_get_or_create( entry_sensor_temperature = entity_registry.async_get_or_create(
"sensor", "sensor",
"test", "test",
"unique2", "unique3",
original_device_class="temperature", original_device_class="temperature",
) )
entry_media_player = entity_registry.async_get_or_create(
"media_player", "test", "unique4", original_device_class="media_player"
)
return { return {
"blocked": entry_blocked.entity_id, "blocked": entry_blocked.entity_id,
"lock": entry_lock.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, "door_sensor": entry_binary_sensor_door.entity_id,
"sensor": entry_sensor.entity_id, "sensor": entry_sensor.entity_id,
"temperature_sensor": entry_sensor_temperature.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" door_sensor = "binary_sensor.door"
sensor = "sensor.test" sensor = "sensor.test"
sensor_temperature = "sensor.temperature" sensor_temperature = "sensor.temperature"
media_player = "media_player.test"
hass.states.async_set(binary_sensor, "on", {}) hass.states.async_set(binary_sensor, "on", {})
hass.states.async_set(door_sensor, "on", {"device_class": "door"}) hass.states.async_set(door_sensor, "on", {"device_class": "door"})
hass.states.async_set(sensor, "on", {}) hass.states.async_set(sensor, "on", {})
hass.states.async_set(sensor_temperature, "on", {"device_class": "temperature"}) hass.states.async_set(sensor_temperature, "on", {"device_class": "temperature"})
hass.states.async_set(media_player, "idle", {})
return { return {
"blocked": blocked, "blocked": blocked,
"lock": lock, "lock": lock,
@ -89,6 +95,7 @@ def entities_no_unique_id(hass: HomeAssistant) -> dict[str, str]:
"door_sensor": door_sensor, "door_sensor": door_sensor,
"sensor": sensor, "sensor": sensor,
"temperature_sensor": sensor_temperature, "temperature_sensor": sensor_temperature,
"media_player": media_player,
} }
@ -409,8 +416,8 @@ async def test_should_expose(
# Blocked entity is not exposed # Blocked entity is not exposed
assert async_should_expose(hass, "cloud.alexa", entities["blocked"]) is False assert async_should_expose(hass, "cloud.alexa", entities["blocked"]) is False
# Lock is exposed # Lock is not exposed
assert async_should_expose(hass, "cloud.alexa", entities["lock"]) is True assert async_should_expose(hass, "cloud.alexa", entities["lock"]) is False
# Binary sensor without device class is not exposed # Binary sensor without device class is not exposed
assert async_should_expose(hass, "cloud.alexa", entities["binary_sensor"]) is False 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 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 # The second time we check, it should load it from storage
assert ( assert (
async_should_expose(hass, "cloud.alexa", entities["temperature_sensor"]) is True async_should_expose(hass, "cloud.alexa", entities["temperature_sensor"]) is True