correction gestion deconnexion

This commit is contained in:
Laurent Le Houerou 2020-07-02 14:48:07 +04:00
parent 9bc06cb150
commit a709ba65aa
2 changed files with 17 additions and 0 deletions

View File

@ -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")

View File

@ -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(&notifyResponse)
if err != nil {