feat(public-api): add typed alarm hub accessors to LinkStation#894
Conversation
Expose the well-formed alarmHub payload slice (armed, battery, cover, input, output) via read-only typed accessors on LinkStation. Field shapes and the AlarmHubInputType enum members are taken from the alarmHubStatus OpenAPI sub-schema. The opaque alarm_hub dict is retained so electrical sub-sections (connector, *MeterStatus, *TerminalStatus, buckboost) and unmodeled/future keys survive untouched.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR adds typed read-only accessors to LinkStation that expose the alarm-hub payload as structured models. It defines a new AlarmHubInputType enum and four sub-models (Battery, Cover, Input, Output), adds five accessor properties to LinkStation that safely re-derive these from the stored opaque dict, exports them from the public API, and validates the implementation with fixtures and comprehensive tests. ChangesAlarm Hub Typed Accessors on LinkStation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR extends the public LinkStation model to expose a typed, read-only view of the well-structured alarmHub payload (armed, battery, cover, input, output) while preserving the original opaque alarm_hub dict for electrical/unmodeled sections and future keys.
Changes:
- Added
AlarmHubInputType(UnknownValuesEnumMixin) for typedalarmHub.input[*].inputTypehandling with unknown-value fallback. - Introduced
AlarmHubBattery,AlarmHubCover,AlarmHubInput, andAlarmHubOutputsub-models plusLinkStationaccessors that re-derive typed views from the raw dict on each access. - Added fixture-backed tests covering typed accessors, unknown enum fallback, integer-key filtering, and raw dict preservation of unmodeled keys.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_api_linkstation_public.py | Adds public-API tests validating typed alarm-hub accessors and raw dict preservation behavior. |
| tests/sample_data/sample_link_station_alarm_hub.json | Adds an alarm-hub sample payload fixture (including unmodeled electrical sections) used by the new tests. |
| src/uiprotect/data/types.py | Adds AlarmHubInputType enum with unknown-value fallback support. |
| src/uiprotect/data/public_devices.py | Adds alarm-hub sub-models and LinkStation typed accessor properties while keeping alarm_hub opaque. |
| src/uiprotect/data/init.py | Re-exports the new alarm-hub types and enum from uiprotect.data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
Exposes the well-formed slice of the
alarmHubpayload (armed,battery,cover,input,output) onLinkStationvia read-only typed accessors. Field shapes and theAlarmHubInputTypeenum members are derived from thealarmHubStatusOpenAPI sub-schema (matching the approach used by the rest of the public-API typing work in #881–#885). The opaquealarm_hubdict is retained verbatim so the electrical sub-sections (connector,*MeterStatus,*TerminalStatus,buckboost) — whose keys aren't valid Python identifiers and which the spec itself models asadditionalPropertiesmaps — survive untouched alongside any unmodeled/future top-level keys.Closes #893
Changes
AlarmHubInputTypeenum (UnknownValuesEnumMixin) with the full spec set (MOTION,ENTRY,SMOKE,GLASS_BREAK,EMERGENCY_BUTTON,UNKNOWN).ProtectBaseObjectsub-models matching thealarmHubStatussub-schemas:AlarmHubBattery,AlarmHubCover,AlarmHubInput,AlarmHubOutput.LinkStation:alarm_hub_armed,alarm_hub_battery,alarm_hub_cover,alarm_hub_inputs,alarm_hub_outputs. Each re-derives from the stored dict on every access so it stays live against WS updates; non-integer keys ininput/outputmaps are silently skipped.uiprotect.data.Test plan
tests/test_api_linkstation_public.pydriven bytests/sample_data/sample_link_station_alarm_hub.jsoncovers: armed wire flag; typed battery/cover; int-keyed inputs/outputs with non-numeric keys skipped; configured vs. unconfigured zones; a camera-linked zone; an unknowninputTypevalue falling back toAlarmHubInputType.UNKNOWN; round-trip preservation of unmodeled keys (buckboost,connector,currentMeterStatus); andNone/{}returns for a non-alarm-hubLinkStationand for an emptyalarmHubsection.poetry run pytest— 1428 passed.poetry run .bin/run-mypy— clean against the touched files (5 pre-existing errors insrc/uiprotect/cli/backup.pyreproduce onmainand are unrelated to this change).Generated by Kōan
Quality Report
Changes: 5 files changed, 379 insertions(+), 3 deletions(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline
Summary by CodeRabbit