mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Cleanup OpenAI and Ollama conversation entities (#116714)
This commit is contained in:
parent
1eed5442e2
commit
9b4099950c
@ -45,7 +45,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up conversation entities."""
|
"""Set up conversation entities."""
|
||||||
agent = OllamaConversationEntity(hass, config_entry)
|
agent = OllamaConversationEntity(config_entry)
|
||||||
async_add_entities([agent])
|
async_add_entities([agent])
|
||||||
|
|
||||||
|
|
||||||
@ -56,9 +56,8 @@ class OllamaConversationEntity(
|
|||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
def __init__(self, entry: ConfigEntry) -> None:
|
||||||
"""Initialize the agent."""
|
"""Initialize the agent."""
|
||||||
self.hass = hass
|
|
||||||
self.entry = entry
|
self.entry = entry
|
||||||
|
|
||||||
# conversation id -> message history
|
# conversation id -> message history
|
||||||
@ -223,21 +222,21 @@ class OllamaConversationEntity(
|
|||||||
]
|
]
|
||||||
|
|
||||||
for state in exposed_states:
|
for state in exposed_states:
|
||||||
entity = entity_registry.async_get(state.entity_id)
|
entity_entry = entity_registry.async_get(state.entity_id)
|
||||||
names = [state.name]
|
names = [state.name]
|
||||||
area_names = []
|
area_names = []
|
||||||
|
|
||||||
if entity is not None:
|
if entity_entry is not None:
|
||||||
# Add aliases
|
# Add aliases
|
||||||
names.extend(entity.aliases)
|
names.extend(entity_entry.aliases)
|
||||||
if entity.area_id and (
|
if entity_entry.area_id and (
|
||||||
area := area_registry.async_get_area(entity.area_id)
|
area := area_registry.async_get_area(entity_entry.area_id)
|
||||||
):
|
):
|
||||||
# Entity is in area
|
# Entity is in area
|
||||||
area_names.append(area.name)
|
area_names.append(area.name)
|
||||||
area_names.extend(area.aliases)
|
area_names.extend(area.aliases)
|
||||||
elif entity.device_id and (
|
elif entity_entry.device_id and (
|
||||||
device := device_registry.async_get(entity.device_id)
|
device := device_registry.async_get(entity_entry.device_id)
|
||||||
):
|
):
|
||||||
# Check device area
|
# Check device area
|
||||||
if device.area_id and (
|
if device.area_id and (
|
||||||
|
@ -35,7 +35,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up conversation entities."""
|
"""Set up conversation entities."""
|
||||||
agent = OpenAIConversationEntity(hass, config_entry)
|
agent = OpenAIConversationEntity(config_entry)
|
||||||
async_add_entities([agent])
|
async_add_entities([agent])
|
||||||
|
|
||||||
|
|
||||||
@ -46,9 +46,8 @@ class OpenAIConversationEntity(
|
|||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
|
def __init__(self, entry: ConfigEntry) -> None:
|
||||||
"""Initialize the agent."""
|
"""Initialize the agent."""
|
||||||
self.hass = hass
|
|
||||||
self.entry = entry
|
self.entry = entry
|
||||||
self.history: dict[str, list[dict]] = {}
|
self.history: dict[str, list[dict]] = {}
|
||||||
self._attr_name = entry.title
|
self._attr_name = entry.title
|
||||||
|
Loading…
x
Reference in New Issue
Block a user