fix: send only to enabled remotes data

This commit is contained in:
Markus Pesch 2018-11-30 16:14:47 +01:00
parent cc16bb9555
commit 7b18b115c8
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 28 additions and 21 deletions

View File

@ -28,6 +28,7 @@ func SendTemperatures(temperatures []*stypes.Temperature, configDir string) erro
temperaturesAsReader := bytes.NewReader(temperaturesAsBytes) temperaturesAsReader := bytes.NewReader(temperaturesAsBytes)
for _, remote := range cnf.Remotes { for _, remote := range cnf.Remotes {
if remote.Enabled {
requestURL := fmt.Sprintf("%s%s", remote.Address, "/temperatures") requestURL := fmt.Sprintf("%s%s", remote.Address, "/temperatures")
req, err := http.NewRequest("POST", requestURL, temperaturesAsReader) req, err := http.NewRequest("POST", requestURL, temperaturesAsReader)
if err != nil { if err != nil {
@ -49,6 +50,7 @@ func SendTemperatures(temperatures []*stypes.Temperature, configDir string) erro
return fmt.Errorf("Invalid HTTP-Statuscode - expected 200, got %d: %v", resp.StatusCode, string(b)) return fmt.Errorf("Invalid HTTP-Statuscode - expected 200, got %d: %v", resp.StatusCode, string(b))
} }
} }
}
return nil return nil

View File

@ -37,15 +37,20 @@ func Get(sensorNames []string, push bool, configDir string, w io.Writer) error {
if len(sensorNames) > 0 { if len(sensorNames) > 0 {
for _, sensorName := range sensorNames { for _, sensorName := range sensorNames {
for _, sensor := range cnf.Sensors { for _, sensor := range cnf.Sensors {
if sensorName == *sensor.SensorName || if sensorName == *sensor.SensorName && *sensor.SensorEnabled ||
sensorName == sensor.SensorID || sensorName == sensor.SensorID && *sensor.SensorEnabled ||
sensorName == *sensor.WireID { sensorName == *sensor.WireID && *sensor.SensorEnabled {
sensors = append(sensors, sensor) sensors = append(sensors, sensor)
} }
} }
} }
} else { } else {
sensors = append(sensors, cnf.Sensors...) for _, sensor := range cnf.Sensors {
if *sensor.SensorEnabled {
sensors = append(sensors, sensor)
}
}
} }
// check if sensor exists in cnf and has a wire id // check if sensor exists in cnf and has a wire id