Merge branch 'master' into clarify-instructions

This commit is contained in:
Samer Albahra
2019-05-25 12:16:36 -05:00
committed by GitHub
5 changed files with 19 additions and 12 deletions

5
package-lock.json generated
View File

@@ -2377,6 +2377,11 @@
"integrity": "sha1-mDaL6wnfdT9k9m2U5VNql7NqJDA=",
"dev": true
},
"mockdate": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/mockdate/-/mockdate-2.0.2.tgz",
"integrity": "sha1-WuDA6vj+I+AJzQH5iJtCxPY0rxI="
},
"moment": {
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",

View File

@@ -8,6 +8,7 @@
"start": "node js/server",
"dev": "node scripts/serve",
"bundle": "npm run compile && zip weather.zip -r js package.json package-lock.json",
"deploy": "npm run bundle && eb deploy",
"compile": "tsc"
},
"dependencies": {
@@ -16,6 +17,7 @@
"dotenv": "^8.0.0",
"express": "^4.16.4",
"geo-tz": "^5.0.4",
"mockdate": "^2.0.2",
"moment-timezone": "^0.5.25",
"suncalc": "^1.8.0"
},

View File

@@ -2,6 +2,7 @@ import { expect } from 'chai';
import * as nock from 'nock';
import * as MockExpressRequest from 'mock-express-request';
import * as MockExpressResponse from 'mock-express-response';
import * as MockDate from 'mockdate';
import { getWateringData } from './weather';
@@ -11,6 +12,8 @@ const replies = require( '../test/replies.json' );
const location = '01002';
describe('Watering Data', () => {
beforeEach(() => MockDate.set('5/13/2019'));
it('OpenWeatherMap Lookup (Adjustment Method 0, Location 01002)', async () => {
mockOWM();

View File

@@ -262,7 +262,7 @@ export const getWateringData = async function( req: express.Request, res: expres
let wateringData: WateringData;
if ( local.useLocalWeather() ) {
wateringData = await getLocalWateringData( coordinates );
} else {
} else if ( adjustmentMethod !== 0 ) {
wateringData = await weatherProvider.getWateringData(coordinates);
}
@@ -312,14 +312,17 @@ export const getWateringData = async function( req: express.Request, res: expres
sunrise: timeData.sunrise,
sunset: timeData.sunset,
eip: ipToInt( remoteAddress ),
// TODO this may need to be changed (https://github.com/OpenSprinkler/OpenSprinkler-Weather/pull/11#issuecomment-491037948)
rawData: {
rawData: undefined
};
if ( adjustmentMethod > 0 ) {
data.rawData = {
h: wateringData ? Math.round( wateringData.humidity * 100) / 100 : null,
p: wateringData ? Math.round( wateringData.precip * 100 ) / 100 : null,
t: wateringData ? Math.round( wateringData.temp * 10 ) / 10 : null,
raining: wateringData ? ( wateringData.raining ? 1 : 0 ) : null
}
};
}
if ( local.useLocalWeather() ) {
console.log( "OpenSprinkler Weather Response: %s", JSON.stringify( data ) );
@@ -335,7 +338,7 @@ export const getWateringData = async function( req: express.Request, res: expres
"&sunrise=" + data.sunrise +
"&sunset=" + data.sunset +
"&eip=" + data.eip +
"&rawData=" + JSON.stringify( data.rawData )
( adjustmentMethod > 0 ? "&rawData=" + JSON.stringify( data.rawData ) : "" )
);
}

View File

@@ -6,13 +6,7 @@
"tz": 32,
"sunrise": 332,
"sunset": 1203,
"eip": 2130706433,
"rawData": {
"h": 98.5,
"p": 1.09,
"t": 70.8,
"raining": 1
}
"eip": 2130706433
}
},
"adjustment1": {