JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.02k stars 2.37k forks source link

Withings Segment Issue #2581

Closed GHRoss closed 2 years ago

GHRoss commented 2 years ago

Code of Conduct

What happened?

Sorry @JanDeDobbeleer, another one!

I've noticed that weight only shows for today, but weight isn't necessarily recorded everyday like the other data. I manually have to input this, as I don't have their scales, for example, so it would be good to just get the latest available weight data, rather than today's weight.

Theme

clean-detailed

What OS are you seeing the problem on?

Linux

Which shell are you using?

powershell

Log output

N/A
JanDeDobbeleer commented 2 years ago

@GHRoss can you help me with the API output in your case? I only have mine, and probably I need to loop all measurements until I have the right value but want to be certain.

CaptnCodr commented 2 years ago

Hello @JanDeDobbeleer, my Withings segment is not working. Debug is not showing any logs from the withings api only this line in segments: withings(false) - 0 ms -

Any ideas?

JanDeDobbeleer commented 2 years ago

@CaptnCodr can I get the full logs and the Withings segment config?

CaptnCodr commented 2 years ago

Config:


        {
          "type": "withings",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "foreground": "green",
          "background": "#ffffff",
          "template": "{{ if gt .Weight 0.0 }} {{ round .Weight 2 }} kg {{ end }} {{ .SleepHours }} {{ .Steps }}",
          "properties": {
            "access_token": "redacted",
            "refresh_token": "redacted",
            "expires_in": 10800,
            "http_timeout": 1500
          },
          "leading_diamond": "\ue0b2",
          "trailing_diamond": "\ue0b2"
        },

Log: omp.log

JanDeDobbeleer commented 2 years ago

@CaptnCodr can you have a look at what's inside the cache? You can get the location using oh-my-posh cache path and open the omp.cache file. If there's some Withings data, remove the cached responses (not the access_token etc.). And try again.

CaptnCodr commented 2 years ago

After removing those cached element I ran oh-my-posh debug following came out:

2022/08/17 14:40:47 error: OAuth
no data in cache
2022/08/17 14:40:47 debug: HTTPRequest
POST /v2/measure HTTP/1.1
Host: wbsapi.withings.net
User-Agent: Go-http-client/1.1
Content-Length: 93
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

action=getactivity&category=1&data_fields=steps&enddateymd=2022-08-17&startdateymd=2022-08-16
2022/08/17 14:40:47 debug: HTTPRequest
{"status":501,"error":"Invalid Session: sessionid missing"}
2022/08/17 14:40:47 HTTPRequest duration: 202.176ms, args: https://wbsapi.withings.net/v2/measure
2022/08/17 14:40:47 error: OAuth
no data in cache
2022/08/17 14:40:47 debug: HTTPRequest
POST /measure HTTP/1.1
Host: wbsapi.withings.net
User-Agent: Go-http-client/1.1
Content-Length: 59
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

action=getmeas&category=1&lastupdate=1659530447&meastypes=1
2022/08/17 14:40:47 debug: HTTPRequest
{"status":503,"body":{},"error":"Invalid Params"}
2022/08/17 14:40:47 HTTPRequest duration: 46.6973ms, args: https://wbsapi.withings.net/measure
2022/08/17 14:40:47 error: OAuth
no data in cache
2022/08/17 14:40:47 debug: HTTPRequest
POST /v2/sleep HTTP/1.1
Host: wbsapi.withings.net
User-Agent: Go-http-client/1.1
Content-Length: 50
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

action=get&enddate=1660737600&startdate=1660683600
2022/08/17 14:40:47 debug: HTTPRequest
{"status":503,"error":"Invalid Params: Missing [access_token]"}
2022/08/17 14:40:47 HTTPRequest duration: 54.9086ms, args: https://wbsapi.withings.net/v2/sleep
JanDeDobbeleer commented 2 years ago

@CaptnCodr yup, that's a Withings API bug. I also had that a few times during development. Can you remove the entire cache and re-authenticate? That could solve the issue.

CaptnCodr commented 2 years ago

I did now, but the access_token in omp.cache does not match with my access_token, is this correct? Re-authentication does not help. Same error messages.

JanDeDobbeleer commented 2 years ago

@CaptnCodr yes, that's correct. It will refresh when needed. I also had that during my testing and couldn't find the root cause. Unless I did ruin something lately. Will try when I'm at home (but did validate that).

JanDeDobbeleer commented 2 years ago

@lnu could this be the same issue you were trying to fix?

lnu commented 2 years ago

Exactly

JanDeDobbeleer commented 2 years ago

@CaptnCodr can you try again with the latest? Might need to remove the cache values although it shouldn't.

CaptnCodr commented 2 years ago

Yes, I will test this as soon as I can.

CaptnCodr commented 2 years ago

That works now. Thank you very much. 🙂

CaptnCodr commented 2 years ago

No, not anymore. After 2nd refresh the access_token and refresh_token are now missing from the cache.

Edit: Unfortunately, I did a re-authentication and that might have helped.

CaptnCodr commented 2 years ago

It seems to work properly after deleting cache and re-authenticating. 🙂

JanDeDobbeleer commented 2 years ago

@GHRoss can you help me with the API output in your case? I only have mine, and probably I need to loop all measurements until I have the right value but want to be certain.

@GHRoss any pointers? Would love to fix this one for you ;-)

GHRoss commented 2 years ago

@JanDeDobbeleer Sorry for the radio silence, I think this might have solved itself! Also, it's a good reminder to actually measure your weight. I was impacted by the bug that @CaptnCodr raised, but didn't have time to raise it.

github-actions[bot] commented 9 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.