feat(owm): correct data type for temperature

resolves #2591
This commit is contained in:
Jan De Dobbeleer 2022-07-29 13:29:24 +02:00 committed by Jan De Dobbeleer
parent 69856f4464
commit 9238f3adbf
3 changed files with 6 additions and 5 deletions

View file

@ -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":

View file

@ -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)

View file

@ -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