Warn about unexpected notification types.
[kraftakt.git] / gfitsync.go
index 61e9107..9eadde9 100644 (file)
@@ -126,8 +126,11 @@ func fitbitGrantHandler(ctx context.Context, w http.ResponseWriter, r *http.Requ
                return err
        }
 
-       if err := c.Subscribe(ctx, "activities"); err != nil {
-               return fmt.Errorf("c.Subscribe() = %v", err)
+       for _, collection := range []string{"activities", "sleep"} {
+               if err := c.Subscribe(ctx, collection); err != nil {
+                       return fmt.Errorf("c.Subscribe(%q) = %v", collection, err)
+               }
+               log.Infof(ctx, "Successfully subscribed to %q", collection)
        }
 
        redirectURL := r.URL
@@ -206,6 +209,7 @@ func handleNotifications(ctx context.Context, payload []byte) error {
 
        for _, s := range subscriptions {
                if s.CollectionType != "activities" {
+                       log.Warningf(ctx, "ignoring collection type %q", s.CollectionType)
                        continue
                }
 
@@ -326,7 +330,7 @@ func handleNotification(ctx context.Context, s *fitbit.Subscription) error {
                                continue
                        }
 
-                       startTime, err := time.ParseInLocation("2006-01-02T15:04:05", a.StartDate+"T"+a.StartTime, profile.Timezone)
+                       startTime, err := time.ParseInLocation("2006-01-02T15:04", a.StartDate+"T"+a.StartTime, profile.Timezone)
                        if err != nil {
                                errs = append(errs, fmt.Errorf("gfitClient.SetActivities() = %v", err))
                                return