feat(data): add Sensor *_public convenience setters#1010
Conversation
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
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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:
|
|
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:
|
Description of change
Adds dedicated public-API convenience setters to the
Sensormodel, mirroringthe existing
Camera/Light/Chimepattern. Previously a consumer wantingto 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 nestedpayload for the fields the public
PATCH /v1/sensors/{id}exposes (its typed*_settingsshapes):set_name_public(name)set_motion_status_public,set_motion_sensitivity_publicset_temperature_status_public,set_temperature_safe_range_publicset_humidity_status_public,set_humidity_safe_range_publicset_light_status_public,set_light_safe_range_publicset_alarm_status_publicAdditive 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*_publicsetters onSensor,wrapping
update_sensor_public; range setters reuse the same validationbounds as the private counterparts;
set_motion_sensitivity_publicvalidatesvia
model_copy+ assignment soPercentIntbounds are enforced before therequest.
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 passedruff checkandmypy src/uiprotect/data/devices.pycleanQuality Report
Changes: 2 files changed, 286 insertions(+)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan