add integration scaffolding

This commit is contained in:
Alex O'Connell
2023-10-24 21:56:33 -04:00
parent 0e08124260
commit dee600c974
8 changed files with 193 additions and 2 deletions

3
.gitignore vendored
View File

@@ -1 +1,2 @@
models/
models/
.DS_Store

View File

@@ -32,7 +32,7 @@ def main():
"light.office_desk_lamp = on",
"light.family_room_overhead = on",
"fan.family_room = off",
"lock.fron_door = locked"
"lock.front_door = locked"
],
"available_services": ["turn_on", "turn_off", "toggle", "lock", "unlock" ],
"question": request,

View File

@@ -0,0 +1,34 @@
"""The LLM Conductor integration."""
from __future__ import annotations
import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.components.button import ButtonEntity
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
# TODO List the platforms that you want to support.
# For your initial PR, limit it to 1 platform.
PLATFORMS: list[Platform] = [Platform.BUTTON]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up LLM Conductor from a config entry."""
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = entry
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if isUnloaded := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
await hass.data[DOMAIN][f"{entry.entry_id}-entity"].unload_model()
return isUnloaded

View File

@@ -0,0 +1,50 @@
"""Support for buttons which integrates with other components."""
from __future__ import annotations
import logging
import transformers
from homeassistant.config_entries import ConfigEntry
from homeassistant.components.button import ButtonEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
entity = LLMConductor(hass, entry)
hass.data[DOMAIN][f"{entry.entry_id}-entity"] = entity
async_add_entities([entity])
class LLMConductor(ButtonEntity):
"""Representation of an Awesome Light."""
def __init__(self, hass, entry: ConfigEntry) -> None:
"""Initialize an LLMConductor"""
self._name = entry.title
self._state = None
self._model = None
self._attr_unique_id = f"{entry.entry_id}-llm-conductor"
@property
def name(self) -> str:
"""Return the display name of this light."""
return self._name
def press(self) -> None:
"""Presses the button"""
_LOGGER.info("Button was pressed")
async def unload_model(self):
_LOGGER.info("Unloading Model")

View File

@@ -0,0 +1,66 @@
"""Config flow for LLM Conductor integration."""
from __future__ import annotations
import logging
from typing import Any
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from homeassistant.components.button import PLATFORM_SCHEMA
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
STEP_USER_DATA_SCHEMA = vol.Schema(
{
vol.Required("conductor_name"): str,
vol.Required("model_name"): str,
vol.Optional("temperature", default=0.7): float,
}
)
async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]:
"""Validate the user input allows us to connect.
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
"""
# Return info that you want to store in the config entry.
return {
"title": data["conductor_name"],
"description": f"Model '{data['model_name']}' at temperature {data['temperature']}",
}
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for LLM Conductor."""
VERSION = 1
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
errors: dict[str, str] = {}
if user_input is not None:
try:
info = await validate_input(self.hass, user_input)
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
return self.async_create_entry(
title=info["title"],
description=info["description"],
data=user_input,
)
return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
)

View File

@@ -0,0 +1,3 @@
"""Constants for the LLM Conductor integration."""
DOMAIN = "llm_conductor"

View File

@@ -0,0 +1,16 @@
{
"domain": "llm_conductor",
"name": "LLM Conductor",
"codeowners": [
"@acon96"
],
"config_flow": true,
"dependencies": [],
"documentation": "https://www.home-assistant.io/integrations/llm_conductor",
"integration_type": "device",
"homekit": {},
"iot_class": "local_push",
"requirements": [],
"ssdp": [],
"zeroconf": []
}

View File

@@ -0,0 +1,21 @@
{
"config": {
"step": {
"user": {
"data": {
"conductor_name": "Conductor Name",
"model_name": "Hugging Face Model Name",
"temperature": "Temperature"
}
}
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
}
}
}