Skip to content

feat(data): add Sensor *_public convenience setters#1010

Closed
bluetoothbot wants to merge 2 commits into
uilibs:mainfrom
bluetoothbot:koan/fix-issue-1009
Closed

feat(data): add Sensor *_public convenience setters#1010
bluetoothbot wants to merge 2 commits into
uilibs:mainfrom
bluetoothbot:koan/fix-issue-1009

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Description of change

Adds dedicated public-API convenience setters to the Sensor model, mirroring
the existing Camera / Light / Chime pattern. Previously a consumer wanting
to change a sensor setting over the public API had to hand-build the nested
settings dict and call the raw ProtectApiClient.update_sensor_public(...).

Each new setter just wraps update_sensor_public(...) with the correct nested
payload for the fields the public PATCH /v1/sensors/{id} exposes (its typed
*_settings shapes):

  • set_name_public(name)
  • motion: set_motion_status_public, set_motion_sensitivity_public
  • temperature: set_temperature_status_public, set_temperature_safe_range_public
  • humidity: set_humidity_status_public, set_humidity_safe_range_public
  • light: set_light_status_public, set_light_safe_range_public
  • alarm: set_alarm_status_public

Additive and non-breaking. A sensor status-light setter is intentionally not
added — the public sensor PATCH schema exposes no LED field.

Closes #1009

Changes

  • src/uiprotect/data/devices.py: ten *_public setters on Sensor,
    wrapping update_sensor_public; range setters reuse the same validation
    bounds as the private counterparts; set_motion_sensitivity_public validates
    via model_copy + assignment so PercentInt bounds are enforced before the
    request.
  • tests/data/test_sensor.py: full coverage incl. validation-error paths.

Test plan

  • poetry run pytest tests/data/test_sensor.py tests/test_api_public.py — 310 passed
  • ruff check and mypy src/uiprotect/data/devices.py clean

Quality Report

Changes: 2 files changed, 286 insertions(+)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan

bluetoothbot and others added 2 commits June 18, 2026 20:12
Mirror the existing Camera/Light public-API helper pattern on Sensor:
name, motion (status + sensitivity), temperature/humidity/light
(status + safe range), and alarm status. Each wraps
update_sensor_public with the correct nested payload.

Closes uilibs#1009
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 699f07b5-7dac-4e48-958d-87262b902251

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@codspeed-hq

codspeed-hq Bot commented Jun 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 4 untouched benchmarks


Comparing bluetoothbot:koan/fix-issue-1009 (2d20bbb) with main (d336fdd)

Open in CodSpeed

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/uiprotect/data/devices.py 89.09% <100.00%> (+0.26%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RaHehl

RaHehl commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Closing for now — we will redo this alongside the HA core migration that actually consumes these setters, so we build exactly what core needs with correct, spec-derived validation.

Review findings to carry over to the redo:

  • Validation bounds are wrong for the public contract. They were copied from the private setters and contradict the OpenAPI spec for PATCH /v1/sensors/{id}: temperature lowThreshold is -39…124 (not 0…45 °C) and light lowThreshold is 1…503192 (not 1…1000 lux). humidity (1…99) and motion sensitivity (0…100) happen to match. Public setters must derive bounds from the spec, not the private/UI limits.
  • Partial updates are correct. The spec makes the body and every *_settings object fully optional (additionalProperties: false, no required), so the partial-dict approach here is right — keep it. Whole-object PATCH (the Light/Camera style) would over-send against the spec.
  • alarm vs glass-break mapping needs clarifying. set_alarm_status_public maps to alarmSettings, but the spec also exposes a separate top-level glassBreakSettings.
  • Align with the established public-setter pattern: validate via the model, take the update lock, and apply local state from the response.

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.

Add Sensor *_public convenience setters

2 participants