app.yaml: Set api_version "go1".
[kraftakt.git] / kraftakt.go
index 53d1764..72389bd 100644 (file)
@@ -258,13 +258,9 @@ func fitbitNotifyHandler(ctx context.Context, w http.ResponseWriter, r *http.Req
        // Fitbit recommendation: "If signature verification fails, you should
        // respond with a 404"
        if !fitbit.CheckSignature(ctx, data, r.Header.Get("X-Fitbit-Signature")) {
-               /*
-                       log.Errorf(ctx, "signature mismatch")
-                       w.WriteHeader(http.StatusNotFound)
-                       return nil
-               */
-       } else {
-               log.Warningf(ctx, "TODO(octo): re-enable signature checking, see https://community.fitbit.com/t5/Web-API-Development/Push-notification-signatures-are-currently-invalid/m-p/2496159")
+               log.Errorf(ctx, "signature mismatch")
+               w.WriteHeader(http.StatusNotFound)
+               return nil
        }
 
        if err := delayedHandleNotifications.Call(ctx, data); err != nil {
@@ -437,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 {
@@ -491,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 {
@@ -500,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()
@@ -518,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)
        }