fix: send only to enabled remotes data
This commit is contained in:
parent
cc16bb9555
commit
7b18b115c8
@ -28,25 +28,27 @@ 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 {
|
||||||
requestURL := fmt.Sprintf("%s%s", remote.Address, "/temperatures")
|
if remote.Enabled {
|
||||||
req, err := http.NewRequest("POST", requestURL, temperaturesAsReader)
|
requestURL := fmt.Sprintf("%s%s", remote.Address, "/temperatures")
|
||||||
if err != nil {
|
req, err := http.NewRequest("POST", requestURL, temperaturesAsReader)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
client := http.Client{}
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
|
||||||
b, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Invalid HTTP-Statuscode - expected 200, got %d - can not read response body: %v", resp.StatusCode, err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client := http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||||
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Invalid HTTP-Statuscode - expected 200, got %d - can not read response body: %v", resp.StatusCode, err)
|
||||||
|
}
|
||||||
|
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))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user