Actually cache the new sunrise/sunset data of the correct day

This commit is contained in:
Paul van Tilburg 2015-09-22 19:38:48 +02:00
parent 48004beb92
commit cb245ba880
1 changed files with 4 additions and 3 deletions

View File

@ -131,9 +131,10 @@ module Hued
# Retrieve new sunrise/sunset data if cache is too old
if @@sun_data.nil? or @@sun_data[:day] != Date.today
lat, lon = cond_value
url = "http://api.sunrise-sunset.org/json?lat=%s&lng=%s&formatted=0" %
[lat, lon]
@log.debug "Retreiving sunrise/sunset data from #{url}..."
today = Date.today.strftime("%Y-%m-%d")
url = "http://api.sunrise-sunset.org/json?lat=%s&lng=%s&date=%s&formatted=0" %
[lat, lon, today]
@log.debug "Retreiving sunrise/sunset data from #{url} for #{today}..."
begin
data = Net::HTTP.get(URI(url))
json_data = JSON(data)