Skip to content

Fix TemperatureAPI making API calls and showing unhealthy when disabled#3839

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-temperatureapi-error-handling
Draft

Fix TemperatureAPI making API calls and showing unhealthy when disabled#3839
Copilot wants to merge 2 commits intomainfrom
copilot/fix-temperatureapi-error-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 26, 2026

TemperatureAPI continued polling the Open-Meteo endpoint even after toggling temperature_enable off via the UI, and the component incorrectly reported as unhealthy in the dashboard.

Two bugs:

  • Stale enable flag: run() read self.temperature_enable cached at init time (from apps.yaml). A UI toggle writes to an HA entity state, not apps.yaml, so the cached value was never updated and polling continued regardless.
  • Missing health timestamp: When temperature_enable=False, run() returned early without calling update_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):

  • Re-read temperature_enable live on every run() call via get_arg(), so UI toggle changes take effect without a restart:
    temperature_enable = self.get_arg("temperature_enable", self.temperature_enable)
    if not temperature_enable:
        self.update_success_timestamp()  # keep health check green
        return True

Test updates (tests/test_temperature.py):

  • Added get_arg() to MockTemperatureAPI to satisfy the dynamic lookup.
  • Updated _test_run_disabled to assert that update_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
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --quick (dns block)
  • gitlab.com
    • Triggering command: /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
    • Triggering command: /home/REDACTED/work/batpred/batpred/coverage/venv/bin/python3 python3 ../apps/predbat/unit_test.py --test temperature (http block)
    • Triggering command: /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:

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
Copilot AI requested a review from springfall2008 April 26, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting "Warn: TemperatureAPI: Failed to fetch data, status code 502" messages even thought temperature component is disabled

2 participants