X-Git-Url: https://git.octo.it/?p=kraftakt.git;a=blobdiff_plain;f=kraftakt.go;h=72389bd1430b36450a071d09d8a491597d4805d7;hp=d53a3a35d810630f6d9e7979f00009fcb8af6f60;hb=b2a4c7b34862646d55add7c416362360cf383de5;hpb=b0b4324f51ba7658e5e97b294ebd8ab7008d8f2a diff --git a/kraftakt.go b/kraftakt.go index d53a3a3..72389bd 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -291,20 +291,20 @@ func handleNotifications(ctx context.Context, payload []byte) error { switch s.CollectionType { case "activities": wg.Add(1) - go func() { + go func(s fitbit.Subscription) { defer wg.Done() if err := activitiesNotification(ctx, &s); err != nil { log.Warningf(ctx, "activitiesNotification() = %v", err) } - }() + }(s) // copies s case "sleep": wg.Add(1) - go func() { + go func(s fitbit.Subscription) { defer wg.Done() if err := sleepNotification(ctx, &s); err != nil { log.Warningf(ctx, "sleepNotification() = %v", err) } - }() + }(s) // copies s default: log.Warningf(ctx, "ignoring collection type %q", s.CollectionType) @@ -433,7 +433,7 @@ func activitiesNotification(ctx context.Context, s *fitbit.Subscription) error { activities = append(activities, gfit.Activity{ Start: startTime, End: endTime, - Type: gfit.ParseFitbitActivity(a.Name), + Type: a.Name, }) } if err := gfitClient.SetActivities(ctx, activities, tm); err != nil { @@ -487,6 +487,7 @@ func sleepNotification(ctx context.Context, s *fitbit.Subscription) error { if err != nil { return err } + log.Debugf(ctx, "fitbitClient.Sleep(%v) returned %d sleep stages", tm, len(sleep.Stages)) var activities []gfit.Activity for _, stg := range sleep.Stages { @@ -496,17 +497,19 @@ func sleepNotification(ctx context.Context, s *fitbit.Subscription) error { } switch stg.Level { case fitbit.SleepLevelDeep: - a.Type = 110 // Deep sleep + a.Type = "Deep sleep" case fitbit.SleepLevelLight: - a.Type = 109 // Light sleep + a.Type = "Light sleep" case fitbit.SleepLevelREM: - a.Type = 111 // REM sleep + a.Type = "REM sleep" case fitbit.SleepLevelWake: - a.Type = 112 // Awake (during sleep cycle) + a.Type = "Awake (during sleep cycle)" default: log.Warningf(ctx, "unexpected sleep level %v", stg.Level) continue } + + activities = append(activities, a) } wg.Wait() @@ -514,6 +517,7 @@ func sleepNotification(ctx context.Context, s *fitbit.Subscription) error { return gfitErr } + log.Debugf(ctx, "passing %d activities to gfitClient.SetActivities()", len(activities)) if err := gfitClient.SetActivities(ctx, activities, tm); err != nil { return fmt.Errorf("SetActivities() = %v", err) }