From 80f14168ee4f399fd401e1371b10f02f4304e6a2 Mon Sep 17 00:00:00 2001 From: alves-dev Date: Wed, 22 Oct 2025 19:35:14 -0300 Subject: [PATCH] fix: Tokens count --- CHANGELOG.md | 7 +++++++ custom_components/stackspot/agent.py | 10 ++++++---- custom_components/stackspot/manifest.json | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f04547c..dd1746c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All remarkable changes for this project will be documented here. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [SemVer](https://semver.org). +--- +## [1.5.0] - 2025-10-22 + +### Fix +- There was a change in the StackSpot API response that caused the token count to break + - **NOTE**: I was contacted and informed that the fields are under review and that after that the documentation will be updated. + --- ## [1.4.0] - 2025-09-17 diff --git a/custom_components/stackspot/agent.py b/custom_components/stackspot/agent.py index 68e399b..c81605c 100644 --- a/custom_components/stackspot/agent.py +++ b/custom_components/stackspot/agent.py @@ -127,11 +127,13 @@ async def _send_prompt_to_stackspot(self, prompt: str) -> str: async def _actions_with_response(self, response: dict) -> None: if "tokens" in response and isinstance(response["tokens"], dict): - user_tokens = response["tokens"].get("user", 0) - enrichment_tokens = response["tokens"].get("enrichment", 0) - output_tokens = response["tokens"].get("output", 0) + # TODO: Verificar quando o pessoal atualizar a documentação + user_tokens = response["tokens"].get("user") or 0 + input_token = response["tokens"].get("input") or 0 + enrichment_tokens = response["tokens"].get("enrichment") or 0 + output_tokens = response["tokens"].get("output") or 0 - await self._update_token_sensors(user_tokens, enrichment_tokens, output_tokens) + await self._update_token_sensors(user_tokens + input_token, enrichment_tokens, output_tokens) else: _LOGGER.debug("Resposta da StackSpot AI sem dados de tokens.") diff --git a/custom_components/stackspot/manifest.json b/custom_components/stackspot/manifest.json index bbb192c..0c3f75d 100644 --- a/custom_components/stackspot/manifest.json +++ b/custom_components/stackspot/manifest.json @@ -15,5 +15,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/alves-dev/stackspot-homeassistant/issues", "requirements": [], - "version": "1.4.0" + "version": "1.5.0" }