Skip to content

Sync upstream master (incl. #407 ruff CI fix) - #7

Merged
rhammen merged 4 commits into
masterfrom
sync-upstream-407
Jul 24, 2026
Merged

Sync upstream master (incl. #407 ruff CI fix)#7
rhammen merged 4 commits into
masterfrom
sync-upstream-407

Conversation

@rhammen

@rhammen rhammen commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Pulls in upstream/master, which now includes:

Also includes a follow-up commit fixing the one lint error (D209, docstring closing-quote placement) that custom-components#407's new unrestricted check surfaces in api.py - everything else was already clean from the earlier ruff-cleanup PR.

Verified locally: ruff format --diff clean, ruff check (new unrestricted form) clean, full test suite 231 passed / 2 skipped.

rhammen and others added 4 commits July 24, 2026 13:07
* Add offline unit tests for the Zaptec API client

api.py previously had only a single integration test that requires live
login, leaving the core logic effectively uncovered offline. This adds a
fake aiohttp ClientSession and exercises the pure logic and request
machinery without credentials or network:

- request() status handling: 200 JSON, 204 bytes, invalid JSON, error
  status codes, 500 GET retry-to-exhaustion vs 500 POST immediate raise,
  401 -> token refresh -> retry
- _request_worker retry/backoff: connection errors and timeouts retried
  then surfaced as RequestConnectionError / RequestTimeoutError
- state_to_attrs: keydict mapping, Value/ValueAsString precedence, missing
  key/value skipping, excludes, duplicate-last-wins
- set_attributes: ATTR_TYPES conversion, snake_case keys, conversion-failure
  fallback, update-in-place
- is_command_valid: all resume/stop branches (incl. a characterization test
  for the int(None) issue flagged for the Phase 3 correctness cleanup)
- stream_update routing: matching charger, unknown/missing/zero-guid ids
- Zaptec mapping + poll dispatch: register/contains/qual_id, poll dispatch
  and unknown-object error

Tests are self-contained (no live-constants fixture) so they run under
SKIP_ZAPTEC_API_TEST and in CI. Lint-clean under the repo's ruff config.

* Extend api.py offline tests to the command/poll/lifecycle wrappers

Follows up the initial offline suite with the cheap, high-value cases,
raising api.py statement coverage from ~50% to ~66%:

- command(): named id, numeric id, authorize_charge alias, unknown-command
  error
- charger settings wrappers: set_settings (valid + unknown-key), authorize_
  charge, set_permanent_cable_lock, set_hmi_brightness (URL + payload)
- installation current setters: set_limit_current (availableCurrent,
  missing-arg, partial-phase, out-of-range) and
  set_three_to_one_phase_switch_current (valid + out-of-range)
- Charger.poll_info (happy, 403 -> charger-list fallback, non-403 re-raise)
  and poll_state (happy, 403 ignored)
- Installation.poll_info SupportGroup logo stripping
- login()/_refresh_token: token stored and sent on later requests; 400 ->
  AuthenticationError
- small accessors/lifecycle: is_charging, model/model_prefix, Zaptec
  objects/installations/chargers/iter/len, async context manager

Payload validation is bypassed in the poll tests (it has its own test
module). build()/streaming/poll_firmware remain uncovered and are better
tested alongside the Phase 2 typed-model work.

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
…ts#407)

* Use requirements.txt for ruff version in ci-pipeline
* Remove ruff workaround for api.py
# Conflicts:
#	tests/zaptec/test_api.py
Surfaced by upstream custom-components#407's new unrestricted `ruff check` CI gate
(previously excluded api.py and ran --exit-zero).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@rhammen
rhammen merged commit 7c8a547 into master Jul 24, 2026
5 of 6 checks passed
@rhammen
rhammen deleted the sync-upstream-407 branch July 24, 2026 17:10
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.

2 participants