From 9238f3adbf5da839e391af4542c62f23461eec82 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Fri, 29 Jul 2022 13:29:24 +0200 Subject: [PATCH] feat(owm): correct data type for temperature resolves #2591 --- src/segments/owm.go | 5 +++-- src/segments/owm_test.go | 4 ++-- website/docs/segments/owm.mdx | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/segments/owm.go b/src/segments/owm.go index 9c9ac4af..20e96245 100644 --- a/src/segments/owm.go +++ b/src/segments/owm.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "math" "oh-my-posh/environment" "oh-my-posh/properties" ) @@ -12,7 +13,7 @@ type Owm struct { props properties.Properties env environment.Environment - Temperature float64 + Temperature int Weather string URL string units string @@ -106,7 +107,7 @@ func (d *Owm) setStatus() error { } id := q.Data[0].TypeID - d.Temperature = q.temperature.Value + d.Temperature = int(math.Round(q.temperature.Value)) icon := "" switch id { case "01n": diff --git a/src/segments/owm_test.go b/src/segments/owm_test.go index 32c6b881..b583eff6 100644 --- a/src/segments/owm_test.go +++ b/src/segments/owm_test.go @@ -182,7 +182,7 @@ func TestOWMSegmentIcons(t *testing.T) { for _, tc := range cases { env := &mock.MockedEnvironment{} - response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) + response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20.3}}`, tc.IconID) expectedString := fmt.Sprintf("%s (20°C)", tc.ExpectedIconString) env.On("HTTPRequest", OWMAPIURL).Return([]byte(response), nil) @@ -205,7 +205,7 @@ func TestOWMSegmentIcons(t *testing.T) { for _, tc := range cases { env := &mock.MockedEnvironment{} - response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) + response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20.3}}`, tc.IconID) expectedString := fmt.Sprintf("[%s (20°C)](http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key)", tc.ExpectedIconString) env.On("HTTPRequest", OWMAPIURL).Return([]byte(response), nil) diff --git a/website/docs/segments/owm.mdx b/website/docs/segments/owm.mdx index c70288f6..1881207a 100644 --- a/website/docs/segments/owm.mdx +++ b/website/docs/segments/owm.mdx @@ -60,7 +60,7 @@ properties below - defaults to `{{.Weather}} ({{.Temperature}}{{.UnitIcon}})` ### Properties - `.Weather`: `string` - the current weather icon -- `.Temperature`: `string` - the current temperature +- `.Temperature`: `int` - the current temperature - `.UnitIcon`: `string` - the current unit icon(based on units property) - `.URL`: `string` - the url of the current api call