Fix ruff lint errors in api.py - #390
Merged
Merged
Conversation
Resolve all 36 ruff check errors (down from 36 to 0) in the vendored Zaptec API client: - Add missing return-type and argument annotations (ANN001/003/201/204/205) - Replace mutable default arg for `excludes` with the None-default pattern (B006) - Move the "stream already running" precondition raise out of the try (TRY301) - Bind loop-captured log messages as an immutable default arg (B023) - Reword a stale FIXME comment to NOTE (TD001/002/003, FIX001) - Remove commented-out debug lines (ERA001) - Drop redundant exception args from logging.exception calls (TRY401) - Remove unnecessary AsyncGenerator None type arg (UP043) Also fix two pre-existing latent type issues: - Initialize operation_mode/final_stop_active so they are not possibly unbound in is_command_valid's debug log (reportPossiblyUnbound) - Widen ZaptecBase.__contains__ key param to object for a compatible Mapping override (reportIncompatibleMethodOverride) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sveinse
approved these changes
Jul 8, 2026
sveinse
left a comment
Collaborator
There was a problem hiding this comment.
I think this looks great.
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
Resolves all 36
ruff checkerrors in the vendored Zaptec API client (custom_components/zaptec/zaptec/api.py), taking that file from 36 → 0. This chips away at the non-cleanruff checkbaseline tracked in #258 (CI currently runsruff checkwith--exit-zero).Almost entirely annotations, comment/logging tidy-ups, and two safe latent-type fixes. See the Behavior note below for the one edge case that is not purely cosmetic.
Lint fixes
ANN001/003/201/204/205)excludeswith theNone-default pattern (B006)raiseout of thetry(TRY301)B023)FIXMEcomment toNOTE(TD001/002/003,FIX001)ERA001)logging.exception(...)calls (TRY401)AsyncGeneratorNonetype arg (UP043)Two safe latent-type fixes (surfaced while annotating)
operation_mode/final_stop_activeso they aren't possibly-unbound inis_command_valid's debug logZaptec.__contains__key param toobjectfor a compatibleMappingoverrideThe
TRY301fix moves the "stream already running" preconditionraise RuntimeError(...)from insidestream_main'stryto before it. Previously that error was caught by the method's ownexcept Exception(logged as "Stream failed", and thefinallyreset_stream_running); now it propagates to the caller instead. This guard is only hit ifstream_mainis invoked while a stream is already running — which shouldn't happen in normal use (stream()callscancel_stream()first, and the manager starts one background task per installation) — and no test exercises it. Arguably more correct (a programming-error guard shouldn't be swallowed by the stream's own handler, and it no longer clobbers a live stream's_stream_runningflag), but calling it out since it's the one non-cosmetic change. Happy to use a# noqa: TRY301instead if maintainers prefer to keep the old swallow-and-log behavior.Verification
ruff check custom_components tests— passes (api.py now 0 errors)ruff format --diff— cleanFollow-up (separate PRs)
This is deliberately scoped to lint-only. I'd like to follow up with staged PRs to raise
api.pyto high-quality code:state_to_attrs,is_command_valid,stream_update, hierarchy parsing) — currently the only api test requires live login.Mappingcovariance, typed accessors to removeZaptecBase→Charger/Installationdowncasts.Anyon API payloads.command()variable reuse +int(final_stop_active)guard, explicit kwargs forset_limit_current, instance-scoped debug flags.Happy to split/reorder these however maintainers prefer.
🤖 Generated with Claude Code