JanDeDobbeleer / oh-my-posh

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

Withings segment issue #2551

Closed GHRoss closed 2 years ago

GHRoss commented 2 years ago

Code of Conduct

What happened?

Hi Jan, thanks for creating this segment!

I've just tried to put it into my config, but it's not returning anything.

Running debug the only mention of Withings I get is: withings(false) - 22 ms -

Using the example from the Withings segment docs page.

Not much to go on, but let me know if I can help.

EDIT: Just seen this problem in VS Code. Screenshot 2022-07-20 162721 Incorrect type. Expected "integer".

Theme

clean-detailed

What OS are you seeing the problem on?

Linux

Which shell are you using?

powershell

Log output

withings(false)      -  22 ms -
JanDeDobbeleer commented 2 years ago

@GHRoss debug should show what it doing underneath.

GHRoss commented 2 years ago

It doesn't, it only shows what I've posted?

GHRoss commented 2 years ago

You were of course correct!

2022/07/20 16:51:58 debug: HTTPRequest GET /api/refresh?segment=withings&token=redacted HTTP/1.1 Host: ohmyposh.dev User-Agent: Go-http-client/1.1 Accept-Encoding: gzip

2022/07/20 16:51:58 debug: HTTPRequest GET /api/refresh?segment=withings&token=redacted HTTP/1.1 Host: ohmyposh.dev User-Agent: Go-http-client/1.1 Accept-Encoding: gzip

2022/07/20 16:51:58 debug: HTTPRequest GET /api/refresh?segment=withings&token=redacted HTTP/1.1 Host: ohmyposh.dev User-Agent: Go-http-client/1.1 Accept-Encoding: gzip

2022/07/20 16:51:58 error: HTTPRequest Get "https://ohmyposh.dev/api/refresh?segment=withings&token=redacted": context deadline exceeded 2022/07/20 16:51:58 HTTPRequest duration: 20.2058ms, args: https://ohmyposh.dev/api/refresh?segment=withings&token=redacted 2022/07/20 16:51:58 error: HTTPRequest Get "https://ohmyposh.dev/api/refresh?segment=withings&token=redacted": context deadline exceeded 2022/07/20 16:51:58 HTTPRequest duration: 20.1203ms, args: https://ohmyposh.dev/api/refresh?segment=withings&token=redacted 2022/07/20 16:51:58 error: HTTPRequest Get "https://ohmyposh.dev/api/refresh?segment=withings&token=redacted": context deadline exceeded 2022/07/20 16:51:58 HTTPRequest duration: 20.1668ms, args: https://ohmyposh.dev/api/refresh?segment=withings&token=redacted

GHRoss commented 2 years ago

Just to clarify, I can connect to this page using Invoke-WebRequest.

JanDeDobbeleer commented 2 years ago

@GHRoss you need to set a different "http_timeout" as the requests takes longer than the default 20ms.

GHRoss commented 2 years ago

I've set this to extremely high values already and it doesn't make a difference.

For what it's worth, http_timeout also says that it's an incorrect type in the config viewed in VS Code...

JanDeDobbeleer commented 2 years ago

@GHRoss did you add an int or string?

GHRoss commented 2 years ago

Int. Generally different variations of 9999.

JanDeDobbeleer commented 2 years ago

@GHRoss hmm. I have this at 1500 and it works. I'll check.

GHRoss commented 2 years ago

To rule out OS, I setup oh-my-posh in Windows too and get the same error.

JanDeDobbeleer commented 2 years ago

@GHRoss seems like parallel execution was the issue, removed it as race conditions occur to refresh the token which makes oh-my-posh use the current token.

GHRoss commented 2 years ago

Still getting the same thing...

2022/07/22 11:18:15 debug: HTTPRequest GET /api/refresh?segment=withings&token=redacted HTTP/1.1 Host: ohmyposh.dev User-Agent: Go-http-client/1.1 Accept-Encoding: gzip

