UNPKG

huawei-wingle-4g

Version:

This is a module NodeJS allowing to drive Huawei Wingle 4G. This module can :

50 lines 2.58 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const log4js_1 = __importDefault(require("log4js")); const StringUtils_1 = require("../../utils/StringUtils"); const WlanStatus_1 = require("../../model/home/WlanStatus"); class default_1 { constructor(connection) { this.connection = connection; this.logger = log4js_1.default.getLogger(StringUtils_1.substringAfter(__filename, 'huawei-wingle-4g')); } activeLog(activeLog) { this.logger.level = activeLog ? 'debug' : 'OFF'; this.connection.activeLog(activeLog); } getWlanInformation() { var _a, _b; return __awaiter(this, void 0, void 0, function* () { yield this.connection.openHomePage(); const response = yield this.connection.get('/api/monitoring/status'); const document = response.document; const wifiStatus = (_a = document.querySelector('WifiStatus')) === null || _a === void 0 ? void 0 : _a.textContent; if (!wifiStatus) { throw new Error('Unable to retrieve WLAN state'); } const currentWifiUser = (_b = document.querySelector('CurrentWifiUser')) === null || _b === void 0 ? void 0 : _b.textContent; if (!currentWifiUser) { throw new Error('Unable to retrieve users count'); } const status = wifiStatus === '1' ? WlanStatus_1.WlanStatus.ON : WlanStatus_1.WlanStatus.OFF; this.logger.debug(`State : ${status}`); const users = +currentWifiUser; this.logger.debug(`Users : ${users}`); return { status, users }; }); } } exports.default = default_1; //# sourceMappingURL=WlanStatusExtractor.js.map