sleepNotification(): Actually add converted sleep stages to the activities list.
[kraftakt.git] / kraftakt.go
index e2318e7..4381596 100644 (file)
@@ -295,20 +295,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)
 
@@ -437,7 +437,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 {
@@ -500,17 +500,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()