Markus Pesch
fb8d4dd5eb
changes: - Remove cli Some cli commands are not complete tested and are deprecated. - Daemon - Old version has a very bad implementation of how to verify, if the device or the sensors are in the database insert. The current implementation can be improved but this one is betten then the old one. - Remove complete the cache store implementation. Use a normal array and query the length and capacity to determine how the array cache must be cleaned. - Type Remove unused types and functions
41 lines
681 B
Go
41 lines
681 B
Go
package sensor
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/types"
|
|
)
|
|
|
|
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
|
|
}
|
|
}
|