fix(pkg/daemon): use measuredValue interface instead of different structs
This commit is contained in:
		| @@ -16,15 +16,11 @@ import ( | ||||
| ) | ||||
|  | ||||
| // Start the daemon | ||||
| func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compression bool, degree types.TemperatureUnit, round float64, logger logger.Logger) { | ||||
| func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compression bool, logger logger.Logger) { | ||||
|  | ||||
| 	// Info | ||||
| 	logger.Info("Use clean-cache-interval: %v", cleanCacheInterval.String()) | ||||
| 	logger.Info("Use compression: %v", compression) | ||||
| 	logger.Info("Round values: %v", round) | ||||
| 	logger.Info("Temperature unit: %v", degree) | ||||
|  | ||||
| 	temperatureLogfile := logfile.New(cnf.Device.TemperatureLogfile) | ||||
|  | ||||
| 	ticker := time.Tick(cleanCacheInterval) | ||||
|  | ||||
| @@ -32,16 +28,16 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress | ||||
| 	signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM) | ||||
|  | ||||
| 	errorChannel := make(chan error, 0) | ||||
| 	//humidityChannel := make(chan *types.Humidity, 0) | ||||
| 	temperatureChannel := make(chan *types.Temperature, 0) | ||||
| 	measuredValueChannel := make(chan types.MeasuredValue, 0) | ||||
|  | ||||
| 	ctx := context.Background() | ||||
| 	childContext, cancel := context.WithCancel(ctx) | ||||
|  | ||||
| 	// go sensor.ReadHumiditiesContinuously(cnf.GetHumiditySensors(config.ENABLED), humidityChannel, errorChannel) | ||||
| 	go sensor.ReadTemperaturesContinuously(childContext, cnf.GetTemperatureSensors(config.ENABLED), degree, round, temperatureChannel, errorChannel) | ||||
| 	logfile := logfile.New(cnf) | ||||
|  | ||||
| 	temperatureCache := make([]*types.Temperature, 0) | ||||
| 	measuredValuesCache := make([]types.MeasuredValue, 0) | ||||
|  | ||||
| 	go sensor.ReadContinuously(childContext, cnf.GetTemperatureSensors(config.ENABLED), measuredValueChannel, errorChannel) | ||||
|  | ||||
| 	rgbLEDs := cnf.GetRGBLEDs(config.ENABLED) | ||||
|  | ||||
| @@ -70,7 +66,7 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress | ||||
| 				logger.Error("Can not turn on blue info light: %v", err) | ||||
| 			} | ||||
|  | ||||
| 			err = logfile.AppendTemperatures(temperatureLogfile, compression, temperatureCache) | ||||
| 			err = logfile.Append(compression, measuredValuesCache) | ||||
| 			if err != nil { | ||||
|  | ||||
| 				err = rgbled.Error(rgbLEDs) | ||||
| @@ -81,10 +77,10 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress | ||||
| 				cancel() | ||||
| 				logger.Fatal("Can not save temperatures: %v", err) | ||||
| 			} | ||||
| 			temperatureCache = make([]*types.Temperature, 0) | ||||
| 			measuredValuesCache = make([]types.MeasuredValue, 0) | ||||
|  | ||||
| 		case temperature, _ := <-temperatureChannel: | ||||
| 			temperatureCache = append(temperatureCache, temperature) | ||||
| 		case measuredValue, _ := <-measuredValueChannel: | ||||
| 			measuredValuesCache = append(measuredValuesCache, measuredValue) | ||||
|  | ||||
| 		case killSignal := <-interrupt: | ||||
| 			logger.Warn("Daemon was interruped by system signal %v\n", killSignal) | ||||
| @@ -96,8 +92,8 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress | ||||
| 				logger.Error("Can not turn on red info light: %v", err) | ||||
| 			} | ||||
|  | ||||
| 			logger.Warn("Save remaining temperature data from the cache") | ||||
| 			err = logfile.AppendTemperatures(temperatureLogfile, compression, temperatureCache) | ||||
| 			logger.Warn("Save remaining data from the cache: %v", len(measuredValuesCache)) | ||||
| 			err = logfile.Append(compression, measuredValuesCache) | ||||
| 			if err != nil { | ||||
| 				logger.Fatal("%v", err) | ||||
| 			} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user