go-meteologix/humidity.go

49 lines
1.1 KiB
Go
Raw Permalink Normal View History

// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
//
// SPDX-License-Identifier: MIT
package meteologix
import (
"fmt"
"math"
"time"
)
// Humidity is a type wrapper of an WeatherData for holding humidity
// values in WeatherData
type Humidity WeatherData
// IsAvailable returns true if an Humidity value was
// available at time of query
2023-05-23 20:00:42 +02:00
func (h Humidity) IsAvailable() bool {
return !h.na
}
// DateTime returns the timestamp of when the humidity
// measurement was taken.
2023-05-23 20:00:42 +02:00
func (h Humidity) DateTime() time.Time {
return h.dt
}
// String satisfies the fmt.Stringer interface for the Humidity type
2023-05-23 20:00:42 +02:00
func (h Humidity) String() string {
return fmt.Sprintf("%.1f%%", h.fv)
2023-05-23 20:00:42 +02:00
}
// Source returns the Source of Humidity
// If the Source is not available it will return SourceUnknown
func (h Humidity) Source() Source {
return h.s
}
// Value returns the float64 value of an Humidity
// If the Humidity is not available in the WeatherData
// Value will return math.NaN instead.
2023-05-23 20:00:42 +02:00
func (h Humidity) Value() float64 {
if h.na {
return math.NaN()
}
return h.fv
}