mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use exposed_entities API in cloud tests (#92408)
This commit is contained in:
parent
b71f98e8b7
commit
470c3a0f5f
@ -16,9 +16,11 @@ from homeassistant.components.homeassistant.exposed_entities import (
|
|||||||
DATA_EXPOSED_ENTITIES,
|
DATA_EXPOSED_ENTITIES,
|
||||||
ExposedEntities,
|
ExposedEntities,
|
||||||
async_expose_entity,
|
async_expose_entity,
|
||||||
|
async_get_entity_settings,
|
||||||
)
|
)
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
@ -602,20 +604,23 @@ async def test_alexa_config_migrate_expose_entity_prefs(
|
|||||||
)
|
)
|
||||||
await conf.async_initialize()
|
await conf.async_initialize()
|
||||||
|
|
||||||
entity_exposed = entity_registry.async_get(entity_exposed.entity_id)
|
with pytest.raises(HomeAssistantError):
|
||||||
assert entity_exposed.options == {"cloud.alexa": {"should_expose": True}}
|
async_get_entity_settings(hass, "light.unknown")
|
||||||
|
assert async_get_entity_settings(hass, entity_migrated.entity_id) == {
|
||||||
entity_migrated = entity_registry.async_get(entity_migrated.entity_id)
|
"cloud.alexa": {"should_expose": False}
|
||||||
assert entity_migrated.options == {"cloud.alexa": {"should_expose": False}}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_migrated.entity_id) == {
|
||||||
entity_config = entity_registry.async_get(entity_config.entity_id)
|
"cloud.alexa": {"should_expose": False}
|
||||||
assert entity_config.options == {"cloud.alexa": {"should_expose": False}}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_config.entity_id) == {
|
||||||
entity_default = entity_registry.async_get(entity_default.entity_id)
|
"cloud.alexa": {"should_expose": False}
|
||||||
assert entity_default.options == {"cloud.alexa": {"should_expose": True}}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_default.entity_id) == {
|
||||||
entity_blocked = entity_registry.async_get(entity_blocked.entity_id)
|
"cloud.alexa": {"should_expose": True}
|
||||||
assert entity_blocked.options == {"cloud.alexa": {"should_expose": False}}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_blocked.entity_id) == {
|
||||||
|
"cloud.alexa": {"should_expose": False}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_alexa_config_migrate_expose_entity_prefs_default_none(
|
async def test_alexa_config_migrate_expose_entity_prefs_default_none(
|
||||||
@ -646,8 +651,9 @@ async def test_alexa_config_migrate_expose_entity_prefs_default_none(
|
|||||||
)
|
)
|
||||||
await conf.async_initialize()
|
await conf.async_initialize()
|
||||||
|
|
||||||
entity_default = entity_registry.async_get(entity_default.entity_id)
|
assert async_get_entity_settings(hass, entity_default.entity_id) == {
|
||||||
assert entity_default.options == {"cloud.alexa": {"should_expose": True}}
|
"cloud.alexa": {"should_expose": True}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_alexa_config_migrate_expose_entity_prefs_default(
|
async def test_alexa_config_migrate_expose_entity_prefs_default(
|
||||||
@ -723,26 +729,21 @@ async def test_alexa_config_migrate_expose_entity_prefs_default(
|
|||||||
)
|
)
|
||||||
await conf.async_initialize()
|
await conf.async_initialize()
|
||||||
|
|
||||||
binary_sensor_supported = entity_registry.async_get(
|
assert async_get_entity_settings(hass, binary_sensor_supported.entity_id) == {
|
||||||
binary_sensor_supported.entity_id
|
"cloud.alexa": {"should_expose": True}
|
||||||
)
|
}
|
||||||
assert binary_sensor_supported.options == {"cloud.alexa": {"should_expose": True}}
|
assert async_get_entity_settings(hass, binary_sensor_unsupported.entity_id) == {
|
||||||
|
"cloud.alexa": {"should_expose": False}
|
||||||
binary_sensor_unsupported = entity_registry.async_get(
|
}
|
||||||
binary_sensor_unsupported.entity_id
|
assert async_get_entity_settings(hass, light.entity_id) == {
|
||||||
)
|
"cloud.alexa": {"should_expose": True}
|
||||||
assert binary_sensor_unsupported.options == {
|
}
|
||||||
|
assert async_get_entity_settings(hass, sensor_supported.entity_id) == {
|
||||||
|
"cloud.alexa": {"should_expose": True}
|
||||||
|
}
|
||||||
|
assert async_get_entity_settings(hass, sensor_unsupported.entity_id) == {
|
||||||
|
"cloud.alexa": {"should_expose": False}
|
||||||
|
}
|
||||||
|
assert async_get_entity_settings(hass, water_heater.entity_id) == {
|
||||||
"cloud.alexa": {"should_expose": False}
|
"cloud.alexa": {"should_expose": False}
|
||||||
}
|
}
|
||||||
|
|
||||||
light = entity_registry.async_get(light.entity_id)
|
|
||||||
assert light.options == {"cloud.alexa": {"should_expose": True}}
|
|
||||||
|
|
||||||
sensor_supported = entity_registry.async_get(sensor_supported.entity_id)
|
|
||||||
assert sensor_supported.options == {"cloud.alexa": {"should_expose": True}}
|
|
||||||
|
|
||||||
sensor_unsupported = entity_registry.async_get(sensor_unsupported.entity_id)
|
|
||||||
assert sensor_unsupported.options == {"cloud.alexa": {"should_expose": False}}
|
|
||||||
|
|
||||||
water_heater = entity_registry.async_get(water_heater.entity_id)
|
|
||||||
assert water_heater.options == {"cloud.alexa": {"should_expose": False}}
|
|
||||||
|
@ -19,9 +19,11 @@ from homeassistant.components.homeassistant.exposed_entities import (
|
|||||||
DATA_EXPOSED_ENTITIES,
|
DATA_EXPOSED_ENTITIES,
|
||||||
ExposedEntities,
|
ExposedEntities,
|
||||||
async_expose_entity,
|
async_expose_entity,
|
||||||
|
async_get_entity_settings,
|
||||||
)
|
)
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EntityCategory
|
from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EntityCategory
|
||||||
from homeassistant.core import CoreState, HomeAssistant, State
|
from homeassistant.core import CoreState, HomeAssistant, State
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
@ -553,27 +555,24 @@ async def test_google_config_migrate_expose_entity_prefs(
|
|||||||
)
|
)
|
||||||
await conf.async_initialize()
|
await conf.async_initialize()
|
||||||
|
|
||||||
entity_exposed = entity_registry.async_get(entity_exposed.entity_id)
|
with pytest.raises(HomeAssistantError):
|
||||||
assert entity_exposed.options == {"cloud.google_assistant": {"should_expose": True}}
|
async_get_entity_settings(hass, "light.unknown")
|
||||||
|
assert async_get_entity_settings(hass, entity_exposed.entity_id) == {
|
||||||
entity_migrated = entity_registry.async_get(entity_migrated.entity_id)
|
"cloud.google_assistant": {"should_expose": True}
|
||||||
assert entity_migrated.options == {
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_migrated.entity_id) == {
|
||||||
"cloud.google_assistant": {"should_expose": False}
|
"cloud.google_assistant": {"should_expose": False}
|
||||||
}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_no_2fa_exposed.entity_id) == {
|
||||||
entity_no_2fa_exposed = entity_registry.async_get(entity_no_2fa_exposed.entity_id)
|
|
||||||
assert entity_no_2fa_exposed.options == {
|
|
||||||
"cloud.google_assistant": {"disable_2fa": True, "should_expose": True}
|
"cloud.google_assistant": {"disable_2fa": True, "should_expose": True}
|
||||||
}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_config.entity_id) == {
|
||||||
entity_config = entity_registry.async_get(entity_config.entity_id)
|
"cloud.google_assistant": {"should_expose": False}
|
||||||
assert entity_config.options == {"cloud.google_assistant": {"should_expose": False}}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_default.entity_id) == {
|
||||||
entity_default = entity_registry.async_get(entity_default.entity_id)
|
"cloud.google_assistant": {"should_expose": True}
|
||||||
assert entity_default.options == {"cloud.google_assistant": {"should_expose": True}}
|
}
|
||||||
|
assert async_get_entity_settings(hass, entity_blocked.entity_id) == {
|
||||||
entity_blocked = entity_registry.async_get(entity_blocked.entity_id)
|
|
||||||
assert entity_blocked.options == {
|
|
||||||
"cloud.google_assistant": {"should_expose": False}
|
"cloud.google_assistant": {"should_expose": False}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,8 +604,9 @@ async def test_google_config_migrate_expose_entity_prefs_default_none(
|
|||||||
)
|
)
|
||||||
await conf.async_initialize()
|
await conf.async_initialize()
|
||||||
|
|
||||||
entity_default = entity_registry.async_get(entity_default.entity_id)
|
assert async_get_entity_settings(hass, entity_default.entity_id) == {
|
||||||
assert entity_default.options == {"cloud.google_assistant": {"should_expose": True}}
|
"cloud.google_assistant": {"should_expose": True}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_google_config_migrate_expose_entity_prefs_default(
|
async def test_google_config_migrate_expose_entity_prefs_default(
|
||||||
@ -681,32 +681,21 @@ async def test_google_config_migrate_expose_entity_prefs_default(
|
|||||||
)
|
)
|
||||||
await conf.async_initialize()
|
await conf.async_initialize()
|
||||||
|
|
||||||
binary_sensor_supported = entity_registry.async_get(
|
assert async_get_entity_settings(hass, binary_sensor_supported.entity_id) == {
|
||||||
binary_sensor_supported.entity_id
|
|
||||||
)
|
|
||||||
assert binary_sensor_supported.options == {
|
|
||||||
"cloud.google_assistant": {"should_expose": True}
|
"cloud.google_assistant": {"should_expose": True}
|
||||||
}
|
}
|
||||||
|
assert async_get_entity_settings(hass, binary_sensor_unsupported.entity_id) == {
|
||||||
binary_sensor_unsupported = entity_registry.async_get(
|
|
||||||
binary_sensor_unsupported.entity_id
|
|
||||||
)
|
|
||||||
assert binary_sensor_unsupported.options == {
|
|
||||||
"cloud.google_assistant": {"should_expose": False}
|
"cloud.google_assistant": {"should_expose": False}
|
||||||
}
|
}
|
||||||
|
assert async_get_entity_settings(hass, light.entity_id) == {
|
||||||
light = entity_registry.async_get(light.entity_id)
|
|
||||||
assert light.options == {"cloud.google_assistant": {"should_expose": True}}
|
|
||||||
|
|
||||||
sensor_supported = entity_registry.async_get(sensor_supported.entity_id)
|
|
||||||
assert sensor_supported.options == {
|
|
||||||
"cloud.google_assistant": {"should_expose": True}
|
"cloud.google_assistant": {"should_expose": True}
|
||||||
}
|
}
|
||||||
|
assert async_get_entity_settings(hass, sensor_supported.entity_id) == {
|
||||||
sensor_unsupported = entity_registry.async_get(sensor_unsupported.entity_id)
|
"cloud.google_assistant": {"should_expose": True}
|
||||||
assert sensor_unsupported.options == {
|
}
|
||||||
|
assert async_get_entity_settings(hass, sensor_unsupported.entity_id) == {
|
||||||
|
"cloud.google_assistant": {"should_expose": False}
|
||||||
|
}
|
||||||
|
assert async_get_entity_settings(hass, water_heater.entity_id) == {
|
||||||
"cloud.google_assistant": {"should_expose": False}
|
"cloud.google_assistant": {"should_expose": False}
|
||||||
}
|
}
|
||||||
|
|
||||||
water_heater = entity_registry.async_get(water_heater.entity_id)
|
|
||||||
assert water_heater.options == {"cloud.google_assistant": {"should_expose": False}}
|
|
||||||
|
@ -1060,8 +1060,8 @@ async def test_update_alexa_entity(
|
|||||||
response = await client.receive_json()
|
response = await client.receive_json()
|
||||||
|
|
||||||
assert response["success"]
|
assert response["success"]
|
||||||
assert entity_registry.async_get(entry.entity_id).options["cloud.alexa"] == {
|
assert exposed_entities.async_get_entity_settings(hass, entry.entity_id) == {
|
||||||
"should_expose": False
|
"cloud.alexa": {"should_expose": False}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user