test: add entity test coverage for sensor/switch/number/button/binary_sensor/update platforms - #395
Draft
rhammen wants to merge 18 commits into
Draft
Conversation
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.
…n chaining, dead code, docstrings)
…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>
This was referenced Jul 12, 2026
Add per-charger energy statistics feed to fix Energy Dashboard hour-misattribution (fixes #300)
#396
Closed
…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
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>
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.
Summary
sensor.py,switch.py,number.py,button.py,binary_sensor.py,update.py._post_initoverrides,availableoverrides, async command methods with success/HomeAssistantError-failure paths) usingMagicMock(spec=Charger)/MagicMock(spec=Installation)test doubles so a typo'd method name fails loudly instead of silently returning a fresh mock.hass/config_entryfixtures andcoordinator.py/entity.pycoverage this branch builds on).services.pytest coverage plus a realservices.yamlbugfix (documented service key wasupdate_firmware, actual registered service isupgrade_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 intest_zconst.py/test_redact.py, documented inCLAUDE.md, unrelated to this change)ruff format --diff/ruff checkclean on all new files🤖 Generated with Claude Code