UNPKG

thermostat-pi-dht

Version:

A Node.js framework (standalone app + lib) to control a heating system with a Raspberry Pi using DHT11 or DHT22/AM2302 sensors and GPIO actuators.

43 lines 1.8 kB
"use strict"; // Project: thermostat-pi-dht // File: getRemoteThermostatData.ts // // Copyright 2021 Henning Kerstan // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.getRemoteThermostatData = void 0; const hmac_authenticated_payload_1 = require("@henningkerstan/hmac-authenticated-payload"); const httpGetJSON_1 = require("./httpGetJSON"); async function getRemoteThermostatData(options) { // get const result = await (0, httpGetJSON_1.httpGetJSON)({ host: options.host, port: options.port, path: '/data.json', }); // parse the result as JSON // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const resultObject = JSON.parse(result); // create an HMACAuthenticatedData from the received result const ad = new hmac_authenticated_payload_1.HMACAuthenticatedPayload(resultObject.payload, resultObject.nonce, resultObject.hmac); // validate the hmac if (!ad.validate(options.hmacKey)) { console.log('FEILADE VALIDATION'); return Promise.reject(); } // interpret the received data return ad.payload; } exports.getRemoteThermostatData = getRemoteThermostatData; //# sourceMappingURL=getRemoteThermostatData.js.map