2022/07/22 11:18:15 error: HTTPRequest Get "https://ohmyposh.dev/api/refresh?segment=withings&token=redacted": context deadline exceeded 2022/07/22 11:18:15 HTTPRequest duration: 21.0939ms, args: https://ohmyposh.dev/api/refresh?segment=withings&token=redacted 2022/07/22 11:18:15 error: OAuth no data in cache 2022/07/22 11:18:15 debug: HTTPRequest GET /api/refresh?segment=withings&token=redacted HTTP/1.1 Host: ohmyposh.dev User-Agent: Go-http-client/1.1 Accept-Encoding: gzip

2022/07/22 11:18:15 error: HTTPRequest Get "https://ohmyposh.dev/api/refresh?segment=withings&token=redacted": context deadline exceeded 2022/07/22 11:18:15 HTTPRequest duration: 21.1064ms, args: https://ohmyposh.dev/api/refresh?segment=withings&token=redacted 2022/07/22 11:18:15 error: OAuth no data in cache 2022/07/22 11:18:15 debug: HTTPRequest GET /api/refresh?segment=withings&token=redacted HTTP/1.1 Host: ohmyposh.dev User-Agent: Go-http-client/1.1 Accept-Encoding: gzip

2022/07/22 11:18:15 error: HTTPRequest Get "https://ohmyposh.dev/api/refresh?segment=withings&token=redacted": context deadline exceeded 2022/07/22 11:18:15 HTTPRequest duration: 20.1959ms, args: https://ohmyposh.dev/api/refresh?segment=withings&token=redacted

JanDeDobbeleer commented 2 years ago

But that's still the default 20ms, can you share your redacted segment?

GHRoss commented 2 years ago

{ "type": "withings", "style": "powerline", "powerline_symbol": "\uE0B0", "template": "{{ if gt .Weight 0.0 }} {{ round .Weight 2 }}kg {{ end }}", "properties": { "access_token": "redacted", "refresh_token": "redacted", "expires_in": "10800", "http_timeout": "1500" } },

JanDeDobbeleer commented 2 years ago

@GHRoss can you remove the quotes from the http_timeout value? That's an integer, and I also fixed the website to reflect that upon authentication.

GHRoss commented 2 years ago

Still get the same thing.

GHRoss commented 2 years ago

Ah! It seems to be working now, but some of the values are incorrect?

Steps is yesterday's steps where (I personally) would prefer to know how close I am to my steps goal, so today's current step count would be good.

Sleep hours just shows '0.0'.

withings(true) - 1 ms - 0.0 4215 88.5882

Above is sleep hours, steps and weight.

JanDeDobbeleer commented 2 years ago

@GHRoss can you get me the output of oh-my-posh debug?

GHRoss commented 2 years ago

@JanDeDobbeleer

action=getactivity&category=1&data_fields=steps&enddateymd=2022-07-22&startdateymd=2022-07-21 2022/07/22 15:48:27 debug: HTTPRequest {"status":0,"body":{"activities":[{"steps":4215,"deviceid":null,"hash_deviceid":null,"timezone":"Europe\/London","date":"2022-07-21","modified":1658476377,"brand":18,"is_tracker":true},{"steps":922,"deviceid":null,"hash_deviceid":null,"timezone":"Europe\/London","date":"2022-07-22","modified":1658493852,"brand":18,"is_tracker":true}],"more":false,"offset":0}} 2022/07/22 15:48:27 HTTPRequest duration: 225.2839ms, args: https://wbsapi.withings.net/v2/measure 2022/07/22 15:48:27 error: OAuth no data in cache 2022/07/22 15:48:27 debug: HTTPRequest POST /measure HTTP/1.1 Host: wbsapi.withings.net User-Agent: Go-http-client/1.1 Content-Length: 59 Authorization: Bearer REDACTED Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip

