mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Adjust registry access in intent (#88881)
This commit is contained in:
parent
1bed5c7775
commit
54f709f704
@ -18,7 +18,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, State
|
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, State
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
area_registry,
|
area_registry as ar,
|
||||||
config_validation as cv,
|
config_validation as cv,
|
||||||
integration_platform,
|
integration_platform,
|
||||||
intent,
|
intent,
|
||||||
@ -109,9 +109,9 @@ class GetStateIntentHandler(intent.IntentHandler):
|
|||||||
|
|
||||||
# Look up area first to fail early
|
# Look up area first to fail early
|
||||||
area_name = slots.get("area", {}).get("value")
|
area_name = slots.get("area", {}).get("value")
|
||||||
area: area_registry.AreaEntry | None = None
|
area: ar.AreaEntry | None = None
|
||||||
if area_name is not None:
|
if area_name is not None:
|
||||||
areas = area_registry.async_get(hass)
|
areas = ar.async_get(hass)
|
||||||
area = areas.async_get_area(area_name) or areas.async_get_area_by_name(
|
area = areas.async_get_area(area_name) or areas.async_get_area_by_name(
|
||||||
area_name
|
area_name
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON
|
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import area_registry, config_validation as cv, intent
|
from homeassistant.helpers import area_registry as ar, config_validation as cv, intent
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
@ -56,9 +56,9 @@ class SetIntentHandler(intent.IntentHandler):
|
|||||||
|
|
||||||
# Look up area first to fail early
|
# Look up area first to fail early
|
||||||
area_name = slots.get("area", {}).get("value")
|
area_name = slots.get("area", {}).get("value")
|
||||||
area: area_registry.AreaEntry | None = None
|
area: ar.AreaEntry | None = None
|
||||||
if area_name is not None:
|
if area_name is not None:
|
||||||
areas = area_registry.async_get(hass)
|
areas = ar.async_get(hass)
|
||||||
area = areas.async_get_area(area_name) or areas.async_get_area_by_name(
|
area = areas.async_get_area(area_name) or areas.async_get_area_by_name(
|
||||||
area_name
|
area_name
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@ from homeassistant.const import (
|
|||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import area_registry, entity_registry, intent
|
from homeassistant.helpers import area_registry as ar, entity_registry as er, intent
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockUser, async_mock_service
|
from tests.common import MockUser, async_mock_service
|
||||||
@ -186,7 +186,11 @@ async def test_turn_on_multiple_intent(hass: HomeAssistant) -> None:
|
|||||||
assert call.data == {"entity_id": ["light.test_lights_2"]}
|
assert call.data == {"entity_id": ["light.test_lights_2"]}
|
||||||
|
|
||||||
|
|
||||||
async def test_get_state_intent(hass: HomeAssistant) -> None:
|
async def test_get_state_intent(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
area_registry: ar.AreaRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
) -> None:
|
||||||
"""Test HassGetState intent.
|
"""Test HassGetState intent.
|
||||||
|
|
||||||
This tests name, area, domain, device class, and state constraints.
|
This tests name, area, domain, device class, and state constraints.
|
||||||
@ -194,33 +198,31 @@ async def test_get_state_intent(hass: HomeAssistant) -> None:
|
|||||||
assert await async_setup_component(hass, "homeassistant", {})
|
assert await async_setup_component(hass, "homeassistant", {})
|
||||||
assert await async_setup_component(hass, "intent", {})
|
assert await async_setup_component(hass, "intent", {})
|
||||||
|
|
||||||
areas = area_registry.async_get(hass)
|
bedroom = area_registry.async_get_or_create("bedroom")
|
||||||
bedroom = areas.async_get_or_create("bedroom")
|
kitchen = area_registry.async_get_or_create("kitchen")
|
||||||
kitchen = areas.async_get_or_create("kitchen")
|
office = area_registry.async_get_or_create("office")
|
||||||
office = areas.async_get_or_create("office")
|
|
||||||
|
|
||||||
# 1 light in bedroom (off)
|
# 1 light in bedroom (off)
|
||||||
# 1 light in kitchen (on)
|
# 1 light in kitchen (on)
|
||||||
# 1 sensor in kitchen (50)
|
# 1 sensor in kitchen (50)
|
||||||
# 2 binary sensors in the office (problem, moisture, on)
|
# 2 binary sensors in the office (problem, moisture, on)
|
||||||
entities = entity_registry.async_get(hass)
|
bedroom_light = entity_registry.async_get_or_create("light", "demo", "1")
|
||||||
bedroom_light = entities.async_get_or_create("light", "demo", "1")
|
entity_registry.async_update_entity(bedroom_light.entity_id, area_id=bedroom.id)
|
||||||
entities.async_update_entity(bedroom_light.entity_id, area_id=bedroom.id)
|
|
||||||
|
|
||||||
kitchen_sensor = entities.async_get_or_create("sensor", "demo", "2")
|
kitchen_sensor = entity_registry.async_get_or_create("sensor", "demo", "2")
|
||||||
entities.async_update_entity(kitchen_sensor.entity_id, area_id=kitchen.id)
|
entity_registry.async_update_entity(kitchen_sensor.entity_id, area_id=kitchen.id)
|
||||||
|
|
||||||
kitchen_light = entities.async_get_or_create("light", "demo", "3")
|
kitchen_light = entity_registry.async_get_or_create("light", "demo", "3")
|
||||||
entities.async_update_entity(kitchen_light.entity_id, area_id=kitchen.id)
|
entity_registry.async_update_entity(kitchen_light.entity_id, area_id=kitchen.id)
|
||||||
|
|
||||||
kitchen_sensor = entities.async_get_or_create("sensor", "demo", "4")
|
kitchen_sensor = entity_registry.async_get_or_create("sensor", "demo", "4")
|
||||||
entities.async_update_entity(kitchen_sensor.entity_id, area_id=kitchen.id)
|
entity_registry.async_update_entity(kitchen_sensor.entity_id, area_id=kitchen.id)
|
||||||
|
|
||||||
problem_sensor = entities.async_get_or_create("binary_sensor", "demo", "5")
|
problem_sensor = entity_registry.async_get_or_create("binary_sensor", "demo", "5")
|
||||||
entities.async_update_entity(problem_sensor.entity_id, area_id=office.id)
|
entity_registry.async_update_entity(problem_sensor.entity_id, area_id=office.id)
|
||||||
|
|
||||||
moisture_sensor = entities.async_get_or_create("binary_sensor", "demo", "6")
|
moisture_sensor = entity_registry.async_get_or_create("binary_sensor", "demo", "6")
|
||||||
entities.async_update_entity(moisture_sensor.entity_id, area_id=office.id)
|
entity_registry.async_update_entity(moisture_sensor.entity_id, area_id=office.id)
|
||||||
|
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
bedroom_light.entity_id, "off", attributes={ATTR_FRIENDLY_NAME: "bedroom light"}
|
bedroom_light.entity_id, "off", attributes={ATTR_FRIENDLY_NAME: "bedroom light"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user