From a709ba65aa52a7ac0541d5fd88a86c5eda1fa15c Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Thu, 2 Jul 2020 14:48:07 +0400 Subject: [PATCH] correction gestion deconnexion --- cmd/main.go | 13 +++++++++++++ event_stream.go | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/cmd/main.go b/cmd/main.go index 34fa697..b4b165e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,12 +2,25 @@ package main import ( "context" + "fmt" + "path" + "runtime" "git.lehouerou.net/laurent/arlo-go" log "github.com/sirupsen/logrus" ) func main() { + log.SetLevel(log.TraceLevel) + log.SetFormatter(&log.TextFormatter{ + ForceColors: true, + FullTimestamp: true, + TimestampFormat: "02-01-2006 15:04:05", + CallerPrettyfier: func(f *runtime.Frame) (string, string) { + filename := path.Base(f.File) + return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line) + }, + }) ctx := context.Background() a := arlo.NewArlo() err := a.Login(ctx, "hass@lehouerou.net", "TiPXMVLUeZfUg6RrmwzK") diff --git a/event_stream.go b/event_stream.go index b4442ac..2615bd8 100644 --- a/event_stream.go +++ b/event_stream.go @@ -87,11 +87,13 @@ func (e *eventStream) listen(ctx context.Context) error { return case event, ok := <-e.Events: if !ok { + e.disconnect() return } if event == nil || event.Data == nil { log.Warn("EventStream > nil event or nil data in event") + e.disconnect() continue } @@ -99,6 +101,8 @@ func (e *eventStream) listen(ctx context.Context) error { e.setLastId(string(event.ID)) } + log.Tracef("Data > %s", event.Data) + var notifyResponse EventStreamResponse err := json.NewDecoder(bytes.NewBuffer(event.Data)).Decode(¬ifyResponse) if err != nil {