"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ewelink = void 0;
const ewelink_api = require('ewelink-api');
require('dotenv').config();
const base_1 = require("./base");
const deviceID = process.env.EWELINK_DEVICE_ID || null;
const email = process.env.EWELINK_EMAIL || null;
const password = process.env.EWELINK_PASSWORD || null;
const region = process.env.EWELINK_REGION || null;
if (deviceID === null || email === null || password === null || region === null) {
    console.log("Missing value for EWELINK DEVICE_ID, EMAIL, PASSWORD and REGION in .env file");
    //process.exit();
}
const connection = new ewelink_api({
    email: email,
    password: password,
    region: region,
});
class Ewelink extends base_1.Base {
    async getStatus() {
        let status;
        try {
            status = await connection.getDevicePowerState(deviceID);
            if (status.error) {
                console.log(status);
            }
        }
        catch (err) {
            console.log(err);
        }
        return status.state;
    }
    async getPowerUsage() {
        let usage;
        try {
            usage = await connection.getDevicePowerUsage(deviceID);
            if (usage.error) {
                console.log(usage);
            }
        }
        catch (err) {
            console.log(err);
        }
        return {
            monthly: usage.monthly,
            daily: usage.daily,
        };
    }
    async setState(state) {
        let status;
        try {
            status = await connection.setDevicePowerState(deviceID, state);
            if (status.error) {
                console.log(status);
            }
        }
        catch (err) {
            console.log(err);
        }
        return status.state;
    }
}
exports.Ewelink = Ewelink;
//# sourceMappingURL=ewelink.js.map