Skip to content

test: add entity test coverage for sensor/switch/number/button/binary_sensor/update platforms - #395

Draft
rhammen wants to merge 18 commits into
custom-components:masterfrom
rhammen:test/platform-entity-coverage
Draft

test: add entity test coverage for sensor/switch/number/button/binary_sensor/update platforms#395
rhammen wants to merge 18 commits into
custom-components:masterfrom
rhammen:test/platform-entity-coverage

Conversation

@rhammen

@rhammen rhammen commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds unit tests for the six HA entity-platform files that previously had 0% coverage: sensor.py, switch.py, number.py, button.py, binary_sensor.py, update.py.
  • Exercises real entity-class logic (value transforms, _post_init overrides, available overrides, async command methods with success/HomeAssistantError-failure paths) using MagicMock(spec=Charger)/MagicMock(spec=Installation) test doubles so a typo'd method name fails loudly instead of silently returning a fresh mock.
  • Stacked on test: add unit tests for ZaptecUpdateCoordinator and ZaptecBaseEntity #394 (adds the hass/config_entry fixtures and coordinator.py/entity.py coverage this branch builds on).
  • Also includes one commit from a separate, already-reviewed workstream: services.py test coverage plus a real services.yaml bugfix (documented service key was update_firmware, actual registered service is upgrade_firmware).

Coverage after this branch: sensor.py 97%, switch.py 97%, number.py 97%, button.py 93%, binary_sensor.py 93%, update.py 94% — remaining gaps are exactly each file's async_setup_entry() body (declarative/thin-delegation code, out of scope by design).

Test plan

  • SKIP_ZAPTEC_API_TEST=true pytest tests -q → 132 passed, 2 skipped, 22 errors (pre-existing DNS-fixture gap in test_zconst.py/test_redact.py, documented in CLAUDE.md, unrelated to this change)
  • ruff format --diff / ruff check clean on all new files
  • Each task individually reviewed (spec compliance + code quality, both approved) plus a final whole-branch review (no Critical/Important findings)

🤖 Generated with Claude Code

rhammen and others added 16 commits July 11, 2026 01:19
Covers _trigger_poll's per-object delay/refresh sequencing (charger vs
installation), the installation-triggers-tracked-children fan-out and its
untracked-child skip path, trigger_poll's no-op when there is no
zaptec_object, and the cancel-in-flight-task-before-starting-new-one race.

The final test needed two asyncio.sleep(0) yields rather than one: the
first lets the replacement task run to completion, the second lets its
add_done_callback (which clears _trigger_task) actually fire, since Task
done-callbacks are scheduled via call_soon rather than invoked
synchronously on completion. Verified deterministic across 45+ runs.
…l mismatch

Cover service registration/unregistration, iter_objects id resolution and
every error path, each handler's success/failure behavior, and the
voluptuous schemas. Also fix services.yaml documenting the firmware-upgrade
service under the wrong key (update_firmware instead of upgrade_firmware),
found via a new test asserting the yaml keys match the registered service
names.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
rhammen and others added 2 commits July 16, 2026 00:40
…t coverage

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Keep planning docs local-only rather than publishing them to the PR branch, matching the convention used on other in-flight PRs.
@rhammen
rhammen marked this pull request as draft July 25, 2026 16:38
rhammen added a commit to rhammen/zaptec that referenced this pull request Jul 26, 2026
….__getitem__

_backed_get's mock .get() did a bare dict lookup, diverging from the real
ZaptecBase (which normalizes camelCase API keys to snake_case symmetrically
on both read and write). Harmless today since all seed data is hand-authored
snake_case, but would have silently broken a future fixture seeded from a
raw diagnostics dump (e.g. custom-components#395) without the normalization. to_under is
idempotent on already-normalized keys, so this has no effect on current tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
rhammen added a commit to rhammen/zaptec that referenced this pull request Jul 27, 2026
…omponents#300)

Standalone version of custom-components#396, rebased onto master without the custom-components#394/custom-components#395
test-coverage dependencies. Imports Zaptec's archived charge-session
history (/api/sessions/archived) into Home Assistant long-term
statistics as an external statistic (zaptec:energy_<id>), fixing the
Energy Dashboard hour-misattribution described in custom-components#300 (and custom-components#162).

Squashed from the 17 energy-statistics commits (a62dc20..b103473) of
custom-components#396. Keeps the self-contained tests (bucket_sessions_hourly / _floor_hour
and the archived-sessions API client); omits the ZaptecStatisticsCoordinator
async tests and test_manager.py, which depend on fixtures introduced by
the (separate, being-redesigned) custom-components#394/custom-components#395, plus the internal
implementation-plan doc.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant