fix: breaking changes
changes: - remove remote operations - add function to write measured values into a channel - add get humidity sensors from config - add get temperature sensors from config - remove FileLogger - exclude some functions from pkf into internal
This commit is contained in:
16
pkg/internal/collect/errors.go
Normal file
16
pkg/internal/collect/errors.go
Normal file
@ -0,0 +1,16 @@
|
||||
package collect
|
||||
|
||||
func Errors(errorChannel <-chan error) []error {
|
||||
errorList := make([]error, 0)
|
||||
for {
|
||||
select {
|
||||
case err, more := <-errorChannel:
|
||||
if more {
|
||||
errorList = append(errorList, err)
|
||||
continue
|
||||
}
|
||||
default:
|
||||
return errorList
|
||||
}
|
||||
}
|
||||
}
|
20
pkg/internal/collect/humidity.go
Normal file
20
pkg/internal/collect/humidity.go
Normal file
@ -0,0 +1,20 @@
|
||||
package collect
|
||||
|
||||
import "github.com/volker-raschek/flucky/pkg/types"
|
||||
|
||||
func Humidities(humidityChannel <-chan *types.Humidity) []*types.Humidity {
|
||||
humidityList := make([]*types.Humidity, 0)
|
||||
|
||||
for {
|
||||
select {
|
||||
case hum, more := <-humidityChannel:
|
||||
if more {
|
||||
humidityList = append(humidityList, hum)
|
||||
continue
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return humidityList
|
||||
}
|
||||
}
|
||||
}
|
20
pkg/internal/collect/temperatures.go
Normal file
20
pkg/internal/collect/temperatures.go
Normal file
@ -0,0 +1,20 @@
|
||||
package collect
|
||||
|
||||
import (
|
||||
"github.com/volker-raschek/flucky/pkg/types"
|
||||
)
|
||||
|
||||
func Temperatures(temperatureChannel <-chan *types.Temperature) []*types.Temperature {
|
||||
temperatureList := make([]*types.Temperature, 0)
|
||||
for {
|
||||
select {
|
||||
case temperature, more := <-temperatureChannel:
|
||||
if more {
|
||||
temperatureList = append(temperatureList, temperature)
|
||||
continue
|
||||
}
|
||||
default:
|
||||
return temperatureList
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package errutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func CollectErrors(errChan <-chan error) []error {
|
||||
errorList := make([]error, 0)
|
||||
for {
|
||||
select {
|
||||
case err, more := <-errChan:
|
||||
if more {
|
||||
errorList = append(errorList, err)
|
||||
continue
|
||||
}
|
||||
default:
|
||||
return errorList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FormatErrors(errorList []error) error {
|
||||
if len(errorList) > 0 {
|
||||
errMsg := ""
|
||||
for _, err := range errorList {
|
||||
errMsg = fmt.Sprintf("%v\n%v", errMsg, err.Error())
|
||||
}
|
||||
return fmt.Errorf(errMsg)
|
||||
}
|
||||
return nil
|
||||
}
|
14
pkg/internal/prittyprint/prittyprint.go
Normal file
14
pkg/internal/prittyprint/prittyprint.go
Normal file
@ -0,0 +1,14 @@
|
||||
package prittyprint
|
||||
|
||||
import "fmt"
|
||||
|
||||
func FormatErrors(errors []error) error {
|
||||
if len(errors) > 0 {
|
||||
errMsg := ""
|
||||
for _, err := range errors {
|
||||
errMsg = fmt.Sprintf("%v\n%v", errMsg, err.Error())
|
||||
}
|
||||
return fmt.Errorf(errMsg)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// GetSensorsByTemperatures returns commulated list of sensors by temperature values
|
||||
func GetSensorsByTemperatures(temperatures []*types.Temperature, cnf *config.FluckyConfig) []*types.Sensor {
|
||||
func GetSensorsByTemperatures(temperatures []*types.Temperature, cnf *config.Configuration) []*types.Sensor {
|
||||
sensors := []*types.Sensor{}
|
||||
for _, temperature := range temperatures {
|
||||
duplicated := false
|
||||
@ -66,7 +66,7 @@ func GetTemperaturesBetweenTimeRange(from time.Time, till *time.Time, temperatur
|
||||
|
||||
// GetTemperaturesBySensors returns a list of temperatures given by the sensor id.
|
||||
// If the sensor name, wire-id or id can not found in configured sensors, it would be skiped!
|
||||
func GetTemperaturesBySensors(sensorNamesOrIDs []string, temperatures []*types.Temperature, cnf *config.FluckyConfig) []*types.Temperature {
|
||||
func GetTemperaturesBySensors(sensorNamesOrIDs []string, temperatures []*types.Temperature, cnf *config.Configuration) []*types.Temperature {
|
||||
cachedSensors := []*types.Sensor{}
|
||||
cachedTemperatures := []*types.Temperature{}
|
||||
|
||||
|
Reference in New Issue
Block a user