Commit Graph
81 Commits
Author SHA1 Message Date
SMKRV 772a614a20 chore: Add .gitignore for pycache, venvs, IDE files, archives 2026-03-12 02:32:42 +03:00
SMKRV c8be545655 fix: Prevent shallow copy mutation in async_get_history with include_metadata
When include_metadata=True, the metadata dict was added directly to the
original history entry objects (shallow copy of list, same dict refs).
Now creates per-entry dict copies before enriching with metadata.
2026-03-12 02:24:52 +03:00
SMKRV a8a91972ba fix: Comprehensive v2.4.0 quality pass — 24 review findings + review agent fixes
Phase A — Critical:
- Remove dual timeout stacking in coordinator._send_to_api
- Add Gemini-specific asyncio.timeout (sync SDK via to_thread)
- Store full text in history for context; cap per-field at 32KB on disk
- Fix instance lookup to match by normalized_name
- Add Bearer/sk-/x-api-key credential sanitization patterns

Phase B — Dead code removal:
- Merge async_ask_question/async_process_question into single method
- Remove dead is_anthropic flag from coordinator and __init__
- Remove unused DEFAULT_TIMEOUT and API_TIMEOUT constants
- Remove redundant _create_history_dir calls
- Consolidate async_check_api to use provider registry

Phase C — Config flow correctness:
- Truncate name before uniqueness check (prevent post-truncation collisions)
- Add async_set_unique_id + _abort_if_unique_id_configured
- Extract shared _build_parameter_schema for ConfigFlow/OptionsFlow dedup

Phase D — UX improvements:
- Optimize history write: serialize from memory, single file write
- Show last 5 history entries in sensor attributes (was 1)
- Return actual error type in ask_question service response
- Add dedicated api_key_required error for provider/endpoint changes
- Pass config_entry to DataUpdateCoordinator (HA 2024.8+)

Phase E — Cleanup:
- Extract _apply_structured_output for OpenAI/DeepSeek dedup
- Reduce ABSOLUTE_MAX_HISTORY_SIZE to 200 with Final annotation
- Remove dead translation keys (queued, invalid_characters)
- Migrate to _attr_has_entity_name = True
- Add from __future__ import annotations to all modules
- Remove redundant api_status sensor attribute
- Add missing translation keys (last_model, last_timestamp, etc.)

Review agent fixes:
- Add archive file cleanup (max 3 archives) to prevent disk exhaustion
- Per-entry storage cap (32KB per field) for history on disk
2026-03-12 02:24:09 +03:00
SMKRV 9cdeb9f417 fix: HA 2024.11+ compatibility and deprecation fixes
CRITICAL:
- Remove OptionsFlowHandler.__init__ (deprecated HA 2024.11+)
- Replace FlowResult with ConfigFlowResult (deprecated HA 2024.4+)

Compatibility:
- Reorder async_unload_entry: unload platforms before coordinator cleanup
- Clean up hass.data[DOMAIN] when last entry removed
- Remove aiohttp from manifest requirements (provided by HA core)
- Replace blocking file I/O in const.py with hardcoded VERSION
- Remove unused os, json, logging imports from const.py
- Fix f-string logger calls in api_client.py to use %s formatting
2026-03-12 02:06:21 +03:00
SMKRV 31560a8835 fix: Round 2 review findings — async SSRF, error sanitization, constants
Security:
- Make validate_endpoint async with hass.async_add_executor_job for DNS resolution
- Use _RestrictedIPError instead of fragile string matching for IP check flow
- Add is_multicast/is_unspecified to SSRF IP restriction checks
- Remove resolved private IP from error messages (generic message)
- Remove raw endpoint from __init__.py error log
- Sanitize error messages in metrics: strip URLs, API keys, Gemini key patterns
- Truncate API error response bodies before logging (512 chars)
- Use generic error messages in Gemini exception handlers (no str(e) interpolation)
- Pass api_key as explicit APIClient constructor parameter (not from header)
- Add defensive validation: Gemini provider requires api_key at construction

