fix(withings): pick today's steps

This commit is contained in:
Jan De Dobbeleer 2022-07-22 20:02:50 +02:00 committed by Jan De Dobbeleer
parent 8426f81e71
commit 7029013fd8
2 changed files with 16 additions and 2 deletions

View file

@ -179,8 +179,15 @@ func (w *Withings) getActivities() bool {
if err != nil || len(data.Body.Activities) == 0 {
return false
}
w.Steps = data.Body.Activities[0].Steps
return true
today := time.Now().Format("2006-01-02")
for _, activity := range data.Body.Activities {
if activity.Date != today {
continue
}
w.Steps = activity.Steps
return true
}
return false
}
func (w *Withings) getSleep() bool {

View file

@ -5,6 +5,7 @@ import (
"oh-my-posh/mock"
"oh-my-posh/properties"
"testing"
"time"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
@ -84,8 +85,13 @@ func TestWithingsSegment(t *testing.T) {
WithingsData: &WithingsData{
Body: &Body{
Activities: []*Activity{
{
Steps: 5066,
Date: time.Now().AddDate(0, 0, -1).Format("2006-01-02"),
},
{
Steps: 7077,
Date: time.Now().Format("2006-01-02"),
},
},
},
@ -127,6 +133,7 @@ func TestWithingsSegment(t *testing.T) {
Activities: []*Activity{
{
Steps: 976,
Date: time.Now().Format("2006-01-02"),
},
},
},