OpenDevicePartnership / OpenDevicePartnership/embedded-sensors

f32 sample/threshold domain is unconstrained and ErrorKind::InvalidInput is undocumented

Open
#56 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation enhancement
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 / inf mean as a sample or as a threshold argument.
  • Whether Percentage is expected to be within 0.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:

  1. Document implementer obligations on ThresholdSet / Hysteresis: e.g. "Implementations MUST return ErrorKind::InvalidInput if threshold is not finite, or if setting it would make low > high."
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.