Skip to content

Commit

Permalink
Use area id for context instead of name (#105313)
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam authored and frenck committed Dec 8, 2023
1 parent 1e3c154 commit d9b31e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/conversation/default_agent.py
Expand Up @@ -649,7 +649,7 @@ def _make_intent_context(
if device_area is None:
return None

return {"area": device_area.name}
return {"area": device_area.id}

def _get_error_text(
self, response_type: ResponseType, lang_intents: LanguageIntents | None
Expand Down
12 changes: 9 additions & 3 deletions tests/components/conversation/test_default_agent.py
Expand Up @@ -307,8 +307,8 @@ async def test_device_area_context(
turn_on_calls = async_mock_service(hass, "light", "turn_on")
turn_off_calls = async_mock_service(hass, "light", "turn_off")

area_kitchen = area_registry.async_get_or_create("kitchen")
area_bedroom = area_registry.async_get_or_create("bedroom")
area_kitchen = area_registry.async_get_or_create("Kitchen")
area_bedroom = area_registry.async_get_or_create("Bedroom")

# Create 2 lights in each area
area_lights = defaultdict(list)
Expand All @@ -323,7 +323,7 @@ async def test_device_area_context(
"off",
attributes={ATTR_FRIENDLY_NAME: f"{area.name} light {i}"},
)
area_lights[area.name].append(light_entity)
area_lights[area.id].append(light_entity)

# Create voice satellites in each area
entry = MockConfigEntry()
Expand Down Expand Up @@ -354,6 +354,8 @@ async def test_device_area_context(
)
await hass.async_block_till_done()
assert result.response.response_type == intent.IntentResponseType.ACTION_DONE
assert result.response.intent is not None
assert result.response.intent.slots["area"]["value"] == area_kitchen.id

# Verify only kitchen lights were targeted
assert {s.entity_id for s in result.response.matched_states} == {
Expand All @@ -375,6 +377,8 @@ async def test_device_area_context(
)
await hass.async_block_till_done()
assert result.response.response_type == intent.IntentResponseType.ACTION_DONE
assert result.response.intent is not None
assert result.response.intent.slots["area"]["value"] == area_bedroom.id

# Verify only bedroom lights were targeted
assert {s.entity_id for s in result.response.matched_states} == {
Expand All @@ -396,6 +400,8 @@ async def test_device_area_context(
)
await hass.async_block_till_done()
assert result.response.response_type == intent.IntentResponseType.ACTION_DONE
assert result.response.intent is not None
assert result.response.intent.slots["area"]["value"] == area_bedroom.id

# Verify only bedroom lights were targeted
assert {s.entity_id for s in result.response.matched_states} == {
Expand Down

0 comments on commit d9b31e9

Please sign in to comment.