Fix TemperatureAPI making API calls and showing unhealthy when disabled#3839
Merged
springfall2008 merged 3 commits intomainfrom May 7, 2026
Merged
Conversation
Agent-Logs-Url: https://github.com/springfall2008/batpred/sessions/1fe42cbb-3fc0-4288-8f4d-955796e16cbb Co-authored-by: springfall2008 <48591903+springfall2008@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix TemperatureAPI data fetch error when component is disabled
Fix TemperatureAPI making API calls and showing unhealthy when disabled
Apr 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR targets the TemperatureAPI component to ensure it behaves correctly when temperature_enable is toggled off at runtime (stop polling external endpoints) and to keep the component health status from showing as unhealthy when disabled.
Changes:
- Updates
TemperatureAPI.run()to callupdate_success_timestamp()before returning early when disabled. - Extends the temperature component test mock to include a
get_arg()method. - Updates the “disabled” run test to assert the success timestamp is updated while disabled.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/predbat/temperature.py | Marks the component healthy when temperature_enable is false by updating the success timestamp before returning. |
| apps/predbat/tests/test_temperature.py | Adds get_arg() to the mock and strengthens the disabled-path test to require a health timestamp update. |
| @@ -55,6 +55,7 @@ async def run(self, seconds, first): | |||
| """ | |||
| try: | |||
| if not self.temperature_enable: | |||
Comment on lines
+757
to
+761
| if temp_api._last_updated_time is None: | ||
| print(" ERROR: update_success_timestamp should be called when disabled to keep component healthy") | ||
| return 1 | ||
|
|
||
| print(" PASS: run returns True without fetching when disabled, and marks component healthy") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TemperatureAPIcontinued polling the Open-Meteo endpoint even after togglingtemperature_enableoff via the UI, and the component incorrectly reported as unhealthy in the dashboard.Two bugs:
run()readself.temperature_enablecached at init time (fromapps.yaml). A UI toggle writes to an HA entity state, notapps.yaml, so the cached value was never updated and polling continued regardless.temperature_enable=False,run()returned early without callingupdate_success_timestamp(). The health check considers any component with no success update in 60+ minutes as dead, triggering the "Demand (unhealthy)" banner.Fixes (
temperature.py):temperature_enablelive on everyrun()call viaget_arg(), so UI toggle changes take effect without a restart:Test updates (
tests/test_temperature.py):get_arg()toMockTemperatureAPIto satisfy the dynamic lookup._test_run_disabledto assert thatupdate_success_timestamp()is called when the component is disabled.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.octopus.energy/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick(dns block)gitlab.com/usr/lib/git-core/git-remote-https /usr/lib/git-core/git-remote-https origin REDACTED(dns block)https://api.github.com/repos/springfall2008/batpred/contents/apps/predbat/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test temperature(http block)/home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick(http block)If you need me to access, download, or install something from one of these locations, you can either: