Skip to content

Commit

Permalink
chore: Validate temperature data on read
Browse files Browse the repository at this point in the history
  • Loading branch information
yryz committed May 27, 2020
1 parent 3cf383a commit 448a8e7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ds18b20.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func Temperature(sensor string) (float64, error) {

raw := string(data)

if !strings.Contains(raw, " YES") {
return 0.0, ErrReadSensor
}

i := strings.LastIndex(raw, "t=")
if i == -1 {
return 0.0, ErrReadSensor
Expand Down

0 comments on commit 448a8e7

Please sign in to comment.