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
45 lines • 2.04 kB
JavaScript
;
/**
* Common type definitions for all device types
* Consolidates and standardizes device-related types
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeviceEventType = void 0;
exports.inferTapoDeviceType = inferTapoDeviceType;
const device_types_1 = require("./device-types");
/**
* Device event types
*/
var DeviceEventType;
(function (DeviceEventType) {
DeviceEventType["CONNECTED"] = "connected";
DeviceEventType["DISCONNECTED"] = "disconnected";
DeviceEventType["STATE_CHANGED"] = "state_changed";
DeviceEventType["ERROR"] = "error";
DeviceEventType["CAPABILITY_CHANGED"] = "capability_changed";
})(DeviceEventType || (exports.DeviceEventType = DeviceEventType = {}));
/**
* Infer TapoDeviceType from device information using deviceTypeToCategory mapping
* @param deviceInfo Device information obtained from the device
* @returns Inferred TapoDeviceType
*/
function inferTapoDeviceType(deviceInfo) {
const model = deviceInfo.model.toUpperCase();
// Get all supported device types from deviceTypeToCategory (excluding UNKNOWN)
const supportedDeviceTypes = Object.keys(device_types_1.deviceTypeToCategory).filter(type => type !== 'UNKNOWN');
// Sort by length (longest first) to ensure more specific matches come first
const sortedDeviceTypes = supportedDeviceTypes.sort((a, b) => b.length - a.length);
// Check each supported device type against the model
for (const deviceType of sortedDeviceTypes) {
// Handle special case for P110M which maps to P110 functionality
if (deviceType === 'P110' && model.startsWith('P110M')) {
return 'P110M'; // Return P110M as specific type, but it uses P110 implementation
}
// Standard prefix matching - check if model starts with device type
if (model.startsWith(deviceType)) {
return deviceType;
}
}
return 'UNKNOWN'; // Unknown device type - should be handled explicitly
}
//# sourceMappingURL=device-common.js.map