action=getmeas&category=1&lastupdate=1657291707&meastypes=1 2022/07/22 15:48:27 debug: HTTPRequest {"status":0,"body":{"updatetime":1658501307,"timezone":"Europe\/London","measuregrps":[{"grpid":3714375707,"attrib":2,"date":1657445883,"created":1657445888,"modified":1657445888,"category":1,"deviceid":null,"hash_deviceid":null,"measures":[{"value":675852,"type":1,"unit":-4,"algo":0,"fm":3}],"comment":null}]}} 2022/07/22 15:48:27 HTTPRequest duration: 114.3405ms, args: https://wbsapi.withings.net/measure 2022/07/22 15:48:27 error: OAuth no data in cache 2022/07/22 15:48:27 debug: HTTPRequest POST /v2/sleep HTTP/1.1 Host: wbsapi.withings.net User-Agent: Go-http-client/1.1 Content-Length: 50 Authorization: Bearer REDACTED Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip

action=get&enddate=1658501307&startdate=1655909307 2022/07/22 15:48:27 debug: HTTPRequest {"status":0,"body":{"series":[{"startdate":REDACTED,"state":0,"enddate":REDACTED,"model":"Activite Steel HR","hash_deviceid":"REDACTED","model_id":55},],"model":16}} 2022/07/22 15:48:27 HTTPRequest duration: 139.1991ms, args: https://wbsapi.withings.net/v2/sleep

There were lots more records for /sleep, but I took them out to more quickly redact stuff. They all looked the same, just for different time periods.

JanDeDobbeleer commented 2 years ago

@GHRoss ok, so activities aren't sorted meaning I need to filter today from the results. For sleep, duration is calculated from the dates so if I can get those, that would be ace 👍🏻

GHRoss commented 2 years ago

{"startdate":1655936880,"state":0,"enddate":1655937000,"model":"redacted","hash_deviceid":"redacted","model_id":redacted}

There's about 200 of these that go throughout the night.

JanDeDobbeleer commented 2 years ago

@GHRoss ah, so they're all measures for the same night? Meaning I also need to filter out for that night.

GHRoss commented 2 years ago

It looks like it, yeah.

GHRoss commented 2 years ago

Steps are no longer working.

withings(true) - 0 ms - 7.9 0 88.58kg

Sleep, Steps, weight.

JanDeDobbeleer commented 2 years ago

@GHRoss strange as I do fetch the current day steps. Do you have the api output for me?

GHRoss commented 2 years ago

Looks like the value is in there. 1568 today. Need to go for a walk!!

action=getactivity&category=1&data_fields=steps&enddateymd=2022-07-22&startdateymd=2022-07-21 2022/07/22 21:51:48 debug: HTTPRequest {"status":0,"body":{"activities":[{"steps":4215,"deviceid":null,"hash_deviceid":null,"timezone":"Europe\/London","date":"2022-07-21","modified":1658476377,"brand":,"is_tracker":true},{"steps":1568,"deviceid":null,"hash_deviceid":null,"timezone":"Europe\/London","date":"2022-07-22","modified":1658519211,"brand":,"is_tracker":true}],"more":false,"offset":0}} 2022/07/22 21:51:48 HTTPRequest duration: 5.1716565s, args: https://wbsapi.withings.net/v2/measure 2022/07/22 21:51:48 error: OAuth no data in cache 2022/07/22 21:51:48 debug: HTTPRequest POST /measure HTTP/1.1 Host: wbsapi.withings.net User-Agent: Go-http-client/1.1 Content-Length: 59 Authorization: Bearer REDACTED Content-Type: application/x-www-form-urlencoded Accept-Encoding: gzip

JanDeDobbeleer commented 2 years ago

@GHRoss the code is correct, there's an issue in the JSON however: "brand":,, that field has no value which isn't correct. That error should also be logged in the debug output. And that's for Withings to fix...

github-actions[bot] commented 8 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.