node-red-contrib-tplink-tapo-connect-api
Version:
This unofficial node-RED node allows connection to TP-Link Tapo devices. This project has been enhanced with AI support to enable new features. Starting with v0.50, we have added support for the KLAP protocol. To prioritize the operation of this node, we
137 lines • 6.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tplinkTapoConnectWrapper = void 0;
const device_factory_1 = require("../factory/device-factory");
const device_control_service_1 = require("../services/device-control-service");
const batch_operation_service_1 = require("../services/batch-operation-service");
/**
* Main wrapper class for TP-Link Tapo device operations
* Provides a simplified interface for device control with proper error handling and retry logic
*
* @export
* @class tplinkTapoConnectWrapper
*/
class tplinkTapoConnectWrapper {
/**
* Get singleton instance
*
* @static
* @returns {tplinkTapoConnectWrapper}
* @memberof tplinkTapoConnectWrapper
*/
static getInstance() {
if (!this._instance)
this._instance = new tplinkTapoConnectWrapper();
return this._instance;
}
/**
* Creates an instance of tplinkTapoConnectWrapper.
* @memberof tplinkTapoConnectWrapper
*/
constructor() {
this.currentWorkingDirectory = process.cwd();
// Initialization completed
}
/**
* Clear all cached clients and their devices
*/
clearCache() {
// Clear the device info cache
device_factory_1.DeviceFactory.clearDeviceInfoCache();
// Clear the device control service cache for session continuity
device_control_service_1.DeviceControlService.clearDeviceCache();
}
/**
* Get device information including energy usage data for supported devices
* The method will automatically detect the device type and retrieve basic device information
* Energy usage data is included automatically for supported devices (P110, P115, etc.)
*
* @param {string} _email - Tapo account email
* @param {string} _password - Tapo account password
* @param {string} _targetIp - Device IP address
* @param {RetryOptions} _retryOptions - Optional retry configuration
* @returns {Promise< tplinkTapoConnectWrapperType.tapoConnectResults >} - Contains device information and energy usage (if supported)
* @memberof tplinkTapoConnectWrapper
*/
async getTapoDeviceInfo(_email, _password, _targetIp, _retryOptions) {
return device_control_service_1.DeviceControlService.getDeviceInfo(_email, _password, _targetIp, _retryOptions);
}
/**
* Get energy usage information for devices that support energy monitoring
* First checks if the device supports energy monitoring, then retrieves energy data
*
* @deprecated Use getTapoDeviceInfo() instead, which now includes energy usage data for supported devices
* @param {string} _email - Tapo account email
* @param {string} _password - Tapo account password
* @param {string} _targetIp - Device IP address
* @param {RetryOptions} _retryOptions - Optional retry configuration
* @return {*} {Promise<tplinkTapoConnectWrapperType.tapoConnectResults>}
* @memberof tplinkTapoConnectWrapper
*/
async getTapoEnergyUsage(_email, _password, _targetIp, _retryOptions) {
return device_control_service_1.DeviceControlService.getEnergyUsage(_email, _password, _targetIp, _retryOptions);
}
/**
* Turn device on
*
* @param {string} _email - Tapo account email
* @param {string} _password - Tapo account password
* @param {string} _targetIp - Device IP address
* @param {RetryOptions} _retryOptions - Optional retry configuration
* @returns {Promise< tplinkTapoConnectWrapperType.tapoConnectResults >}
* @memberof tplinkTapoConnectWrapper
*/
async setTapoTurnOn(_email, _password, _targetIp, _retryOptions) {
return device_control_service_1.DeviceControlService.turnOn(_email, _password, _targetIp, _retryOptions);
}
/**
* Turn device off
*
* @param {string} _email - Tapo account email
* @param {string} _password - Tapo account password
* @param {string} _targetIp - Device IP address
* @param {RetryOptions} _retryOptions - Optional retry configuration
* @returns {Promise< tplinkTapoConnectWrapperType.tapoConnectResults >}
* @memberof tplinkTapoConnectWrapper
*/
async setTapoTurnOff(_email, _password, _targetIp, _retryOptions) {
return device_control_service_1.DeviceControlService.turnOff(_email, _password, _targetIp, _retryOptions);
}
/**
* Set device brightness
*
* @param {string} _email - Tapo account email
* @param {string} _password - Tapo account password
* @param {string} _targetIp - Device IP address
* @param {number} _brightness - Brightness level (1-100)
* @param {RetryOptions} _retryOptions - Optional retry configuration
* @returns {Promise< tplinkTapoConnectWrapperType.tapoConnectResults >}
* @memberof tplinkTapoConnectWrapper
*/
async setTapoBrightness(_email, _password, _targetIp, _brightness, _retryOptions) {
return device_control_service_1.DeviceControlService.setBrightness(_email, _password, _targetIp, _brightness, _retryOptions);
}
/**
* Set color using named color
*
* @param {string} _email - Tapo account email
* @param {string} _password - Tapo account password
* @param {string} _targetIp - Device IP address
* @param {string} _colour - Named color (red, green, blue, etc.)
* @param {RetryOptions} _retryOptions - Optional retry configuration
* @returns {Promise< tplinkTapoConnectWrapperType.tapoConnectResults >}
* @memberof tplinkTapoConnectWrapper
*/
async setTapoColour(_email, _password, _targetIp, _colour, _retryOptions) {
return device_control_service_1.DeviceControlService.setColor(_email, _password, _targetIp, _colour, _retryOptions);
}
/**
* Batch operations with smart delays to prevent KLAP -1012 errors
* Migrated from Enhanced Wrapper for consistency
*/
async executeBatch(operations, options = {}) {
return batch_operation_service_1.BatchOperationService.executeBatch(operations, options);
}
}
exports.tplinkTapoConnectWrapper = tplinkTapoConnectWrapper;
//# sourceMappingURL=tplink-tapo-connect-wrapper.js.map