Skip to content

Commit

Permalink
add mph to hourly weather events
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Hawksley committed May 4, 2024
1 parent 72faa1e commit f6e6cf2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/weather_kit_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ def self.hourly_calendar_events

next if !weather_hour.present?

wind_suffix = if weather_hour["windGust"].to_f > 20
" / #{weather_hour["windGust"].round}mph"
end

CalendarEvent.new(
id: "_weather_hour_#{hour.to_i}",
starts_at: hour,
ends_at: hour,
icon: icon_for(weather_hour["conditionCode"]),
summary: "#{celsius_fahrenheit(weather_hour["temperature"])}°".html_safe
summary: "#{celsius_fahrenheit(weather_hour["temperature"])}°#{wind_suffix}".html_safe
)
end.compact
end
Expand Down
19 changes: 19 additions & 0 deletions test/models/weather_kit_account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,25 @@ def test_calendar_events_example
end
end

def test_wind_hourly_calendar_event
weather = {
"forecastHourly" => {
"hours" => [
{"temperature" => 20.83,
"conditionCode" => "Clear",
"forecastStart" => "2023-08-27T18:00:00Z",
"precipitationType" => "clear",
"windGust"=>31.15,}]
}
}

WeatherKitAccount.stub :weather, weather do
travel_to DateTime.new(2023, 8, 27, 16, 20, 0, "-0600") do
assert(WeatherKitAccount.hourly_calendar_events.last.summary.include?("31mph"))
end
end
end

def test_precip_calendar_events_no_data
WeatherKitAccount.stub :weather, {} do
assert_equal([], WeatherKitAccount.precip_calendar_events)
Expand Down

0 comments on commit f6e6cf2

Please sign in to comment.