homebridge-omnik
Version:
Add your Omnik-Inverter to Homekit
69 lines (68 loc) • 2.18 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
class OmnikApi {
constructor(ip, username, password) {
this.ip = ip;
this.username = username;
this.password = password;
}
SplitStatusData(statusData) {
return statusData.split('myDeviceArray[0]')[1].split('";')[0].split(',');
}
async ValidateIp() {
try {
await axios_1.default.get(`http://${this.ip}/`, {
timeout: this.timeout,
auth: {
username: this.username,
password: this.password,
},
});
return true;
}
catch (error) {
return false;
}
}
async GetDeviceInfo() {
try {
const { data } = await axios_1.default.get(`http://${this.ip}/js/status.js`, {
timeout: this.timeout,
auth: {
username: this.username,
password: this.password,
},
});
const statusData = this.SplitStatusData(data);
return {
name: statusData[3],
serial: statusData[0].split('="')[1],
firmware: statusData[2],
};
}
catch (error) { /* noop */ }
}
async GetPowerProduction() {
try {
const { data } = await axios_1.default.get(`http://${this.ip}/js/status.js`, {
timeout: this.timeout,
auth: {
username: this.username,
password: this.password,
},
});
const statusData = this.SplitStatusData(data);
return {
now: parseInt(statusData[5]),
total: parseInt(statusData[7]),
today: parseInt(statusData[6]),
};
}
catch (error) { /* noop */ }
}
}
exports.default = OmnikApi;