PKGBUILD/pkg/sensor/sensor.go

41 lines
690 B
Go
Raw Normal View History

package sensor
2019-02-24 21:46:36 +00:00
import (
"errors"
"sync"
2020-06-10 19:13:05 +00:00
"git.cryptic.systems/volker.raschek/flucky/pkg/types"
2019-02-24 21:46:36 +00:00
)
var (
ErrSensorModelNotMatched = errors.New("Sensor model not matched")
)
// New returns a new sensor
func New(sensor *types.Sensor) (Sensor, error) {
switch sensor.Model {
case "BME280":
return &BME280{
Sensor: sensor,
mutex: new(sync.Mutex),
}, nil
case "DHT11":
return &DHT11{
Sensor: sensor,
mutex: new(sync.Mutex),
}, nil
case "DHT22":
return &DHT22{
Sensor: sensor,
mutex: new(sync.Mutex),
}, nil
case "DS18B20":
return &DS18B20{
Sensor: sensor,
mutex: new(sync.Mutex),
}, nil
default:
return nil, ErrSensorModelNotMatched
2019-02-24 21:46:36 +00:00
}
}