X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=gfitsync.go;h=beb44d755bf8d18d102c5be6bc3417062ff983b2;hb=0b5931467b50004d313104794a2be450c6413582;hp=22f4c5668e63eac577830aca0fbc94bd04aed89c;hpb=43223a02eecd68642404b09c3085f435722cb144;p=kraftakt.git diff --git a/gfitsync.go b/gfitsync.go index 22f4c56..beb44d7 100644 --- a/gfitsync.go +++ b/gfitsync.go @@ -219,12 +219,18 @@ func handleNotification(ctx context.Context, s *fitbit.Subscription) error { return err } - tm, err := time.Parse("2006-01-02", s.Date) + fitbitClient, err := fitbit.NewClient(ctx, s.OwnerID, u) if err != nil { return err } - fitbitClient, err := fitbit.NewClient(ctx, s.OwnerID, u) + profile, err := fitbitClient.Profile(ctx) + if err != nil { + return err + } + log.Debugf(ctx, "profile = %+v", profile) + + tm, err := time.ParseInLocation("2006-01-02", s.Date, profile.Timezone) if err != nil { return err } @@ -233,7 +239,8 @@ func handleNotification(ctx context.Context, s *fitbit.Subscription) error { if err != nil { return err } - log.Debugf(ctx, "ActivitySummary for %s = %+v", u.Email, summary) + log.Debugf(ctx, "%s (%s) took %d steps on %s", + profile.Name, u.Email, summary.Summary.Steps, s.Date) gfitClient, err := gfit.NewClient(ctx, u) if err != nil { @@ -244,5 +251,9 @@ func handleNotification(ctx context.Context, s *fitbit.Subscription) error { return fmt.Errorf("gfitClient.SetSteps(%d) = %v", summary.Summary.Steps, err) } + if err := gfitClient.SetCalories(ctx, summary.Summary.CaloriesOut, tm); err != nil { + return fmt.Errorf("gfitClient.SetCalories(%d) = %v", summary.Summary.CaloriesOut, err) + } + return nil }