turn on and off hot water
This commit is contained in:
parent
ddf2aad2db
commit
32f1041a85
@ -2,18 +2,18 @@ const got = require('got')
|
||||
const token = require('basic-auth-token');
|
||||
|
||||
module.exports = {
|
||||
postRequest: async () => {
|
||||
postRequest: async (body, url) => {
|
||||
const authToken = token(process.env.username, process.env.password)
|
||||
const options = {
|
||||
method: 'POST',
|
||||
json: {},
|
||||
json: JSON.parse(body),
|
||||
headers: {
|
||||
"User-Agent-Wiser": "iPhoneTestTool;iOS6;WiserApp2.0.0",
|
||||
"Authorization": "Basic " + authToken
|
||||
}
|
||||
}
|
||||
try {
|
||||
const response = await got('https://public.wcs.schneider-electric.ws/rpc/public_genie/poll', options);
|
||||
const response = await got('https://public.wcs.schneider-electric.ws/rpc/public_genie/' + url, options);
|
||||
const res = JSON.parse(response.body)
|
||||
return res
|
||||
} catch (error) {
|
||||
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -419,11 +419,6 @@
|
||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz",
|
||||
"integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ=="
|
||||
},
|
||||
"numeral": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/numeral/-/numeral-2.0.6.tgz",
|
||||
"integrity": "sha1-StCAk21EPCVhrtnyGX7//iX05QY="
|
||||
},
|
||||
"on-finished": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
|
||||
|
@ -14,8 +14,9 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"basic-auth-token": "^0.4.2",
|
||||
"body-parser": "^1.19.0",
|
||||
"express": "^4.17.1",
|
||||
"fs": "0.0.1-security",
|
||||
"got": "^11.1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ const common = require('../lib/common')
|
||||
|
||||
module.exports = function (app) {
|
||||
app.get("/heating", async function (req, res, next) {
|
||||
const response = await post.postRequest()
|
||||
const response = await post.postRequest('{}', 'poll')
|
||||
const heating = response.updateData.zones[0]
|
||||
res.json(heating)
|
||||
});
|
||||
|
||||
app.get("/heating/status", async function (req, res, next) {
|
||||
const response = await post.postRequest()
|
||||
const response = await post.postRequest('{}', 'poll')
|
||||
const heating = response.updateData.zones[0].status
|
||||
const mrt = await common.updateTemp(heating)
|
||||
const on = await common.heatingOn(heating)
|
||||
@ -27,7 +27,7 @@ module.exports = function (app) {
|
||||
});
|
||||
|
||||
app.get("/heating/config", async function (req, res, next) {
|
||||
const response = await post.postRequest()
|
||||
const response = await post.postRequest('{}', 'poll')
|
||||
const heating = response.updateData.zones[0].config
|
||||
res.json(heating)
|
||||
});
|
11
routes/heating_post.js
Normal file
11
routes/heating_post.js
Normal file
@ -0,0 +1,11 @@
|
||||
const post = require('../lib/post')
|
||||
const common = require('../lib/common')
|
||||
|
||||
module.exports = function (app) {
|
||||
app.post("/heating", async function (req, res, next) {
|
||||
const response = await post.postRequest('{}')
|
||||
const heating = response.updateData.zones[0]
|
||||
res.json(heating)
|
||||
});
|
||||
|
||||
}
|
@ -3,13 +3,13 @@ const common = require('../lib/common')
|
||||
|
||||
module.exports = function (app) {
|
||||
app.get("/water", async function (req, res, next) {
|
||||
const response = await post.postRequest()
|
||||
const response = await post.postRequest('{}', 'poll')
|
||||
const water = response.updateData.zones[1]
|
||||
res.json(water)
|
||||
});
|
||||
|
||||
app.get("/water/status", async function (req, res, next) {
|
||||
const response = await post.postRequest()
|
||||
const response = await post.postRequest('{}', 'poll')
|
||||
const water = response.updateData.zones[1].status
|
||||
const on = await common.heatingOn(water)
|
||||
|
||||
@ -23,7 +23,7 @@ module.exports = function (app) {
|
||||
});
|
||||
|
||||
app.get("/water/config", async function (req, res, next) {
|
||||
const response = await post.postRequest()
|
||||
const response = await post.postRequest('{}', 'poll')
|
||||
const water = response.updateData.zones[1].config
|
||||
res.json(water)
|
||||
});
|
19
routes/water_post.js
Normal file
19
routes/water_post.js
Normal file
@ -0,0 +1,19 @@
|
||||
const post = require('../lib/post')
|
||||
const common = require('../lib/common')
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
module.exports = function (app) {
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
|
||||
app.post("/water", async function (req, res, next) {
|
||||
if (req.query.switch === '1') {
|
||||
await post.postRequest('{"zoneId":[1],"setPoint": 255,"durationMinutes": 90}', 'apply_timer')
|
||||
} else if (req.query.switch === '0') {
|
||||
await post.postRequest('{"zoneId":[1]}', 'cancel_timer')
|
||||
} else {
|
||||
throw new Error
|
||||
}
|
||||
res.json(req.query)
|
||||
});
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user