From 933aff47b14646892bbf77410a5eb434403fa74b Mon Sep 17 00:00:00 2001 From: Andrew Kreps Date: Mon, 4 Jul 2016 09:21:13 -0700 Subject: [PATCH] Added some text to !windows. --- lib/lita/handlers/forecasts.rb | 22 ++++++++++++++++++++-- lita-onewheel-forecast-io.gemspec | 2 +- spec/lita/handlers/forecast_io_spec.rb | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/lita/handlers/forecasts.rb b/lib/lita/handlers/forecasts.rb index 0a371d5..cd4d94d 100644 --- a/lib/lita/handlers/forecasts.rb +++ b/lib/lita/handlers/forecasts.rb @@ -463,26 +463,44 @@ def do_the_tomorrow_thing(forecast) # Check for the time of day when it will hit 72F. def do_the_windows_thing(forecast) time_to_close_the_windows = nil + time_to_open_the_windows = nil + window_close_temp = 0 + high_temp = 0 + forecast['hourly']['data'].each_with_index do |hour, index| tm = Time.at(hour['time']).to_datetime.strftime('%k:%M') puts "#{hour['time']} - #{tm} - #{hour['temperature']}" + + if hour['temperature'].to_i > high_temp + high_temp = hour['temperature'].to_i + end + if hour['temperature'].to_i >= 71 puts "Setting close time to #{hour['time']}" time_to_close_the_windows = hour['time'] + window_close_temp = hour['temperature'] break end + if time_to_close_the_windows and hour['temperature'].to_i < 71 + time_to_open_the_windows = hour['time'] + end break if index > 12 end # Return some meta here and let the caller decide the text. if time_to_close_the_windows.nil? - "Leave 'em open, no excess heat today." + "Leave 'em open, no excess heat today(#{high_temp}°F)." else timezone = TZInfo::Timezone.get('America/Los_Angeles') time_at = Time.at(time_to_close_the_windows).to_datetime local_time = timezone.utc_to_local(time_at) - "Close the windows at #{local_time.strftime('%k:%M')}." + output = "Close the windows at #{local_time.strftime('%k:%M')}, it will be #{window_close_temp}°F. " + if time_to_open_the_windows + open_time = timezone.utc_to_local(Time.at(time_to_close_the_windows).to_datetime) + output += "Open them back up at #{open_time.strftime('%k:%M')}. " + end + output += "The high today will be #{high_temp}°F." end end end diff --git a/lita-onewheel-forecast-io.gemspec b/lita-onewheel-forecast-io.gemspec index b0519ef..ae07c2c 100644 --- a/lita-onewheel-forecast-io.gemspec +++ b/lita-onewheel-forecast-io.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'lita-onewheel-forecast-io' - spec.version = '1.3.7' + spec.version = '1.3.8' spec.authors = ['Andrew Kreps'] spec.email = ['andrew.kreps@gmail.com'] spec.description = <<-EOS diff --git a/spec/lita/handlers/forecast_io_spec.rb b/spec/lita/handlers/forecast_io_spec.rb index de1221b..dfce3b3 100644 --- a/spec/lita/handlers/forecast_io_spec.rb +++ b/spec/lita/handlers/forecast_io_spec.rb @@ -513,7 +513,7 @@ def mock_up(filename) it '!windows' do mock_up 'windows' send_command 'windows' - expect(replies.last).to eq('Close the windows at 16:00.') + expect(replies.last).to eq('Close the windows at 16:00, it will be 72°F. The high today will be 72°F.') end # it 'colors strings' do