fix: small quirks surfaced while writing the test suite#493
Merged
Conversation
Three independent issues observed during the test-suite PR (#484): - Nodes.parse() called the async ``Node.update(xmldoc=...)`` from a synchronous parsing loop without awaiting, so the returned coroutine was silently dropped and the re-parse path never updated the node's state. Inline the work (apply ``last_update``, aux-property merge, and ``update_state``) directly in the sync parser. - NodeIterator implemented ``__next__`` and ``__len__`` but no ``__iter__``, so ``for x in iter(nodes)`` and ``for x in reversed(nodes)`` raised ``TypeError`` because Python's ``for`` protocol calls ``iter()`` on the iterable, which requires ``__iter__`` to exist on the iterator itself. Add the conventional ``__iter__`` returning ``self``. - Programs.__getitem__ raised ``KeyError`` on an unrecognized key (one that wasn't an address, name, or int-convertible index) even though the rest of the method's miss paths return ``None`` through the inner ``try`` and the signature is ``-> ... | None``. Return ``None`` for that branch too so behavior is consistent across all miss cases. Co-Authored-By: Claude Opus 4.7 <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.
Three independent issues observed while building out the offline pytest suite (#484), grouped here because each is one or two lines and none warrants its own ticket.
1.
Nodes.parse()re-update path silently droppedpyisy/nodes/__init__.pyline 415 (pre-fix) called the asyncNode.update(xmldoc=feature)from a synchronous parsing loop withoutawait. The returned coroutine was never run, so whenparse()re-encountered an existing address (the re-update branch) the node's status was never refreshed from the new XML. The test suite caught this asRuntimeWarning: coroutine 'Node.update' was never awaited.Fix inlines the synchronous portion of
Node.update(xmldoc=...)directly in the parser: capturelast_update, mergeaux_properties, and callupdate_state(state). No new public method onNode; the asyncNode.updateis unchanged for its other callers.2.
NodeIteratormissing__iter__NodeIteratorimplemented__next__and__len__but not__iter__. Python'sforprotocol callsiter()on the iterable, which requires__iter__on the iterator object itself — without it,for x in iter(nodes)andfor x in reversed(nodes)raiseTypeError. Added the conventional__iter__returningself.Programsreuses the same iterator class (aliased asProgramIterator), so this fix covers both managers.3.
Programs.__getitem__raisedKeyErroron unrecognized keysThe inner
tryaroundfun(val)returnsNoneonKeyError/IndexError/ValueError, and the signature is-> Program | Folder | None— but the path wherevalisn't an address, isn't a known name, and can't beint()-converted raisedKeyError("Unrecognized Key: ...")instead of returningNone. Inconsistent with the other miss paths.Fix returns
Nonefrom that branch too, matching the rest of the method.Test plan
Regression coverage lands in PR #484 (the test-suite PR), which already has the failing-warning case for #1 and tightens the Programs miss assertions for #3. No new tests in this PR — the fixes are small enough to review on their own.
HA Core impact
None.
homeassistant/components/isy994/doesn't iterateNodeIteratordirectly, doesn't callPrograms.__getitem__("missing-key")with the expectation of aKeyError, and the dropped re-parse manifested as a stale cache the existing event-stream handlers immediately re-corrected.