groqd/custom_components/groqd/__init__.py
sudoxreboot 61f0030f33
Add files via upload
updated tool call handling
updated light color handling
updated searxng handling
- all 3 should work now
2026-03-11 13:44:09 -05:00

50 lines
1.3 KiB
Python

"""groqd integration."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any
import groq
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, Platform
from homeassistant.core import HomeAssistant
from .const import DOMAIN
PLATFORMS: list[Platform] = [Platform.CONVERSATION, Platform.BUTTON]
@dataclass
class GroqdRuntimeData:
"""Runtime data for groqd."""
client: groq.AsyncClient
conversation_agent: Any = field(default=None)
type GroqdConfigEntry = ConfigEntry[GroqdRuntimeData]
async def async_setup_entry(hass: HomeAssistant, entry: GroqdConfigEntry) -> bool:
"""Set up groqd from a config entry."""
api_key = entry.data[CONF_API_KEY]
client = await hass.async_add_executor_job(
lambda: groq.AsyncClient(api_key=api_key)
)
entry.runtime_data = GroqdRuntimeData(client=client)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: GroqdConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
try:
await entry.runtime_data.client.close()
except Exception:
pass
return unload_ok