Code quality:
- Add constants: DEFAULT_INSTANCE_NAME, MIN/MAX_CONTEXT_MESSAGES, MIN/MAX_HISTORY_SIZE
- Replace all hardcoded schema ranges with named constants
- Move datetime import to module level in history.py
- Remove unused full_history/full_history_available keys
- Chain socket.gaierror properly with raise...from
2026-03-12 01:57:49 +03:00
SMKRV c54bfcff3b fix: Coordinator split, Gemini chat context, review findings fixes
- Extract HistoryManager (history.py) and MetricsManager (metrics.py) from coordinator
- Fix Gemini chat: use client.chats.create(history=...) instead of sequential send_message
- Fix float("inf") in metrics breaking json.dump persistence
- Fix _get_current_state checking wrong error key ("error" vs "error_message")
- Fix API key re-entry requirement when endpoint/provider changes in options flow
- Make CONF_API_KEY optional in options schema (stored key used as fallback)
- Add DNS rebinding protection via socket.getaddrinfo in validate_endpoint
- Remove mass assignment vulnerability in config_flow._create_entry
- Add description_placeholders to all error re-show paths
- Fix history migration overwriting existing JSON data
- Return list copy from get_limited_history to prevent reference leaks
- Add history_info to _get_safe_initial_state for data shape consistency
- Add defensive None check in _get_sanitized_last_response
- Move dt_util import to module level in config_flow
- Remove dead fallback branches in coordinator.last_response property
- Fix sensor min_latency display after float("inf") removal
- Fix history directory permissions from 0o777 to 0o755
- Deduplicate schema definitions via _build_provider_schema()
- Use centralized build_auth_headers from providers.py
2026-03-12 01:50:17 +03:00
SMKRV 63c5c7c51e fix: Address code review findings for v2.4.0
- Fix 404 accepted as valid API response in config_flow validation (both ConfigFlow and OptionsFlow)
- Sanitize catch-all exception in config_flow (str(e) → "unknown" error key)
- Add exception chaining (from err) to ConfigEntryNotReady raise
- Replace datetime.now() with dt_util.utcnow() for HA timezone convention
- Add defensive raise after retry loop in api_client._make_request
- Remove unused CONF_API_KEY/CONF_NAME imports from const.py
- Restore google-genai dependency in manifest (required for Gemini provider)
2026-03-12 01:26:31 +03:00
SMKRV 998103ce73 fix: Comprehensive v2.4.0 security, stability, and quality improvements
Security:
- Add SSRF protection via HTTPS-only endpoint validation with private IP blocking
- Mask API keys in all log output via safe_log_data()
- Sanitize error responses to prevent internal detail leakage
- Remove API key pre-population in config flow forms
- Harden service schemas with input length limits and type coercion

Bug fixes:
- Fix temperature=0 rejected due to Python falsy value bug (0 or default)
- Fix fire-and-forget race condition in coordinator init (5 async_create_task → awaited async_initialize)
- Fix rate limit state not resetting after successful API calls
- Fix ConnectionError incorrectly setting is_rate_limited=True
- Fix _rotate_history calling async method via sync executor
- Fix shutil.move blocking event loop in history migration
- Fix async_shutdown removing wrong key from hass.data
- Replace os.rename with shutil.move for cross-device safety

Improvements:
- Add asyncio.Lock for request serialization
- Replace async_timeout with stdlib asyncio.timeout (Python 3.12+)
- Use SupportsResponse.OPTIONAL for ask_question and get_history services
- Use Platform.SENSOR enum instead of string literal
- Add strings.json for HA translation framework
- Update DEFAULT_ANTHROPIC_MODEL to claude-sonnet-4-6
- Retry only transient errors (429, timeout) in API client

Cleanup:
- Remove dead code: unused schemas, imports, sync_write_history, check_memory, check_connection
- Remove icon copying code from async_setup
- Remove unused dependencies from manifest (anthropic, openai, certifi, async-timeout)
- Remove empty manifest arrays (bluetooth, mqtt, ssdp, usb, zeroconf)
- Fix duplicate JSON keys in 5 translation files
- Fix Serbian translation: "Прекључено" → "Искључено" for disconnected state

Bump version to 2.4.0
2026-03-12 01:24:01 +03:00
SMKRV ce0a75f219 refactor: Phase 0 — extract utils.py and providers.py, centralize provider dispatch
- Create utils.py: normalize_name, get_file_hash, safe_log_data
- Create providers.py: PROVIDER_REGISTRY with get_default_endpoint,
  get_default_model, build_auth_headers
