1
0
mirror of https://github.com/Luzifer/tasmota-config.git synced 2024-09-19 00:52:56 +00:00

Improve logging and value checking

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-07-05 01:48:28 +02:00
parent 9ac7aa8c6b
commit 514a6e2860
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
2 changed files with 7 additions and 3 deletions

View File

@ -65,7 +65,7 @@ func main() {
for devName, devConfig := range config.Devices {
if cfg.Device != "" && devName != cfg.Device {
log.WithField("name", devName).Debug("Skipping device as requested")
log.WithField("name", devName).Trace("Skipping device as requested")
continue
}
@ -77,7 +77,6 @@ func main() {
func processDevice(mqttClient mqtt.Client, config *configFile, devName string, devConfig deviceConfig) error {
log.WithField("name", devName).Info("Starting device config")
defer log.WithField("name", devName).Info("Finished device config")
var (
responses = make(chan []byte, 30)
@ -129,10 +128,11 @@ func processDevice(mqttClient mqtt.Client, config *configFile, devName string, d
if len(updates) == 0 {
log.WithField("name", devName).Info("Device looks good, nothing to do")
return nil
}
if cfg.DryRun {
log.WithField("name", devName).Info("Device needs updates but requested dry-run")
log.WithField("name", devName).Infof("Device needs %d updates but requested dry-run", len(updates))
return nil
}

View File

@ -51,6 +51,10 @@ func extractGenericJSONValue(setting string, payload []byte) (interface{}, error
return nil, errors.Wrap(err, "Unable to map payload into map[string]interface{}")
}
if _, ok := data[setting]; !ok {
return nil, errors.New("Unable to find requested value")
}
return data[setting], nil
}