From c48848453954e2765b4f0eb6aba479cb7e1ca25a Mon Sep 17 00:00:00 2001 From: Pete ba Date: Sat, 18 May 2019 18:56:31 +0100 Subject: [PATCH 1/6] rmloeb feedback --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1a247fa..ba0ed10 100644 --- a/README.md +++ b/README.md @@ -115,16 +115,14 @@ pi@OSPi:~/weather $ systemctl status weather.service The final line above checks that the service has been started and you should see the service marked as running. -**Step 7:** You can now test that the service is running correctly from a Web Browser. - -Firstly, ensure that the Weather Service is up and running by navigating to the service (note: the default port was set to 3000 in the .env file): +**Step 7:** You can now test that the service is running correctly from a Web Browser by navigating to the service (note: the default port was set to 3000 in the .env file): ``` http:/// ``` You should see "OpenSprinkler Weather Service" in response. -Secondly, you can use the following request to see the watering level that the Weather Service calculates. Note: to be consistent, change the values of h, t and r to the % weightings and bh (as a %), bt (in F), bp (in inches) to the offsets from the Zimmerman config page in App. +You can use the following request to see the watering level that the Weather Service calculates. Note: to be consistent, change the values of h, t and r to the % weightings and bh (as a %), bt (in F), bp (in inches) to the offsets from the Zimmerman config page in App. ``` http://:3000/weather1.py?loc=50,1&wto="\"h\":100,\"t\":100,\"r\":100,\"bh\":70,\"bt\":59,\"br\":0" @@ -135,7 +133,13 @@ This will return a response similar to below with ```scale``` value equating to &scale=20&rd=-1&tz=48&sunrise=268&sunset=1167&eip=3232235787&rawData={"h":47,"p":0,"t":54.4,"raining":0} ``` -**Step 8:** You will now need to configure your OpenSprinkler device to use the local version of the Weather Service rather than the Cloud version. On a web browser from your PC, go to `http://:8080/su` and specify “localhost:3000” as the new location for the weather service. +**Step 8:** You will now need to configure your OpenSprinkler device to use the local version of the Weather Service rather than the Cloud version. + +- For OS users, go to `http:///su` on your web browser + +- For OSPi users, go to `http://:8080/su` on your web browser + +In the **Weather** text field, specify the IP of your Weather Service server and Port, e.g. for OSPi users this might be “localhost:3000” if the Weather Service is running on the same Raspberry Pi. OpenSprinkler should now be connected to your local Weather Service for calculating rain delay and watering levels. From 9bbb41421f514eb0cdc8b2f3fb86fb732b9d9954 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 19 May 2019 10:37:17 -0500 Subject: [PATCH 2/6] Fix unit tests by mocking the date --- package-lock.json | 5 +++++ package.json | 1 + routes/weather.spec.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/package-lock.json b/package-lock.json index 03017da..322f555 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 1240f6a..573c91a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,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" }, diff --git a/routes/weather.spec.ts b/routes/weather.spec.ts index 7513466..87cede5 100644 --- a/routes/weather.spec.ts +++ b/routes/weather.spec.ts @@ -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(); From e3c7c74e298cdd13a4ee4ae0b7b00914cf8fdd06 Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Sun, 19 May 2019 10:43:30 -0500 Subject: [PATCH 3/6] Add deploy task --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 573c91a..536b9f5 100644 --- a/package.json +++ b/package.json @@ -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": { From 1313e170fb6dcf0afa8f823f8f21293892829941 Mon Sep 17 00:00:00 2001 From: Matthew Oslan Date: Thu, 23 May 2019 11:53:52 -0400 Subject: [PATCH 4/6] Don't fetch WateringData if manual watering mode is being used --- routes/weather.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/weather.ts b/routes/weather.ts index aa1f7e1..f24f5f9 100644 --- a/routes/weather.ts +++ b/routes/weather.ts @@ -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); } From 10c3a6738799ef6d18bdee63da32bfea46f7ad5c Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Thu, 23 May 2019 11:08:27 -0500 Subject: [PATCH 5/6] Hide raw data when not used --- routes/weather.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/routes/weather.ts b/routes/weather.ts index f24f5f9..be4f644 100644 --- a/routes/weather.ts +++ b/routes/weather.ts @@ -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 ) : "" ) ); } From 509f9d5b7cb346fcebbf070f978e19942c1dcbae Mon Sep 17 00:00:00 2001 From: Samer Albahra Date: Thu, 23 May 2019 11:13:11 -0500 Subject: [PATCH 6/6] Fix unit testing --- test/expected.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/expected.json b/test/expected.json index 07816b5..4b78b25 100644 --- a/test/expected.json +++ b/test/expected.json @@ -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": {