From 22d7fa58922dafd6e5739d8757de2756a2adba54 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 16:04:00 -0500 Subject: [PATCH 01/16] Add OpenWeatherMap and set it as the default when no key is provided --- routes/weather.js | 73 ++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index e678dbd..b2a2a65 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -218,6 +218,45 @@ function getYesterdayWeatherData( location, callback ) { } ); } +// Retrieve weather data from Open Weather Map +function getOWMWeatherData( location, callback ) { + + // Generate URL using The Weather Company API v1 in Imperial units + var OWM_API_KEY = process.env.OWM_API_KEY, + url = "http://api.openweathermap.org/data/2.5/weather?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ]; + + // Perform the HTTP request to retrieve the weather data + httpRequest( url, function( data ) { + console.log( url ); + try { + data = JSON.parse( data ); + var weather = { + timezone: timezone, + sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ), + sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ), + temp: parseInt( data.main.temp ), + humidity: parseInt( data.main.humidity ), + wind: parseInt( data.wind.speed ) + }; + + location = location.join( "," ); + + getCache( { + key: "yesterdayHumidity", + location: location, + weather: weather, + callback: callback + } ); + + updateCache( location, weather ); + } catch ( err ) { + + // Otherwise indicate the request failed + callback( false ); + } + } ); +} + // Calculate timezone and sun rise/set information function getTimeData( location, callback ) { timezoner.getTimeZone( @@ -406,7 +445,7 @@ exports.getWeather = function( req, res ) { // and also calculate if a restriction is met to prevent watering. finishRequest = function( weather ) { if ( !weather ) { - res.send( "Error: No weather data found." ); + getTimeData( location, finishRequest ); return; } @@ -494,14 +533,13 @@ exports.getWeather = function( req, res ) { return; } else if ( filters.gps.test( location ) ) { - // Handle GPS coordinates by storing each coordinate in an array - location = location.split( "," ); - location = [ parseFloat( location[ 0 ] ), parseFloat( location[ 1 ] ) ]; + // Handle GPS coordinates by storing each coordinate in an array + location = location.split( "," ); + location = [ parseFloat( location[ 0 ] ), parseFloat( location[ 1 ] ) ]; - // Continue with the weather request - getTimeData( location, finishRequest ); - - } else { + // Continue with the weather request + getOWMWeatherData( location, finishRequest ); + } else { // Attempt to resolve provided location to GPS coordinates when it does not match // a GPS coordinate or Weather Underground location using Weather Underground autocomplete @@ -512,24 +550,7 @@ exports.getWeather = function( req, res ) { } location = result; - getWeatherData( location, function( weather ) { - if ( !weather ) { - var tzOffset = getTimezone( timezone, "minutes" ), - - // Calculate sunrise and sunset since Weather Underground does not provide it - sunData = SunCalc.getTimes( new Date(), location[ 0 ], location[ 1 ] ); - - sunData.sunrise.setUTCMinutes( sunData.sunrise.getUTCMinutes() + tzOffset ); - sunData.sunset.setUTCMinutes( sunData.sunset.getUTCMinutes() + tzOffset ); - - weather = { - timezone: timezone, - sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ), - sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ) - }; - } - finishRequest( weather ); - } ); + getOWMWeatherData( location, finishRequest ); } ); } }; From 9f32feee427a8016ef9f7c2d6b23cd000f5f68ac Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 16:06:00 -0500 Subject: [PATCH 02/16] Remove debugging code --- routes/weather.js | 1 - 1 file changed, 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index b2a2a65..8031107 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -227,7 +227,6 @@ function getOWMWeatherData( location, callback ) { // Perform the HTTP request to retrieve the weather data httpRequest( url, function( data ) { - console.log( url ); try { data = JSON.parse( data ); var weather = { From d19f121559666b1f6209118fd197e6a7691c190d Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 16:07:40 -0500 Subject: [PATCH 03/16] Fix spacing issue --- routes/weather.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 8031107..5d7d584 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -532,12 +532,12 @@ exports.getWeather = function( req, res ) { return; } else if ( filters.gps.test( location ) ) { - // Handle GPS coordinates by storing each coordinate in an array - location = location.split( "," ); - location = [ parseFloat( location[ 0 ] ), parseFloat( location[ 1 ] ) ]; + // Handle GPS coordinates by storing each coordinate in an array + location = location.split( "," ); + location = [ parseFloat( location[ 0 ] ), parseFloat( location[ 1 ] ) ]; - // Continue with the weather request - getOWMWeatherData( location, finishRequest ); + // Continue with the weather request + getOWMWeatherData( location, finishRequest ); } else { // Attempt to resolve provided location to GPS coordinates when it does not match From e938f57c3ccf4bb5af6a5fe8adfc8a604a5abe1d Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 16:27:08 -0500 Subject: [PATCH 04/16] Fix issue retrieving timezone data for OpenWeather Map --- routes/weather.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 5d7d584..704b1a3 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -229,14 +229,15 @@ function getOWMWeatherData( location, callback ) { httpRequest( url, function( data ) { try { data = JSON.parse( data ); - var weather = { - timezone: timezone, - sunrise: ( sunData.sunrise.getUTCHours() * 60 + sunData.sunrise.getUTCMinutes() ), - sunset: ( sunData.sunset.getUTCHours() * 60 + sunData.sunset.getUTCMinutes() ), - temp: parseInt( data.main.temp ), - humidity: parseInt( data.main.humidity ), - wind: parseInt( data.wind.speed ) - }; + } catch ( err ) { + // Otherwise indicate the request failed + callback( false ); + } + + getTimeData( location, function( weather ) { + weather.temp = parseInt( data.main.temp ); + weather.humidity = parseInt( data.main.humidity ); + weather.wind = parseInt( data.wind.speed ); location = location.join( "," ); @@ -248,11 +249,7 @@ function getOWMWeatherData( location, callback ) { } ); updateCache( location, weather ); - } catch ( err ) { - - // Otherwise indicate the request failed - callback( false ); - } + } ); } ); } From aa266d5d8b539e5ac950bcf9c22dab8841f0fca0 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 17:00:25 -0500 Subject: [PATCH 05/16] Fix missing precip data from OpenWeatherMap --- routes/weather.js | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 704b1a3..bfb1220 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -223,34 +223,37 @@ function getOWMWeatherData( location, callback ) { // Generate URL using The Weather Company API v1 in Imperial units var OWM_API_KEY = process.env.OWM_API_KEY, - url = "http://api.openweathermap.org/data/2.5/weather?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ]; + currentUrl = "http://api.openweathermap.org/data/2.5/weather?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ], + forecastUrl = "http://api.openweathermap.org/data/2.5/forecast?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ]; - // Perform the HTTP request to retrieve the weather data - httpRequest( url, function( data ) { - try { - data = JSON.parse( data ); - } catch ( err ) { - // Otherwise indicate the request failed - callback( false ); - } + getTimeData( location, function( weather ) { + + // Perform the HTTP request to retrieve the weather data + httpRequest( currentUrl, function( data ) { + try { + data = JSON.parse( data ); + } catch ( err ) { + // Otherwise indicate the request failed + callback( weather ); + } - getTimeData( location, function( weather ) { weather.temp = parseInt( data.main.temp ); weather.humidity = parseInt( data.main.humidity ); weather.wind = parseInt( data.wind.speed ); - location = location.join( "," ); + httpRequest( forecastUrl, function( forecastData ) { + try { + forecastData = JSON.parse( forecastData ); + weather.precip = forecastData.list[ 0 ].rain[ "3h" ]; + callback( weather ); + } catch ( err ) { - getCache( { - key: "yesterdayHumidity", - location: location, - weather: weather, - callback: callback + // Otherwise indicate the request failed + callback( weather ); + } } ); - - updateCache( location, weather ); } ); - } ); + } ); } // Calculate timezone and sun rise/set information From b332eaaf14edf5238d41120cf7c30606b9f5e6c4 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 17:06:23 -0500 Subject: [PATCH 06/16] Improve request to OWM --- routes/weather.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index bfb1220..304565e 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -223,13 +223,12 @@ function getOWMWeatherData( location, callback ) { // Generate URL using The Weather Company API v1 in Imperial units var OWM_API_KEY = process.env.OWM_API_KEY, - currentUrl = "http://api.openweathermap.org/data/2.5/weather?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ], forecastUrl = "http://api.openweathermap.org/data/2.5/forecast?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ]; getTimeData( location, function( weather ) { // Perform the HTTP request to retrieve the weather data - httpRequest( currentUrl, function( data ) { + httpRequest( forecastUrl, function( data ) { try { data = JSON.parse( data ); } catch ( err ) { @@ -237,21 +236,21 @@ function getOWMWeatherData( location, callback ) { callback( weather ); } - weather.temp = parseInt( data.main.temp ); - weather.humidity = parseInt( data.main.humidity ); - weather.wind = parseInt( data.wind.speed ); + weather.temp = parseInt( data.list[ 0 ].main.temp ); + weather.humidity = parseInt( data.list[ 0 ].main.humidity ); + weather.wind = parseInt( data.list[ 0 ].wind.speed ); + weather.precip = data.list[ 0 ].rain[ "3h" ]; - httpRequest( forecastUrl, function( forecastData ) { - try { - forecastData = JSON.parse( forecastData ); - weather.precip = forecastData.list[ 0 ].rain[ "3h" ]; - callback( weather ); - } catch ( err ) { + location = location.join( "," ); - // Otherwise indicate the request failed - callback( weather ); - } + getCache( { + key: "yesterdayHumidity", + location: location, + weather: weather, + callback: callback } ); + + updateCache( location, weather ); } ); } ); } From 4637ac0fbe6bf5372b9c75e826d1f300aa6b676d Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 17:07:30 -0500 Subject: [PATCH 07/16] Fix the comment --- routes/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index 304565e..8569000 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -221,7 +221,7 @@ function getYesterdayWeatherData( location, callback ) { // Retrieve weather data from Open Weather Map function getOWMWeatherData( location, callback ) { - // Generate URL using The Weather Company API v1 in Imperial units + // Generate URL using OpenWeatherMap in Imperial units var OWM_API_KEY = process.env.OWM_API_KEY, forecastUrl = "http://api.openweathermap.org/data/2.5/forecast?appid=" + OWM_API_KEY + "&units=imperial&lat=" + location[ 0 ] + "&lon=" + location[ 1 ]; From 10bcbfe835388833015c6df1c8c2b1936f0f7e9a Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 17:09:40 -0500 Subject: [PATCH 08/16] Parse the float correctly instead of using as string --- routes/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index 8569000..cb2d25a 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -239,7 +239,7 @@ function getOWMWeatherData( location, callback ) { weather.temp = parseInt( data.list[ 0 ].main.temp ); weather.humidity = parseInt( data.list[ 0 ].main.humidity ); weather.wind = parseInt( data.list[ 0 ].wind.speed ); - weather.precip = data.list[ 0 ].rain[ "3h" ]; + weather.precip = parseFloat( data.list[ 0 ].rain[ "3h" ] ); location = location.join( "," ); From f0780c2906c7235714bc0a4a87ee72f123d40067 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 20 May 2018 17:58:40 -0500 Subject: [PATCH 09/16] Fix missing precip data from OWM --- routes/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index cb2d25a..caebfb6 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -239,7 +239,7 @@ function getOWMWeatherData( location, callback ) { weather.temp = parseInt( data.list[ 0 ].main.temp ); weather.humidity = parseInt( data.list[ 0 ].main.humidity ); weather.wind = parseInt( data.list[ 0 ].wind.speed ); - weather.precip = parseFloat( data.list[ 0 ].rain[ "3h" ] ); + weather.precip = data.list[ 0 ].rain ? parseFloat( data.list[ 0 ].rain[ "3h" ] ) : ""; location = location.join( "," ); From 222401d03f90cf5b2b9f96e6baf28005f2c8cddc Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 21 May 2018 20:41:28 -0500 Subject: [PATCH 10/16] Update `package-lock.json` --- package-lock.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 89a3529..3dda6d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2811,7 +2811,8 @@ "stringstream": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz", - "integrity": "sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA==" + "integrity": "sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA==", + "dev": true }, "strip-ansi": { "version": "3.0.1", From aba1aee4e800ada855d20ed424f36aa68ee081af Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 21 May 2018 20:45:11 -0500 Subject: [PATCH 11/16] Remove Codecov references --- .travis.yml | 1 - README.md | 2 +- package-lock.json | 305 ---------------------------------------------- package.json | 1 - 4 files changed, 1 insertion(+), 308 deletions(-) diff --git a/.travis.yml b/.travis.yml index cf67f96..77364c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,5 @@ before_script: - grunt after_script: - istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec - - cat coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js notifications: on_failure: change diff --git a/README.md b/README.md index 10e2afd..3ed5abe 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

 OpenSprinkler Weather Service [![GitHub version](https://badge.fury.io/gh/OpenSprinkler%2FOpenSprinkler-Weather.svg)](http://badge.fury.io/gh/OpenSprinkler%2FOpenSprinkler-Weather)

- [![Build Status](https://api.travis-ci.org/OpenSprinkler/OpenSprinkler-Weather.svg?branch=master)](https://travis-ci.org/) [![codecov.io](http://codecov.io/github/OpenSprinkler/OpenSprinkler-Weather/coverage.svg?branch=master)](http://codecov.io/github/OpenSprinkler/OpenSprinkler-Weather?branch=master) [![devDependency Status](https://david-dm.org/OpenSprinkler/OpenSprinkler-Weather/status.svg)](https://david-dm.org/OpenSprinkler/OpenSprinkler-Weather#info=dependencies) + [![Build Status](https://api.travis-ci.org/OpenSprinkler/OpenSprinkler-Weather.svg?branch=master)](https://travis-ci.org/) [![devDependency Status](https://david-dm.org/OpenSprinkler/OpenSprinkler-Weather/status.svg)](https://david-dm.org/OpenSprinkler/OpenSprinkler-Weather#info=dependencies)  [Official Site][official] | [Support][help] | [Changelog][changelog]
This script is used by OpenSprinkler Unified Firmware to update the water level of the device. It also provides timezone information based on user location along with other local information (sunrise, sunset, daylights saving time, etc). diff --git a/package-lock.json b/package-lock.json index 3dda6d6..0f73a88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -100,40 +100,12 @@ "resolved": "https://registry.npmjs.org/array-source/-/array-source-0.0.4.tgz", "integrity": "sha512-frNdc+zBn80vipY+GdcJkLEbMWj3xmzArYApmUGxoiV8uAu/ygcs9icPdsGdA26h0MkHUMW6EN2piIvVx+M5Mw==" }, - "asn1": { - "version": "0.1.11", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.1.11.tgz", - "integrity": "sha1-VZvhg3bQik7E2+gId9J4GGObLfc=", - "dev": true, - "optional": true - }, - "assert-plus": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz", - "integrity": "sha1-7nQAlBMALYTOxyGcasgRgS5yMWA=", - "dev": true, - "optional": true - }, "assertion-error": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.1.tgz", "integrity": "sha1-NaruwzCX8R9COZ7K3zP6zNJ/XEw=", "dev": true }, - "async": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", - "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=", - "dev": true, - "optional": true - }, - "aws-sign2": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.5.0.tgz", - "integrity": "sha1-xXED96F/wDfwLXwuZLYC6iI/fWM=", - "dev": true, - "optional": true - }, "aws4": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.7.0.tgz", @@ -155,15 +127,6 @@ "tweetnacl": "^0.14.3" } }, - "bl": { - "version": "0.9.5", - "resolved": "https://registry.npmjs.org/bl/-/bl-0.9.5.tgz", - "integrity": "sha1-wGt5evCF6gC8Unr8jvzxHeIjIFQ=", - "dev": true, - "requires": { - "readable-stream": "~1.0.26" - } - }, "bluebird": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz", @@ -193,15 +156,6 @@ } } }, - "boom": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/boom/-/boom-0.4.2.tgz", - "integrity": "sha1-emNune1O/O+xnO9JR6PGffrukRs=", - "dev": true, - "requires": { - "hoek": "0.9.x" - } - }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -256,12 +210,6 @@ "map-obj": "^1.0.0" } }, - "caseless": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.6.0.tgz", - "integrity": "sha1-gWfBq4OX+1u5X5bSjlqBxQ8kesQ=", - "dev": true - }, "center-align": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", @@ -349,16 +297,6 @@ } } }, - "codecov.io": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/codecov.io/-/codecov.io-0.1.6.tgz", - "integrity": "sha1-Wd/QLaH/McL7K5Uq2K0W/TeBtyg=", - "dev": true, - "requires": { - "request": "2.42.0", - "urlgrey": "0.4.0" - } - }, "coffeescript": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-1.10.0.tgz", @@ -369,16 +307,6 @@ "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=" }, - "combined-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-0.0.7.tgz", - "integrity": "sha1-ATfmV7qlp1QcV6w3rF/AfXO03B8=", - "dev": true, - "optional": true, - "requires": { - "delayed-stream": "0.0.5" - } - }, "commander": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.3.0.tgz", @@ -476,23 +404,6 @@ "moment-timezone": "^0.5.x" } }, - "cryptiles": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-0.2.2.tgz", - "integrity": "sha1-7ZH/HxetE9N0gohZT4pIoNJvMlw=", - "dev": true, - "optional": true, - "requires": { - "boom": "0.4.x" - } - }, - "ctype": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz", - "integrity": "sha1-gsGMJGH3QRTvFsE1IkrQuRRMoS8=", - "dev": true, - "optional": true - }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", @@ -563,31 +474,12 @@ } } }, - "deep-equal": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.1.2.tgz", - "integrity": "sha1-skbCuApXCkfBG+HZvRBw7IeLh84=", - "dev": true - }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, - "defined": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/defined/-/defined-0.0.0.tgz", - "integrity": "sha1-817qfXBekzuvE7LwOz+D2SFAOz4=", - "dev": true - }, - "delayed-stream": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz", - "integrity": "sha1-1LH0OpPoKW3+AmlPRoC8N6MTxz8=", - "dev": true, - "optional": true - }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -658,12 +550,6 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-2.0.0.tgz", "integrity": "sha1-vXWcNXqqcDZeAclrewvsCKbg2Uk=" }, - "duplexer": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", - "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", - "dev": true - }, "ecc-jsbn": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", @@ -879,24 +765,6 @@ } } }, - "forever-agent": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.5.2.tgz", - "integrity": "sha1-bQ4JxJIflKJ/Y9O0nF/v8epMUTA=", - "dev": true - }, - "form-data": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-0.1.4.tgz", - "integrity": "sha1-kavXiKupcCsaq/qLwBAxoqyeOxI=", - "dev": true, - "optional": true, - "requires": { - "async": "~0.9.0", - "combined-stream": "~0.0.4", - "mime": "~1.2.11" - } - }, "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", @@ -1174,19 +1042,6 @@ "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=", "dev": true }, - "hawk": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/hawk/-/hawk-1.1.1.tgz", - "integrity": "sha1-h81JH5tG5OKurKM1QWdmiF0tHtk=", - "dev": true, - "optional": true, - "requires": { - "boom": "0.4.x", - "cryptiles": "0.2.x", - "hoek": "0.9.x", - "sntp": "0.2.x" - } - }, "he": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", @@ -1426,12 +1281,6 @@ } } }, - "hoek": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/hoek/-/hoek-0.9.1.tgz", - "integrity": "sha1-PTIkYrrfB3Fup+uFuviAec3c5QU=", - "dev": true - }, "hooker": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/hooker/-/hooker-0.2.3.tgz", @@ -1492,18 +1341,6 @@ } } }, - "http-signature": { - "version": "0.10.1", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", - "integrity": "sha1-T72sEyVZqoMjEh5UB3nAoBKyfmY=", - "dev": true, - "optional": true, - "requires": { - "asn1": "0.1.11", - "assert-plus": "^0.1.5", - "ctype": "0.5.3" - } - }, "iconv-lite": { "version": "0.4.19", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", @@ -1731,12 +1568,6 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, - "jsonify": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", - "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", - "dev": true - }, "jsonpointer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", @@ -1868,24 +1699,11 @@ "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, - "mime": { - "version": "1.2.11", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz", - "integrity": "sha1-WCA+7Ybjpe8XrtK32evUfwpg3RA=", - "dev": true, - "optional": true - }, "mime-db": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", "integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==" }, - "mime-types": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-1.0.2.tgz", - "integrity": "sha1-mVrhOSq4r/y/yyZB3QVOlDwNXc4=", - "dev": true - }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -2230,13 +2048,6 @@ "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, - "oauth-sign": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.4.0.tgz", - "integrity": "sha1-8ilW8x6nFRqCHl8vsywRPK2Ln2k=", - "dev": true, - "optional": true - }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2416,12 +2227,6 @@ "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", "dev": true }, - "qs": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-1.2.2.tgz", - "integrity": "sha1-GbV/8k3CqZzh+L32r82ln472H4g=", - "dev": true - }, "range-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", @@ -2485,18 +2290,6 @@ "read-pkg": "^1.0.0" } }, - "readable-stream": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", - "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "0.0.1", - "string_decoder": "~0.10.x" - } - }, "redent": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", @@ -2525,29 +2318,6 @@ "is-finite": "^1.0.0" } }, - "request": { - "version": "2.42.0", - "resolved": "https://registry.npmjs.org/request/-/request-2.42.0.tgz", - "integrity": "sha1-VyvQFIk4VkBArHqxSLlkI6BjMEo=", - "dev": true, - "requires": { - "aws-sign2": "~0.5.0", - "bl": "~0.9.0", - "caseless": "~0.6.0", - "forever-agent": "~0.5.0", - "form-data": "~0.1.0", - "hawk": "1.1.1", - "http-signature": "~0.10.0", - "json-stringify-safe": "~5.0.0", - "mime-types": "~1.0.1", - "node-uuid": "~1.4.0", - "oauth-sign": "~0.4.0", - "qs": "~1.2.0", - "stringstream": "~0.0.4", - "tough-cookie": ">=0.12.0", - "tunnel-agent": "~0.4.0" - } - }, "require_optional": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", @@ -2575,15 +2345,6 @@ "protocol-buffers-schema": "^2.0.2" } }, - "resumer": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", - "integrity": "sha1-8ej0YeQGS6Oegq883CqMiT0HZ1k=", - "dev": true, - "requires": { - "through": "~2.3.4" - } - }, "right-align": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", @@ -2691,16 +2452,6 @@ "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", "integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E=" }, - "sntp": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz", - "integrity": "sha1-+4hfGLDzqtGJ+CSGJTa87ux1CQA=", - "dev": true, - "optional": true, - "requires": { - "hoek": "0.9.x" - } - }, "source-map": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz", @@ -2739,15 +2490,6 @@ "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz", "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==" }, - "split": { - "version": "0.2.10", - "resolved": "https://registry.npmjs.org/split/-/split-0.2.10.tgz", - "integrity": "sha1-Zwl8YB1pfOE2j0GPBs0gHPBSGlc=", - "dev": true, - "requires": { - "through": "2" - } - }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -2788,15 +2530,6 @@ "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" }, - "stream-combiner": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz", - "integrity": "sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ=", - "dev": true, - "requires": { - "duplexer": "~0.1.1" - } - }, "stream-source": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/stream-source/-/stream-source-0.3.5.tgz", @@ -2854,45 +2587,16 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" }, - "tape": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/tape/-/tape-2.3.0.tgz", - "integrity": "sha1-Df7scJIn+8yRcKvn8EaWKycUMds=", - "dev": true, - "requires": { - "deep-equal": "~0.1.0", - "defined": "~0.0.0", - "inherits": "~2.0.1", - "jsonify": "~0.0.0", - "resumer": "~0.0.0", - "split": "~0.2.10", - "stream-combiner": "~0.0.2", - "through": "~2.3.4" - } - }, "text-encoding": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.1.tgz", "integrity": "sha1-TeETDmHVDdhnBAQoqhVlbv3cscg=" }, - "through": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", - "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", - "dev": true - }, "timed-cache": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/timed-cache/-/timed-cache-1.1.0.tgz", "integrity": "sha1-HxQlzCbPrAApTecDEY4vCMBIBeI=" }, - "tough-cookie": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.2.2.tgz", - "integrity": "sha1-yDoYMPTl7wuT7yo0iOck+N4Basc=", - "dev": true, - "optional": true - }, "trim-newlines": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-1.0.0.tgz", @@ -2988,15 +2692,6 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, - "urlgrey": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/urlgrey/-/urlgrey-0.4.0.tgz", - "integrity": "sha1-8GU1cED7NcOzEdTl3DZITZbb6gY=", - "dev": true, - "requires": { - "tape": "2.3.0" - } - }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index dde504a..c898c75 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ }, "devDependencies": { "chai": "^3.0.0", - "codecov.io": "^0.1.5", "grunt-contrib-jshint": "^1.1.0", "hippie": "^0.5.1", "istanbul": "^0.4.5", From 25d1b1ee0b2ce26398c0331b7c117d405a81597f Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 21 May 2018 20:52:18 -0500 Subject: [PATCH 12/16] Fix bug interpretting precipitation data from OpenWeatherMap --- routes/weather.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index 0be0b31..d34c1f6 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -239,7 +239,7 @@ function getOWMWeatherData( location, callback ) { weather.temp = parseInt( data.list[ 0 ].main.temp ); weather.humidity = parseInt( data.list[ 0 ].main.humidity ); weather.wind = parseInt( data.list[ 0 ].wind.speed ); - weather.precip = data.list[ 0 ].rain ? parseFloat( data.list[ 0 ].rain[ "3h" ] ) : ""; + weather.precip = data.list[ 0 ].rain ? parseFloat( data.list[ 0 ].rain[ "3h" ] || 0 ) : ""; location = location.join( "," ); @@ -434,6 +434,8 @@ exports.getWeather = function( req, res ) { return; } + console.log( weather ); + var scale = calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ), rainDelay = -1; From 7699a0a6c80452f174938ea5aac7fe4585936de4 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 21 May 2018 20:54:40 -0500 Subject: [PATCH 13/16] Additional fix for preciption data input --- routes/weather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index d34c1f6..02d7e00 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -239,7 +239,7 @@ function getOWMWeatherData( location, callback ) { weather.temp = parseInt( data.list[ 0 ].main.temp ); weather.humidity = parseInt( data.list[ 0 ].main.humidity ); weather.wind = parseInt( data.list[ 0 ].wind.speed ); - weather.precip = data.list[ 0 ].rain ? parseFloat( data.list[ 0 ].rain[ "3h" ] || 0 ) : ""; + weather.precip = data.list[ 0 ].rain ? parseFloat( data.list[ 0 ].rain[ "3h" ] || 0 ) : 0; location = location.join( "," ); From 92465512301b4323857bd57afb3da7c2b6a3c19d Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 21 May 2018 21:00:39 -0500 Subject: [PATCH 14/16] Fix bug handling unresolved locations --- routes/weather.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 02d7e00..5519f01 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -29,7 +29,7 @@ function resolveCoordinates( location, callback ) { data = JSON.parse( data ); // Check if the data is valid - if ( typeof data.RESULTS === "object" && data.RESULTS.length ) { + if ( typeof data.RESULTS === "object" && data.RESULTS.length && data.RESULTS[ 0 ].tz !== "MISSING" ) { // If it is, reply with an array containing the GPS coordinates callback( [ data.RESULTS[ 0 ].lat, data.RESULTS[ 0 ].lon ], moment().tz( data.RESULTS[ 0 ].tz ).utcOffset() ); @@ -95,8 +95,8 @@ function getWeatherUndergroundData( location, weatherUndergroundKey, callback ) // Otherwise indicate the request failed callback( false ); + return; } - } ); } @@ -137,7 +137,6 @@ function getWxWeatherData( location, callback ) { } ); updateCache( location, weather ); - } ); } ); } @@ -154,7 +153,6 @@ function getWeatherData( location, callback ) { // Perform the HTTP request to retrieve the weather data httpRequest( url, function( data ) { - try { data = JSON.parse( data ); @@ -186,8 +184,8 @@ function getWeatherData( location, callback ) { // Otherwise indicate the request failed callback( false ); + return; } - } ); } @@ -232,8 +230,10 @@ function getOWMWeatherData( location, callback ) { try { data = JSON.parse( data ); } catch ( err ) { + // Otherwise indicate the request failed callback( weather ); + return; } weather.temp = parseInt( data.list[ 0 ].main.temp ); From e76ae423a9ed96721f01d8d4149043f64c0d5f39 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Mon, 21 May 2018 21:03:09 -0500 Subject: [PATCH 15/16] Remove debugging code --- routes/weather.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/routes/weather.js b/routes/weather.js index 5519f01..653f162 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -434,8 +434,6 @@ exports.getWeather = function( req, res ) { return; } - console.log( weather ); - var scale = calculateWeatherScale( adjustmentMethod, adjustmentOptions, weather ), rainDelay = -1; From 6d8c35586931ed6bc41d9631b80fe1b2b363fda5 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Thu, 24 May 2018 08:20:19 -0500 Subject: [PATCH 16/16] Handle no valid data states --- routes/weather.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes/weather.js b/routes/weather.js index 653f162..f22e381 100755 --- a/routes/weather.js +++ b/routes/weather.js @@ -430,7 +430,12 @@ exports.getWeather = function( req, res ) { // and also calculate if a restriction is met to prevent watering. finishRequest = function( weather ) { if ( !weather ) { - getTimeData( location, finishRequest ); + if ( typeof location[ 0 ] === "number" && typeof location[ 1 ] === "number" ) { + getTimeData( location, finishRequest ); + } else { + res.send( "Error: No weather data found." ); + } + return; }