mirror of
https://github.com/sudoxreboot/groqd
synced 2026-04-14 11:36:49 +00:00
updated tool call handling updated light color handling updated searxng handling - all 3 should work now
50 lines
1.3 KiB
Python
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
|