OpenDevicePartnership / OpenDevicePartnership/embedded-sensors
f32 sample/threshold domain is unconstrained and ErrorKind::InvalidInput is undocumented
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 4
- Forks
- 9
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 3
Description
Problem
Sample and threshold values are bare f32 with no documented domain constraints. The trait contracts are silent about:
- What
NaN/infmean as a sample or as a threshold argument. - Whether
Percentageis expected to be within0.0..=100.0. - What happens when
threshold_low > threshold_high.
ErrorKind::InvalidInput exists ("The sensor was configured with invalid input") but no documentation anywhere tells an implementer when to return it, so in practice it is unreachable and generic code cannot rely on it.
Suggested fix
Pick one and be explicit:
- Document implementer obligations on
ThresholdSet/Hysteresis: e.g. "Implementations MUST returnErrorKind::InvalidInputifthresholdis not finite, or if setting it would make low > high." - Validate at construction via newtype constructors (see the newtype issue) so invalid values are unrepresentable.
Option 2 is cleaner but breaking; option 1 is non-breaking and can land immediately.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the ThresholdSet and Hysteresis trait contracts and the ErrorKind::InvalidInput definition. Decide between documenting implementer obligations and validating through newtype constructors, then make the chosen behavior explicit for NaN or infinity, Percentage bounds, and reversed thresholds. Done means generic code can determine when InvalidInput applies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- embedded-iot
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100