From 2c4a3f6c20581dafc83a86edfbb1077d35a8ced9 Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 15 May 2021 14:01:21 +0200 Subject: [PATCH] Detect: improve debug output and reduce number of lines (#1022) --- detect/definitions.go | 28 ++++++++++++++-------------- detect/tasklist.go | 5 +++-- detect/tasks/modbus.go | 4 ++-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/detect/definitions.go b/detect/definitions.go index c037a4554..4d8bd161e 100644 --- a/detect/definitions.go +++ b/detect/definitions.go @@ -1,8 +1,6 @@ package detect import ( - "time" - "github.com/andig/evcc/detect/tasks" ) @@ -44,21 +42,23 @@ const ( ) func init() { - taskList.Add(tasks.Task{ - ID: taskSMA, - Type: tasks.Sma, - }) - - taskList.Add(tasks.Task{ - ID: taskKEBA, - Type: tasks.Keba, - }) - taskList.Add(tasks.Task{ ID: TaskPing, Type: tasks.Ping, }) + taskList.Add(tasks.Task{ + ID: taskSMA, + Type: tasks.Sma, + Depends: TaskPing, + }) + + taskList.Add(tasks.Task{ + ID: taskKEBA, + Type: tasks.Keba, + Depends: TaskPing, + }) + taskList.Add(tasks.Task{ ID: TaskModbus, Type: tasks.Tcp, @@ -273,8 +273,8 @@ func init() { Type: tasks.Http, Depends: TaskHttp, Config: map[string]interface{}{ - "path": "/middleware.php/entity.json", - "timeout": 500 * time.Millisecond, + "path": "/middleware.php/entity.json", + "jq": ".version", }, }) } diff --git a/detect/tasklist.go b/detect/tasklist.go index 27a3fa0ad..63a77127a 100644 --- a/detect/tasklist.go +++ b/detect/tasklist.go @@ -90,8 +90,6 @@ func (l *TaskList) Test(log *util.Logger, id string, input tasks.ResultDetails) if id == "" { inputs = append(inputs, input) } else { - log.DEBUG.Printf("ip: %s task: %s (%v)", input.IP, id, input) - var task tasks.Task for _, t := range l.tasks { if t.ID == id { @@ -101,6 +99,9 @@ func (l *TaskList) Test(log *util.Logger, id string, input tasks.ResultDetails) } inputs = task.Test(log, input) + success := len(inputs) > 0 + log.DEBUG.Printf("task: %s %v -> %v", id, input, success) + for _, detail := range inputs { all = append(all, tasks.Result{ Task: task, diff --git a/detect/tasks/modbus.go b/detect/tasks/modbus.go index 3c32c611e..a8169a648 100644 --- a/detect/tasks/modbus.go +++ b/detect/tasks/modbus.go @@ -199,10 +199,10 @@ func (h *ModbusHandler) Test(log *util.Logger, in ResultDetails) (res []ResultDe var ok bool if h.op.OpCode > 0 { - log.DEBUG.Printf("slave id: %d op: %v", slaveID, h.op) + // log.DEBUG.Printf("slave id: %d op: %v", slaveID, h.op) ok = h.testRegister(log, conn.ModbusClient()) } else { - log.DEBUG.Printf("slave id: %d models: %v", slaveID, h.Models) + // log.DEBUG.Printf("slave id: %d models: %v", slaveID, h.Models) ok = h.testSunSpec(log, conn, dev, &mr) }