fix: daemon load sensors from repo instead config
This commit is contained in:
		| @@ -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 { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user