- Add DEFAULT_ANTHROPIC_MODEL constant (was incorrectly using gpt-4o-mini)
- Replace all inline dispatch tables in config_flow.py and __init__.py
- Fix circular import: coordinator.py now imports from utils, not config_flow
- Fix NameError in error paths: replace bare constant refs with provider functions
- Raise ValueError for unknown providers instead of silent OpenAI fallback
2026-03-12 00:55:59 +03:00
SMKRV e7c8b22fde docs: Add v2.4.0 comprehensive fix plan spec
Full refactoring plan covering 48 issues from 4 parallel reviews
(code, security, architecture, UI/UX). 6 phases + final review + tests.
2026-03-12 00:50:02 +03:00
SMKRV 43cbac2d04 feat: Add ability to edit provider, API key, and endpoint in existing integrations
- Extended OptionsFlowHandler with two-step configuration flow
- Step 1: Select provider (OpenAI, Anthropic, DeepSeek, Gemini)
- Step 2: Configure API key, endpoint, model, and other settings
- Auto-reload integration on options change
- When switching providers, show appropriate default endpoint and model
- Updated translations for all 8 languages
2025-12-30 17:22:48 +03:00
SMKRV 986c78dd90 fix: Fix OptionsFlowHandler for HA 2024.1+ compatibility
- Remove __init__ method that was passing config_entry as argument
- OptionsFlow now automatically receives config_entry from base class
- Fixes '500 Internal Server Error' when editing existing integrations
2025-12-30 17:10:06 +03:00
SMKRV 0859c35aec fix: Change release workflow to trigger on release created event 2025-12-30 16:56:27 +03:00
SMKRV 922fefbd43 chore: Bump version to 2.3.0 2025-12-30 16:54:23 +03:00
SMKRV a5ac100b06 feat: Add structured output support with JSON schema validation
- Introduced `structured_output` and `json_schema` parameters to enhance API responses.
- Updated service schemas and API client methods to handle structured output.
- Added translations for new parameters in multiple languages.
- Updated documentation to reflect changes in service capabilities.

Closes #9
2025-12-30 16:44:01 +03:00
smkrvandGitHub ef579af7c1 Create release.yml 2025-12-30 16:27:46 +03:00
SMKRV 3097106e93 feat: Add configurable API timeout setting
- Add CONF_API_TIMEOUT configuration option (5-600 seconds, default 30)
- Update config_flow.py with api_timeout field in provider form and options flow
- Update api_client.py to use configurable timeout instead of hardcoded value
- Update coordinator.py to use api_timeout for async_process_message
- Update __init__.py to read and pass api_timeout from config
- Merge entry.data with entry.options for proper options flow support
- Add translations for api_timeout in all 8 language files (en, ru, de, es, it, hi, sr, zh)
- Bump version to 2.2.0

