Skip to content

fix: map unrecognized enum values to a known "unknown" member - #3

Merged
Lash-L merged 1 commit into
mainfrom
fix/enum-unknown-fallback
Jul 9, 2026
Merged

fix: map unrecognized enum values to a known "unknown" member#3
Lash-L merged 1 commit into
mainfrom
fix/enum-unknown-fallback

Conversation

@Lash-L

@Lash-L Lash-L commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Enumerated state fields (speaker_state, stream_quality) previously stored any unrecognized device value verbatim (lowercased), so consumers that declare fixed options up front could receive an out-of-set value. Because _set_state_value skips None, returning None would have left a stale prior value in place, so unrecognized values are now mapped to the in-set "unknown" member instead. A stored enum value is therefore always a member of its set (or None only when the device omitted the field), and consumers no longer need to clamp the value themselves.

Summary by CodeRabbit

  • Bug Fixes
    • Device settings with unexpected enum values now show as “unknown” instead of being passed through.
    • Known values continue to be handled normally, and empty or missing fields remain unset.
    • If a device later reports an invalid value for a field that previously had a valid one, the value is now replaced with “unknown”.
    • Warnings for unexpected values are still logged once per unique case.

Enumerated state fields (speaker_state, stream_quality) previously stored
any unrecognized device value verbatim (lowercased), so consumers that
declare fixed options up front could receive an out-of-set value. Because
_set_state_value skips None, returning None would have left a stale prior
value in place, so unrecognized values are now mapped to the in-set
"unknown" member instead. A stored enum value is therefore always a member
of its set (or None only when the device omitted the field), and consumers
no longer need to clamp the value themselves.
@Lash-L
Lash-L requested a review from afgarcia86 July 7, 2026 11:42
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Free

Run ID: 80f32af0-48e7-4ff1-8479-c53410d7aa4b

📥 Commits

Reviewing files that changed from the base of the PR and between 39a9ce3 and 9d82882.

📒 Files selected for processing (2)
  • harbor/devices/camera.py
  • tests/test_camera_state.py

📝 Walkthrough

Walkthrough

Adds a module-level UNKNOWN_ENUM_VALUE constant to harbor/devices/camera.py and refactors _normalize_enum_value to map unexpected, non-empty enum values to this constant with deduplicated warning logging. Updates corresponding tests to verify the new mapping behavior instead of prior passthrough behavior.

Changes

Unknown enum value handling

Layer / File(s) Summary
Constant and normalization logic
harbor/devices/camera.py
Adds UNKNOWN_ENUM_VALUE = "unknown" constant and refactors _normalize_enum_value to return this constant for unexpected non-empty enum values, with deduplicated per-field warning logging.
Test coverage for unknown enum mapping
tests/test_camera_state.py
Removes the outdated passthrough test and adds tests verifying unrecognized speaker_state/stream_quality values map to "unknown", including overwriting a prior valid stored value.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

Not applicable — the change is a localized normalization/logic refactor within a single module without multi-component interaction flows.

Poem

A rabbit hopped through fields of state,
Found values strange, mismatched, irate 🐇
"Unknown!" I cry, and log it once,
No stale old value gets a chance,
Clean enums now, my hop's elate! 🥕


Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

Comment @coderabbitai help to get the list of available commands.

@Lash-L
Lash-L merged commit ca61335 into main Jul 9, 2026
8 checks passed
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