fix: Services survive config entry reload, get_history returns a dict response

- service registration extracted to idempotent _async_register_services,
  called from both async_setup and async_setup_entry: unloading the last
  entry unregisters services, and a reload (every options change) never
  re-ran async_setup, leaving the integration without services
- get_history handler wraps the list in {"history": [...]}: HA rejects
  non-dict action responses, so every return_response call failed with a
  server error since the service gained SupportsResponse (v2.4.x) - the
  path never worked, no consumer could depend on the old shape
- README: get_history example shows response_variable usage and the
  actual limit clamp semantics

Both found by live smoke test in HA 2026.7 (Docker), not by static review
This commit is contained in:
SMKRV
2026-07-07 01:38:27 +03:00
parent bcfe69b5f7
commit fc59f584a3
2 changed files with 24 additions and 5 deletions
+2 -1
View File
@@ -283,12 +283,13 @@ data:
```yaml
service: ha_text_ai.get_history
data:
limit: 5 # optional, number of conversations to return (1-100)
limit: 5 # optional, number of conversations to return (values above 200 are clamped); omit to get the full stored history
filter_model: "gpt-4o" # optional, filter by specific AI model
start_date: "2025-02-01" # optional, filter conversations from this date
include_metadata: false # optional, include tokens, response time, etc.
sort_order: "newest" # optional, sort order: "newest" or "oldest"
instance: sensor.ha_text_ai_gpt
response_variable: history_result # entries are in history_result.history
```
## 🚀 Advanced Automation Examples with Response Variables