PKGBUILD/pkg/sensor/ds18b20.go
Markus Pesch 5220eac16b
fix: breaking changes
changes:
- remove remote operations
- add function to write measured values into a channel
- add get humidity sensors from config
- add get temperature sensors from config
- remove FileLogger
- exclude some functions from pkf into internal
2019-06-13 22:15:48 +02:00

45 lines
981 B
Go

package sensor
import (
"fmt"
"time"
uuid "github.com/satori/go.uuid"
"github.com/volker-raschek/flucky/pkg/types"
"github.com/yryz/ds18b20"
)
// DS18B20 is a sensor to measure humidity and temperature.
type DS18B20 struct {
*types.Sensor
}
// GetSensorModel returns the sensor model
func (s *DS18B20) GetSensorModel() types.SensorModel {
return s.Sensor.SensorModel
}
// GetSensor return the sensor struct
func (s *DS18B20) GetSensor() *types.Sensor {
return s.Sensor
}
// ReadTemperature measure the temperature
func (s *DS18B20) ReadTemperature() (*types.Temperature, error) {
t, err := ds18b20.Temperature(*s.WireID)
if err != nil {
return nil, fmt.Errorf("Can not read from Sensor %v (UUID: %v, Wire-ID: %v): %v", s.SensorName, s.SensorID, s.WireID, err)
}
temperature := &types.Temperature{
TemperatureID: uuid.NewV4().String(),
TemperatureValue: t,
TemperatureDate: time.Now(),
SensorID: s.SensorID,
}
return temperature, nil
}