Closes #8
2025-12-22 00:07:17 +03:00
smkrvandGitHub 35073960b8 Delete ha-text-ai.code-workspace 2025-09-03 00:56:56 +03:00
SMKRV 8d0e0b5e44 docs: update README with context_messages parameter
- Added context_messages parameter to Platform Configuration table
- Fixed duplicate parameter entry in configuration docs
- Parameter allows 1-20 previous messages in context (default: 5)
2025-09-02 23:50:20 +03:00
SMKRV e91c3701c5 Fix: Resolve get_history service parameter handling issue
- Fixed async_get_history method to accept limit parameter and other filtering options
- Updated service schema to support all parameters from services.yaml
- Added support for start_date, include_metadata, and sort_order parameters
- Version bump to 2.1.9
2025-09-02 23:27:34 +03:00
smkrv 7f62101b3e Update HACS minimum HA version to align with README requirement (2024.12.0) 2025-09-02 23:15:01 +03:00
smkrvandGitHub 3729c3736f Update hassfest.yaml 2025-09-02 09:36:46 +03:00
smkrvandGitHub f5ce5e459a Update hassfest.yaml
fix: https://github.com/smkrv/ha-text-ai/security/code-scanning/2
2025-09-02 09:24:35 +03:00
smkrvGitHubCopilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
4064486b1e Potential fix for code scanning alert no. 1: Workflow does not contain permissions
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-09-02 09:18:15 +03:00
smkrvandGitHub cad0fd7031 Merge pull request #5 from Azzedde/main
Add Gemini API provider support to HA Text AI integration by @Azzedde
2025-05-19 14:44:06 +03:00
smkrvandGitHub b059744716 Update README.md 2024-12-04 23:23:46 +03:00
smkrvandGitHub 4b3efc0b6f Update README_RU.md 2024-11-27 01:36:11 +03:00
smkrvandGitHub 1592fc2371 Delete socia_logo.png 2024-11-26 23:50:38 +03:00
smkrvandGitHub d5a6613428 Update README.md 2024-11-26 18:00:45 +03:00
smkrvandGitHub a7a945e6e1 Create ha_text_ai_request_push.yaml 2024-11-15 02:24:29 +03:00
smkrvandGitHub 324f43193f Update ha_text_ai_request.yaml 2024-11-15 02:21:59 +03:00
smkrvandGitHub d1822cf04f Update ha_text_ai_request.yaml 2024-11-15 02:15:12 +03:00
smkrvandGitHub 2bd8f2d34f Update ha_text_ai_request.yaml 2024-11-15 02:11:41 +03:00
smkrvandGitHub 947fdc3096 Update README.md 2024-11-15 01:55:29 +03:00
smkrvandGitHub 7085bd3cc3 Update ha_text_ai_request.yaml 2024-11-15 01:47:17 +03:00
smkrvandGitHub cf259ade34 Create ru.json 2024-11-15 01:41:59 +03:00
smkrvandGitHub 9bc1df271e Update en.json 2024-11-15 01:40:05 +03:00
smkrvandGitHub a724606e0e Update config_flow.py 2024-11-15 01:38:57 +03:00
smkrvandGitHub 65e81f8313 Update manifest.json 2024-11-15 01:14:35 +03:00
smkrvandGitHub f2a8e878f0 Update manifest.json 2024-11-15 01:12:45 +03:00
smkrvandGitHub 37e89dacc1 Update config_flow.py 2024-11-15 01:11:24 +03:00
smkrvandGitHub a6218c1cac Update const.py 2024-11-15 00:59:39 +03:00
smkrvandGitHub 7c4331bea3 Update manifest.json 2024-11-15 00:57:36 +03:00
smkrvandGitHub 992d9b3b97 Update en.json 2024-11-15 00:56:20 +03:00
smkrvandGitHub ef78a9da0d Update config_flow.py 2024-11-15 00:55:48 +03:00
smkrvandGitHub cec95a1bce Update hacs.json 2024-11-14 23:42:41 +03:00
smkrvandGitHub 453181ab8c Update hacs.json 2024-11-14 23:39:00 +03:00
smkrvandGitHub c4c1113316 Create icon.svg 2024-11-14 23:32:14 +03:00
smkrvandGitHub a0c5204396 Update hacs.json 2024-11-14 23:31:07 +03:00
smkrvandGitHub 0b48386626 Update manifest.json 2024-11-14 23:26:39 +03:00
smkrvandGitHub c8f315620a Update __init__.py 2024-11-14 23:24:40 +03:00
smkrvandGitHub 0789f8c386 Update config_flow.py 2024-11-14 23:23:01 +03:00
smkrvandGitHub 9a8c676570 Update hacs.json 2024-11-14 23:19:37 +03:00
smkrvandGitHub 55c1309024 Rename .hacs.json to hacs.json 2024-11-14 23:19:24 +03:00
smkrvandGitHub 14760f5bf2 Update .hacs.json 2024-11-14 19:47:25 +03:00
smkrvandGitHub 898bbe20e6 Update .hacs.json 2024-11-14 19:45:02 +03:00
smkrvandGitHub 63b1d537eb Create .hacs.json 2024-11-14 19:36:53 +03:00
smkrvandGitHub 2f4675dcf9 Delete hacs.json 2024-11-14 19:36:31 +03:00
smkrvandGitHub c7ec407e44 Create LICENSE 2024-11-14 18:56:15 +03:00
smkrvandGitHub 369f599d09 Update hacs.json 2024-11-14 18:54:57 +03:00
smkrvandGitHub 15ad3f8e05 Update README.md 2024-11-14 18:53:44 +03:00
smkrvandGitHub 467779e61c Update README.md 2024-11-14 18:53:02 +03:00
smkrvandGitHub 38c8c8fde6 Update README.md 2024-11-14 18:50:04 +03:00
smkrvandGitHub 5f44b2b69f Update README.md 2024-11-14 18:49:02 +03:00
smkrvandGitHub 8478aa3d7a Update README.md 2024-11-14 18:47:53 +03:00
smkrvandGitHub 5013680942 Update README.md 2024-11-14 18:45:46 +03:00
smkrvandGitHub d7ea09fafb Update README.md 2024-11-14 18:43:46 +03:00
smkrvandGitHub 5f129d9245 Update README.md 2024-11-14 18:43:19 +03:00
smkrvandGitHub b00bd9530e Create README.md 2024-11-14 18:39:06 +03:00
smkrvandGitHub 2dea27ccc8 Create ha_text_ai_request.yaml 2024-11-14 18:37:35 +03:00
smkrvandGitHub 725754a2e3 Create services.yaml 2024-11-14 18:35:50 +03:00
smkrvandGitHub b7905b1aa1 Create en.json 2024-11-14 18:35:18 +03:00
smkrvandGitHub a255743526 Create config_flow.py 2024-11-14 18:34:38 +03:00
smkrvandGitHub 4f625d8dc4 Create __init__.py 2024-11-14 18:32:41 +03:00
smkrvandGitHub 39d363dc54 Create const.py 2024-11-14 18:30:03 +03:00
smkrvandGitHub 205d28a6be Update manifest.json 2024-11-14 18:29:29 +03:00
smkrvandGitHub a40873e342 Create manifest.json 2024-11-14 18:28:36 +03:00
smkrvandGitHub e4b5b6ece8 Create validate.yaml 2024-11-14 18:26:58 +03:00
smkrvandGitHub 95b2efd118 Create hassfest.yaml 2024-11-14 18:25:30 +03:00
smkrvandGitHub b429fa01bd Create .gitignore 2024-11-14 18:24:39 +03:00
smkrvandGitHub b0b342cb06 Create hacs.json 2024-11-14 18:23:55 +03:00