Updated the current_conditions module to round all numeric values to integers
This commit is contained in:
@@ -103,12 +103,12 @@ Common fields:
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `.Modules.CurrentConditions.ConditionText` | string | Current condition text. |
|
| `.Modules.CurrentConditions.ConditionText` | string | Current condition text. |
|
||||||
| `.Modules.CurrentConditions.ConditionTextLower` | string | Lower-case current condition text for inline sentences. |
|
| `.Modules.CurrentConditions.ConditionTextLower` | string | Lower-case current condition text for inline sentences. |
|
||||||
| `.Modules.CurrentConditions.TemperatureF` | *float64 | Current temperature. |
|
| `.Modules.CurrentConditions.TemperatureF` | *int | Rounded current temperature. |
|
||||||
| `.Modules.CurrentConditions.ApparentTemperatureF` | *float64 | Apparent temperature. |
|
| `.Modules.CurrentConditions.ApparentTemperatureF` | *int | Rounded apparent temperature. |
|
||||||
| `.Modules.CurrentConditions.RelativeHumidityPercent` | *float64 | Relative humidity. |
|
| `.Modules.CurrentConditions.RelativeHumidityPercent` | *int | Rounded relative humidity. |
|
||||||
| `.Modules.CurrentConditions.WindDirection` | string | 16-point compass wind direction. |
|
| `.Modules.CurrentConditions.WindDirection` | string | 16-point compass wind direction. |
|
||||||
| `.Modules.CurrentConditions.WindDirectionText` | string | Lower-case full wind direction text, such as `northwest`. |
|
| `.Modules.CurrentConditions.WindDirectionText` | string | Lower-case full wind direction text, such as `northwest`. |
|
||||||
| `.Modules.CurrentConditions.WindSpeedMph` | *float64 | Wind speed. |
|
| `.Modules.CurrentConditions.WindSpeedMph` | *int | Rounded wind speed. |
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,10 @@ func TestCurrentConditionsModuleUsesSnakeCaseUnitFields(t *testing.T) {
|
|||||||
}
|
}
|
||||||
value := moduleValue[CurrentConditionsModule](t, output)
|
value := moduleValue[CurrentConditionsModule](t, output)
|
||||||
if value.ConditionText != "Partly cloudy" || value.ConditionTextLower != "partly cloudy" || value.TemperatureF == nil || *value.TemperatureF != 74 {
|
if value.ConditionText != "Partly cloudy" || value.ConditionTextLower != "partly cloudy" || value.TemperatureF == nil || *value.TemperatureF != 74 {
|
||||||
t.Fatalf("CurrentConditions = %#v, want current condition facts", value)
|
t.Fatalf("CurrentConditions = %#v, want rounded current condition facts", value)
|
||||||
|
}
|
||||||
|
if value.ApparentTemperatureF == nil || *value.ApparentTemperatureF != 76 || value.RelativeHumidityPercent == nil || *value.RelativeHumidityPercent != 71 || value.WindSpeedMph == nil || *value.WindSpeedMph != 8 {
|
||||||
|
t.Fatalf("CurrentConditions rounded values = %#v, want apparent 76, humidity 71, wind 8", value)
|
||||||
}
|
}
|
||||||
if value.WindDirection != "S" {
|
if value.WindDirection != "S" {
|
||||||
t.Fatalf("WindDirection = %q, want S", value.WindDirection)
|
t.Fatalf("WindDirection = %q, want S", value.WindDirection)
|
||||||
@@ -403,10 +406,10 @@ func testModuleContext() ModuleContext {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
isDay := true
|
isDay := true
|
||||||
tempF := 74.0
|
tempF := 74.4
|
||||||
apparentF := 76.0
|
apparentF := 75.6
|
||||||
humidity := 71.0
|
humidity := 70.6
|
||||||
windMph := 8.0
|
windMph := 8.4
|
||||||
windDirection := 190.0
|
windDirection := 190.0
|
||||||
narrativeTempF := 81.0
|
narrativeTempF := 81.0
|
||||||
narrativePop := 60.0
|
narrativePop := 60.0
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ type CurrentConditionsModule struct {
|
|||||||
ConditionText string `json:"condition_text,omitempty"`
|
ConditionText string `json:"condition_text,omitempty"`
|
||||||
ConditionTextLower string `json:"condition_text_lower,omitempty"`
|
ConditionTextLower string `json:"condition_text_lower,omitempty"`
|
||||||
IsDay *bool `json:"is_day,omitempty"`
|
IsDay *bool `json:"is_day,omitempty"`
|
||||||
TemperatureC *float64 `json:"temperature_c,omitempty"`
|
TemperatureC *int `json:"temperature_c,omitempty"`
|
||||||
TemperatureF *float64 `json:"temperature_f,omitempty"`
|
TemperatureF *int `json:"temperature_f,omitempty"`
|
||||||
ApparentTemperatureC *float64 `json:"apparent_temperature_c,omitempty"`
|
ApparentTemperatureC *int `json:"apparent_temperature_c,omitempty"`
|
||||||
ApparentTemperatureF *float64 `json:"apparent_temperature_f,omitempty"`
|
ApparentTemperatureF *int `json:"apparent_temperature_f,omitempty"`
|
||||||
DewpointC *float64 `json:"dewpoint_c,omitempty"`
|
DewpointC *int `json:"dewpoint_c,omitempty"`
|
||||||
DewpointF *float64 `json:"dewpoint_f,omitempty"`
|
DewpointF *int `json:"dewpoint_f,omitempty"`
|
||||||
RelativeHumidityPercent *float64 `json:"relative_humidity_percent,omitempty"`
|
RelativeHumidityPercent *int `json:"relative_humidity_percent,omitempty"`
|
||||||
WindSpeedKmh *float64 `json:"wind_speed_kmh,omitempty"`
|
WindSpeedKmh *int `json:"wind_speed_kmh,omitempty"`
|
||||||
WindSpeedMph *float64 `json:"wind_speed_mph,omitempty"`
|
WindSpeedMph *int `json:"wind_speed_mph,omitempty"`
|
||||||
WindDirection string `json:"wind_direction,omitempty"`
|
WindDirection string `json:"wind_direction,omitempty"`
|
||||||
WindDirectionText string `json:"wind_direction_text,omitempty"`
|
WindDirectionText string `json:"wind_direction_text,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -32,15 +32,15 @@ func buildCurrentConditionsModule(ctx ModuleContext, _ any) (*module.Output, err
|
|||||||
ConditionText: current.ConditionText,
|
ConditionText: current.ConditionText,
|
||||||
ConditionTextLower: strings.ToLower(current.ConditionText),
|
ConditionTextLower: strings.ToLower(current.ConditionText),
|
||||||
IsDay: copyBool(current.IsDay),
|
IsDay: copyBool(current.IsDay),
|
||||||
TemperatureC: copyFloat(current.TemperatureC),
|
TemperatureC: roundedInt(current.TemperatureC),
|
||||||
TemperatureF: copyFloat(current.TemperatureF),
|
TemperatureF: roundedInt(current.TemperatureF),
|
||||||
ApparentTemperatureC: copyFloat(current.ApparentTemperatureC),
|
ApparentTemperatureC: roundedInt(current.ApparentTemperatureC),
|
||||||
ApparentTemperatureF: copyFloat(current.ApparentTemperatureF),
|
ApparentTemperatureF: roundedInt(current.ApparentTemperatureF),
|
||||||
DewpointC: copyFloat(current.DewpointC),
|
DewpointC: roundedInt(current.DewpointC),
|
||||||
DewpointF: copyFloat(current.DewpointF),
|
DewpointF: roundedInt(current.DewpointF),
|
||||||
RelativeHumidityPercent: copyFloat(current.RelativeHumidityPercent),
|
RelativeHumidityPercent: roundedInt(current.RelativeHumidityPercent),
|
||||||
WindSpeedKmh: copyFloat(current.WindSpeedKmh),
|
WindSpeedKmh: roundedInt(current.WindSpeedKmh),
|
||||||
WindSpeedMph: copyFloat(current.WindSpeedMph),
|
WindSpeedMph: roundedInt(current.WindSpeedMph),
|
||||||
WindDirection: windDirectionLabel(current.WindDirectionDegrees),
|
WindDirection: windDirectionLabel(current.WindDirectionDegrees),
|
||||||
WindDirectionText: windDirectionTextLabel(current.WindDirectionDegrees),
|
WindDirectionText: windDirectionTextLabel(current.WindDirectionDegrees),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,10 +151,10 @@ func testSnapshot(t *testing.T) module.Snapshot {
|
|||||||
Value: briefing.CurrentConditionsModule{
|
Value: briefing.CurrentConditionsModule{
|
||||||
ConditionText: "Partly cloudy",
|
ConditionText: "Partly cloudy",
|
||||||
ConditionTextLower: "partly cloudy",
|
ConditionTextLower: "partly cloudy",
|
||||||
TemperatureF: floatPtr(74),
|
TemperatureF: intPtr(74),
|
||||||
ApparentTemperatureF: floatPtr(76),
|
ApparentTemperatureF: intPtr(76),
|
||||||
RelativeHumidityPercent: floatPtr(71),
|
RelativeHumidityPercent: intPtr(71),
|
||||||
WindSpeedMph: floatPtr(8),
|
WindSpeedMph: intPtr(8),
|
||||||
WindDirection: "S",
|
WindDirection: "S",
|
||||||
WindDirectionText: "south",
|
WindDirectionText: "south",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -70,12 +70,12 @@ func TestRenderHourly(t *testing.T) {
|
|||||||
CurrentConditions: &testCurrentConditions{
|
CurrentConditions: &testCurrentConditions{
|
||||||
ConditionText: "Partly cloudy",
|
ConditionText: "Partly cloudy",
|
||||||
ConditionTextLower: "partly cloudy",
|
ConditionTextLower: "partly cloudy",
|
||||||
TemperatureF: floatPtr(74),
|
TemperatureF: intPtr(74),
|
||||||
ApparentTemperatureF: floatPtr(76),
|
ApparentTemperatureF: intPtr(76),
|
||||||
RelativeHumidityPercent: floatPtr(71),
|
RelativeHumidityPercent: intPtr(71),
|
||||||
WindDirection: "S",
|
WindDirection: "S",
|
||||||
WindDirectionText: "south",
|
WindDirectionText: "south",
|
||||||
WindSpeedMph: floatPtr(8),
|
WindSpeedMph: intPtr(8),
|
||||||
},
|
},
|
||||||
HourlyForecast: &testHourlyForecast{
|
HourlyForecast: &testHourlyForecast{
|
||||||
Periods: []testHourlyPeriod{
|
Periods: []testHourlyPeriod{
|
||||||
@@ -157,7 +157,7 @@ func TestRenderHourlyOmitsConditionalSectionsForClearWeather(t *testing.T) {
|
|||||||
Modules: testModules{
|
Modules: testModules{
|
||||||
CurrentConditions: &testCurrentConditions{
|
CurrentConditions: &testCurrentConditions{
|
||||||
ConditionTextLower: "cloudy",
|
ConditionTextLower: "cloudy",
|
||||||
TemperatureF: floatPtr(72),
|
TemperatureF: intPtr(72),
|
||||||
},
|
},
|
||||||
HourlyForecast: &testHourlyForecast{
|
HourlyForecast: &testHourlyForecast{
|
||||||
Periods: []testHourlyPeriod{
|
Periods: []testHourlyPeriod{
|
||||||
@@ -237,10 +237,10 @@ type testModules struct {
|
|||||||
type testCurrentConditions struct {
|
type testCurrentConditions struct {
|
||||||
ConditionText string
|
ConditionText string
|
||||||
ConditionTextLower string
|
ConditionTextLower string
|
||||||
TemperatureF *float64
|
TemperatureF *int
|
||||||
ApparentTemperatureF *float64
|
ApparentTemperatureF *int
|
||||||
RelativeHumidityPercent *float64
|
RelativeHumidityPercent *int
|
||||||
WindSpeedMph *float64
|
WindSpeedMph *int
|
||||||
WindDirection string
|
WindDirection string
|
||||||
WindDirectionText string
|
WindDirectionText string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user