Skip to content

Handle incomplete SensorPush records without losing healthy readings - #4

Open
econstantin wants to merge 1 commit into
sstallion:masterfrom
econstantin:codex/incomplete-record-handling
Open

econstantin wants to merge 1 commit into
sstallion:masterfrom
econstantin:codex/incomplete-record-handling

Conversation

@econstantin

@econstantin econstantin commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Context

PR #1 handles missing and empty sample lists. This draft proposes a small defensive follow-up for three other incomplete-response cases.

sensorpush-api 2.1.3 accepts missing Sensor.name, Sample.observed, and Samples.sensors fields as None, while the helper assumes they are present. A few explicit checks can handle those inputs without discarding healthy readings or hiding an invalid whole response. Whether this protection is useful given the service's actual behavior is open for maintainer feedback.

Repro steps

Mock the endpoint results and call SensorPushCloudHelper.async_get_data() with:

  1. A sensor with a device ID, type, and valid sample, but no name.
  2. A sample without observed, alongside a healthy sensor.
  3. Samples() without a sensors mapping, with populated or empty sensor metadata.

Expected

Incomplete records should not block usable readings. An invalid whole response should raise a library error.

Actual

A missing name or observation timestamp raises a validation error and aborts the account update. A missing samples mapping raises AttributeError when sensor metadata is present, or silently returns an empty update when it is empty.

Fix

Use the device ID as the fallback name, skip samples without observation timestamps, and raise SensorPushCloudError for a missing samples mapping. Never substitute the current time. Preserve PR #1's missing/empty-sample behavior and API error propagation.

Testing

  • Reproduced the failures before applying the fix.
  • All six helper tests pass on Python 3.12.13 and 3.13.12, covering the cases above, recovery on a later update, and existing missing/empty-sample and API-error behavior.
  • Source distribution and wheel builds, dependency checks, and git diff --check pass.

Notes

Only mocked responses were used, without credentials or live SensorPush/HA requests. Builds emit the existing license-classifier deprecation warning.

@econstantin
econstantin marked this pull request as ready for review October 23, 2026 06:03
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.

1 participant