Add typed value getters to States container#2114
Open
iMicknl wants to merge 1 commit into
Open
Conversation
efae7d3 to
6b13f6b
Compare
Add get_value_as_* and first_value_as_* methods to the States container that delegate to the existing State.value_as_* properties, returning None when the state is missing and propagating TypeError on type mismatch. Closes #2113
6b13f6b to
c3bd8fe
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds typed value getter helpers to the States container to improve ergonomics for consumers that need concrete types without repeated casts/guards, while preserving the existing State.value_as_* mismatch semantics (i.e., TypeError on wrong-typed states; None only for missing/none-typed values).
Changes:
- Add
States.get_value_as_{int,float,bool,str,dict,list}()pass-through helpers. - Add
States.first_value_as_{int,float,bool,str,dict,list}()helpers for fallback-chain lookups. - Add unit tests and documentation examples covering the new typed accessors (including enum keys, missing states, and mismatch behavior).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyoverkiz/models.py |
Adds the new typed getter methods on States, delegating to State.value_as_*. |
tests/test_models.py |
Adds coverage for typed getters (hit/miss/NONE/type-mismatch/enum keys/dict+list). |
docs/device-control.md |
Documents usage examples for typed getters and typed fallback chains. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Resolves #2113. Follows on from #2108.
States.get_value()/first_value()return the untypedStateTypeunion, so consumers needing a concrete type have to cast or do aget()+None-guard +value_as_*two-step (~52cast(...)sites in the Home Assistantoverkizmigration).This adds thin pass-throughs on
Statesthat delegate to the existingState.value_as_*properties:Six
get_value_as_*(single key) + sixfirst_value_as_*(fallback chain), one perState.value_as_*(int, float, bool, str, dict, list). Missing state →None; wrong type →TypeErrorpropagates.