Release v2.0.0

This commit is contained in:
SMKRV
2024-11-23 03:02:35 +03:00
parent 6ecc3f72d1
commit 12d87e30e1
4 changed files with 12961 additions and 6 deletions
+17
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
import logging
import os
import shutil
from typing import Any, Dict, Optional
import asyncio
import voluptuous as vol
@@ -272,3 +274,18 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except Exception as ex:
_LOGGER.exception("Error unloading entry: %s", str(ex))
return False # Убрано лишнее двоеточие
async def async_setup(hass, config):
"""Copy a custom icon to the www/icons directory."""
# The source of the icon file inside your integration
source = os.path.join(os.path.dirname(__file__), 'icons', 'icon.svg')
# Target directory /config/www/icons/
dest_dir = os.path.join(hass.config.path('www'), 'icons')
# Create the target directory if it does not already exist
os.makedirs(dest_dir, exist_ok=True)
# Path where the icon will be saved
dest = os.path.join(dest_dir, 'icon.svg')
# If the icon has not already been copied, copy it to the target
if not os.path.exists(dest):
shutil.copyfile(source, dest)
return True
@@ -46,6 +46,45 @@ class HATextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
super().__init__()
self.provider = None
def _show_provider_selection(self) -> FlowResult:
"""Show the provider selection form."""
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
vol.Required("provider"): vol.In(API_PROVIDERS),
}),
)
def _show_provider_config(self, provider: str) -> FlowResult:
"""Show the configuration form for the selected provider."""
default_endpoint = (
DEFAULT_OPENAI_ENDPOINT if provider == API_PROVIDER_OPENAI
else DEFAULT_ANTHROPIC_ENDPOINT
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
vol.Required("name", default=f"HA Text AI {len(self._async_current_entries()) + 1}"): str,
vol.Required(CONF_API_PROVIDER): vol.In([provider]),
vol.Required(CONF_API_KEY): str,
vol.Required(CONF_MODEL, default=DEFAULT_MODEL): str,
vol.Optional(CONF_API_ENDPOINT, default=default_endpoint): str,
vol.Optional(CONF_TEMPERATURE, default=DEFAULT_TEMPERATURE): vol.All(
vol.Coerce(float),
vol.Range(min=MIN_TEMPERATURE, max=MAX_TEMPERATURE)
),
vol.Optional(CONF_MAX_TOKENS, default=DEFAULT_MAX_TOKENS): vol.All(
vol.Coerce(int),
vol.Range(min=MIN_MAX_TOKENS, max=MAX_MAX_TOKENS)
),
vol.Optional(CONF_REQUEST_INTERVAL, default=DEFAULT_REQUEST_INTERVAL): vol.All(
vol.Coerce(float),
vol.Range(min=MIN_REQUEST_INTERVAL)
),
})
)
async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None) -> FlowResult:
"""Handle the initial step."""
if user_input is None:
@@ -139,6 +178,7 @@ class HATextAIConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors=errors or {}
)
class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle options flow."""
File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 678 KiB

+2 -6
View File
@@ -99,12 +99,8 @@ class HATextAISensor(CoordinatorEntity, SensorEntity):
@property
def icon(self) -> str:
"""Return the icon based on the current state."""
if self._current_state == STATE_PROCESSING:
return ENTITY_ICON_PROCESSING
elif self._current_state in [STATE_ERROR, STATE_DISCONNECTED, STATE_RATE_LIMITED]:
return ENTITY_ICON_ERROR
return ENTITY_ICON
"""Always return the custom icon."""
return "/local/icons/icon.svg"
@property
def state(self) -> StateType: