Skip to content

Add typed value getters to States container#2114

Open
iMicknl wants to merge 1 commit into
mainfrom
feat/typed-state-getters
Open

Add typed value getters to States container#2114
iMicknl wants to merge 1 commit into
mainfrom
feat/typed-state-getters

Conversation

@iMicknl
Copy link
Copy Markdown
Owner

@iMicknl iMicknl commented Jun 1, 2026

Resolves #2113. Follows on from #2108.

States.get_value() / first_value() return the untyped StateType union, so consumers needing a concrete type have to cast or do a get() + None-guard + value_as_* two-step (~52 cast(...) sites in the Home Assistant overkiz migration).

This adds thin pass-throughs on States that delegate to the existing State.value_as_* properties:

temperature = device.states.get_value_as_float(OverkizState.CORE_TEMPERATURE)  # float | None

orientation = device.states.first_value_as_int(
    [OverkizState.CORE_SLATS_ORIENTATION, OverkizState.CORE_SLATE_ORIENTATION]
)  # int | None

Six get_value_as_* (single key) + six first_value_as_* (fallback chain), one per State.value_as_* (int, float, bool, str, dict, list). Missing state → None; wrong type → TypeError propagates.

@iMicknl iMicknl force-pushed the feat/typed-state-getters branch from efae7d3 to 6b13f6b Compare June 1, 2026 21:06
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
@iMicknl iMicknl force-pushed the feat/typed-state-getters branch from 6b13f6b to c3bd8fe Compare June 4, 2026 15:13
@iMicknl iMicknl marked this pull request as ready for review June 4, 2026 15:20
@iMicknl iMicknl requested a review from tetienne as a code owner June 4, 2026 15:20
Copilot AI review requested due to automatic review settings June 4, 2026 15:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add typed value getters to States container (get_value_as_*/first_value_as_*)

2 participants