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
This commit is contained in:
SMKRV
2026-03-12 01:50:17 +03:00
parent 63c5c7c51e
commit c54bfcff3b
7 changed files with 1053 additions and 1200 deletions
+1 -5
View File
@@ -9,8 +9,6 @@ Sensor platform for HA Text AI.
import logging
import math
from typing import Any, Dict
from datetime import datetime, timedelta
from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
@@ -277,9 +275,7 @@ class HATextAISensor(CoordinatorEntity, SensorEntity):
METRIC_FAILED_REQUESTS: metrics.get("failed_requests", 0),
METRIC_AVERAGE_LATENCY: round(metrics.get("average_latency", 0), 2),
METRIC_MAX_LATENCY: round(metrics.get("max_latency", 0), 2),
METRIC_MIN_LATENCY: (metrics.get("min_latency")
if metrics.get("min_latency") != float("inf")
else None),
METRIC_MIN_LATENCY: metrics.get("min_latency", 0) or None,
})
# Last response handling