fix: daemon load sensors from repo instead config

This commit is contained in:
Markus Pesch 2020-05-21 20:34:38 +02:00
parent d0e238e64a
commit 11717679bc
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -16,19 +16,6 @@ import (
func Start(cnf *config.Config, flogger logger.Logger) error { func Start(cnf *config.Config, flogger logger.Logger) error {
sensors := make([]sensor.Sensor, 0)
for _, cnfSensor := range cnf.Sensors {
if !cnfSensor.Enabled {
continue
}
sensor, err := sensor.New(cnfSensor)
if err != nil {
return err
}
sensors = append(sensors, sensor)
}
measuredValueChannel := make(chan *types.MeasuredValue, 0) measuredValueChannel := make(chan *types.MeasuredValue, 0)
// load storage endpoint // load storage endpoint
@ -42,30 +29,29 @@ func Start(cnf *config.Config, flogger logger.Logger) error {
return err return err
} }
repoSensors, err := repo.GetSensors()
if err != nil {
return err
}
sensors := make([]sensor.Sensor, 0)
for _, repoSensor := range repoSensors {
if !repoSensor.Enabled {
continue
}
sensor, err := sensor.New(repoSensor)
if err != nil {
return err
}
sensors = append(sensors, sensor)
}
interruptChannel := make(chan os.Signal, 1) interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, os.Kill, syscall.SIGTERM) signal.Notify(interruptChannel, os.Kill, syscall.SIGTERM)
// Collection // Collection
parentCtx := context.Background() parentCtx := context.Background()
// Insert device if not exist
device, _ := repo.GetDevice(cnf.Device.ID)
if device == nil {
if err := repo.AddDevices(cnf.Device); err != nil {
return err
}
}
// Insert sensors if not exist
for _, cnfSensor := range cnf.Sensors {
sensor, _ := repo.GetSensor(cnfSensor.ID)
if sensor == nil {
if err := repo.AddSensors(cnfSensor); err != nil {
return err
}
}
}
ctx, cancel := context.WithCancel(parentCtx) ctx, cancel := context.WithCancel(parentCtx)
for _, s := range sensors { for _, s := range sensors {