diff --git a/homeassistant/components/openai_conversation/const.py b/homeassistant/components/openai_conversation/const.py index edad9574f7b..34516cbb109 100644 --- a/homeassistant/components/openai_conversation/const.py +++ b/homeassistant/components/openai_conversation/const.py @@ -7,17 +7,17 @@ DEFAULT_PROMPT = """This smart home is controlled by Home Assistant. An overview of the areas and the devices in this smart home: {%- for area in areas %} -{%- set area_info = namespace(printed=false) %} -{%- for device in area_devices(area.name) -%} -{%- if not device_attr(device, "disabled_by") and not device_attr(device, "entry_type") %} -{%- if not area_info.printed %} + {%- set area_info = namespace(printed=false) %} + {%- for device in area_devices(area.name) -%} + {%- if not device_attr(device, "disabled_by") and not device_attr(device, "entry_type") %} + {%- if not area_info.printed %} {{ area.name }}: -{%- set area_info.printed = true %} -{%- endif %} + {%- set area_info.printed = true %} + {%- endif %} - {{ device_attr(device, "name") }}{% if device_attr(device, "model") not in device_attr(device, "name") %} ({{ device_attr(device, "model") }}){% endif %} -{%- endif %} -{%- endfor %} + {%- endif %} + {%- endfor %} {%- endfor %} Answer the users questions about the world truthfully. diff --git a/tests/components/openai_conversation/test_init.py b/tests/components/openai_conversation/test_init.py index eb6afebd80e..ac5be9f6115 100644 --- a/tests/components/openai_conversation/test_init.py +++ b/tests/components/openai_conversation/test_init.py @@ -50,6 +50,17 @@ async def test_default_prompt(hass, mock_init_component): model="Test Model 3A", suggested_area="Test Area 2", ) + device = device_reg.async_get_or_create( + config_entry_id="1234", + connections={("test", "9876-disabled")}, + name="Test Device 3", + manufacturer="Test Manufacturer 3", + model="Test Model 3A", + suggested_area="Test Area 2", + ) + device_reg.async_update_device( + device.id, disabled_by=device_registry.DeviceEntryDisabler.USER + ) with patch("openai.Completion.create") as mock_create: await conversation.async_converse(hass, "hello", None, Context())