🐛 Fix NameError in AutoProductionRate sensor #11

Merged
mat merged 1 commit from fix/c1-auto-production-rate into main 2026-04-24 13:43:20 +00:00
Owner

Summary

  • ComwattAutoProductionRateSensor.update assigned self._attr_native_value = auto_production_rate — an undefined name — on every poll. The except Exception below silently swallowed the NameError and triggered a full re-auth cycle every time the sensor updated.
  • The correct assignment already lives a few lines down, reading the last bucket of autoproductionRates as a percentage.
  • Drop the dead line.

Side-effects

  • The xfail marker on tests/test_sensor.py::test_auto_production_rate_reads_latest_value is removed; the test now passes normally.
  • The F821 entry in the ruff ignore list (which was only there for this specific NameError) is removed.

Test plan

  • pytest tests/test_sensor.py — 6 passed locally (was 5 passed + 1 xfailed).
  • ruff check . — still green with F821 no longer ignored.
## Summary - `ComwattAutoProductionRateSensor.update` assigned `self._attr_native_value = auto_production_rate` — an undefined name — on every poll. The `except Exception` below silently swallowed the `NameError` and triggered a full re-auth cycle every time the sensor updated. - The correct assignment already lives a few lines down, reading the last bucket of `autoproductionRates` as a percentage. - Drop the dead line. ## Side-effects - The xfail marker on `tests/test_sensor.py::test_auto_production_rate_reads_latest_value` is removed; the test now passes normally. - The `F821` entry in the ruff ignore list (which was only there for this specific NameError) is removed. ## Test plan - [x] `pytest tests/test_sensor.py` — 6 passed locally (was 5 passed + 1 xfailed). - [x] `ruff check .` — still green with `F821` no longer ignored.
🐛 Fix NameError in AutoProductionRate sensor
All checks were successful
Validate / validate-hacs (push) Has been skipped
Validate / validate-hassfest (push) Has been skipped
Validate / lint-ruff (push) Successful in 6s
Validate / test-pytest (push) Successful in 1m45s
Validate / type-check-mypy (push) Successful in 1m49s
Validate / validate-hacs (pull_request) Has been skipped
Validate / validate-hassfest (pull_request) Has been skipped
Validate / lint-ruff (pull_request) Successful in 6s
Validate / test-pytest (pull_request) Successful in 1m44s
Validate / type-check-mypy (pull_request) Successful in 1m49s
f0419a974e
`ComwattAutoProductionRateSensor.update` assigned `self._attr_native_value`
to an undefined name `auto_production_rate`, producing a `NameError` on
every poll. The bare `except Exception` silently forced a re-auth on each
occurrence. The correct assignment already existed below, reading the
percentage from the time series.

Remove the dead line. The fix causes the xfail-marked sensor test to
start passing, so its marker is dropped, and the `F821` entry that was
only tracking this specific case is removed from the ruff ignore list.
mat merged commit cab165707f into main 2026-04-24 13:43:20 +00:00
mat deleted branch fix/c1-auto-production-rate 2026-04-24 13:43:20 +00:00
mat referenced this pull request from a commit 2026-04-24 14:26:33 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
mat referenced this pull request from a commit 2026-04-24 21:51:56 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mat/homeassistant-comwatt!11
No description provided.