UNPKG

tsvesync

Version:

A TypeScript library for interacting with VeSync smart home devices

82 lines (81 loc) 2.23 kB
"use strict"; /** * VeSync Switch Classes */ Object.defineProperty(exports, "__esModule", { value: true }); exports.VeSyncSwitch = exports.switchConfig = void 0; const vesyncBaseDevice_1 = require("./vesyncBaseDevice"); const logger_1 = require("./logger"); // Switch configuration exports.switchConfig = { 'ESWL01': { module: 'VeSyncWallSwitch', features: [] }, 'ESWD16': { module: 'VeSyncDimmerSwitch', features: ['dimmable'] }, 'ESWL03': { module: 'VeSyncWallSwitch', features: [] } }; /** * Base class for VeSync Switches */ class VeSyncSwitch extends vesyncBaseDevice_1.VeSyncBaseDevice { constructor(details, manager) { var _a; super(details, manager); this.details = {}; this.features = []; this.details = details; this.features = ((_a = exports.switchConfig[this.deviceType]) === null || _a === void 0 ? void 0 : _a.features) || []; } /** * Get active time of switch */ get activeTime() { var _a; return (_a = this.details.active_time) !== null && _a !== void 0 ? _a : 0; } /** * Return true if switch is dimmable */ isDimmable() { return this.features.includes('dimmable'); } /** * Return formatted device info to stdout */ display() { super.display(); const info = [ ['Active Time:', this.activeTime] ]; for (const [key, value] of info) { logger_1.logger.info(`${key.toString().padEnd(30, '.')} ${value}`); } } /** * Return JSON details for switch */ displayJSON() { const baseInfo = JSON.parse(super.displayJSON()); return JSON.stringify({ ...baseInfo, 'Active Time': this.activeTime }, null, 4); } /** * Update switch details */ async update() { logger_1.logger.debug(`[${this.deviceName}] Updating switch information`); const success = await this.getDetails(); logger_1.logger.debug(`[${this.deviceName}] Successfully updated switch information`); return success; } } exports.VeSyncSwitch = VeSyncSwitch;