"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Room = void 0;
const axios = require('axios');
const memoize = require("memoizee");
const utils_1 = require("./utils");
require('dotenv').config();
const apiURL = process.env.ROOM_API_CALL || null;
if (apiURL === null) {
    console.log("Missing value for ROOM_API_CALL in .env file");
    process.exit();
}
var loadApi = async function () {
    try {
        let retries = 3;
        let temperature = null;
        while (retries > 0) {
            retries--;
            const res = await axios.get(apiURL, {
                headers: { "Accept-Encoding": "gzip,deflate,compress" }
            });
            if (res.status == 200) {
                temperature = res.data.temperature;
                retries = 0;
            }
            else {
                console.log("API GET ERROR CODE: ", res.status);
                await (0, utils_1.randomSleep)(1500, 8000);
            }
        }
        return temperature;
    }
    catch (err) {
        console.log(apiURL + " => " + err.message);
    }
    return null;
};
const memoized = memoize(loadApi, { maxAge: 10000 }); // 10 seconds cache
class Room {
    async getTemperature() {
        return memoized();
    }
}
exports.Room = Room;
//# sourceMappingURL=room.js.map