UNPKG

@olegivaniv/n8n-nodes-overkiz-tahoma

Version:

This is an n8n community node. It lets you use Overkiz (Tahoma) in your n8n workflows.

237 lines 10.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Overkiz = void 0; const n8n_workflow_1 = require("n8n-workflow"); const change_case_1 = require("change-case"); const GenericFunctions_1 = require("./GenericFunctions"); class Overkiz { constructor() { this.description = { displayName: 'Overkiz (Tahoma)', name: 'overkiz', icon: 'file:overkiz.svg', group: ['input'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Interact with Overkiz (Tahoma) API', defaults: { name: 'Overkiz (Tahoma)', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'overkizApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Object', value: 'object', }, ], default: 'object', description: 'Resource to perform action upon in Overkiz API', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['object'], }, }, options: [ { name: 'Get Many', value: 'getAll', description: 'Get many objects', action: 'Get many objects', }, { name: 'Get Single', value: 'getSingle', description: 'Get a single objects', action: 'Get a single objects', }, { name: 'Get By Type', value: 'getByType', description: 'Get objects by type', action: 'Get by type an object', }, { name: 'Execute Command', value: 'executeCommand', description: 'Executes a command on object', action: 'Execute command an object', }, ], default: 'getAll', }, { displayName: 'Object Type Name or ID', name: 'objectType', type: 'options', typeOptions: { loadOptionsMethod: 'getAvailableTypes', }, displayOptions: { show: { resource: ['object'], operation: ['getByType'], }, }, default: '', description: 'List of available object types to filter. Multiples can be defined separated by comma. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.', }, { displayName: 'Object Name or ID', name: 'objectURL', type: 'options', typeOptions: { loadOptionsMethod: 'getAvailableObjects', }, displayOptions: { show: { resource: ['object'], operation: ['executeCommand', 'getSingle'], }, }, default: '', description: 'Object to perform action upon. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.', }, { displayName: 'Command Name or ID', name: 'commandName', type: 'options', typeOptions: { loadOptionsMethod: 'getObjectCommands', }, displayOptions: { show: { resource: ['object'], operation: ['executeCommand'], }, }, default: '', description: 'Object to perform action upon. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.', }, { displayName: 'Color', name: 'color', type: 'color', default: '#ff0000', displayOptions: { show: { resource: ['object'], operation: ['executeCommand'], commandName: ['genericSetRGBColor'], }, }, }, ], }; this.methods = { loadOptions: { async getAvailableTypes() { const returnData = []; const userClasses = await GenericFunctions_1.getUsedUIClasses.call(this); for (const usedClass of userClasses) { returnData.push({ name: usedClass, value: usedClass, }); } return returnData; }, async getAvailableObjects() { const returnData = []; const homeObjects = await GenericFunctions_1.getAllObjects.call(this); for (const homeObject of homeObjects) { if (GenericFunctions_1.supportedDeviceTypes.includes(homeObject.widget)) { returnData.push({ name: `${homeObject.name} (${(0, change_case_1.capitalCase)(homeObject.definition.uiClass)})`, value: homeObject.URL, }); } } return returnData; }, async getObjectCommands() { const returnData = []; const objectURL = this.getCurrentNodeParameter('objectURL'); const objectData = await GenericFunctions_1.getSingleObject.call(this, objectURL); if (!objectData || !GenericFunctions_1.supportedDeviceTypes.includes(objectData.widget)) return []; const commands = await GenericFunctions_1.getObjectAvailableCommands.call(this, objectData.widget); for (const command of commands) { returnData.push({ name: command.name, value: command.value, }); } return returnData; }, }, }; } async execute() { var _a; const items = this.getInputData(); const returnData = []; const credentials = await this.getCredentials('overkizApi'); if (!credentials) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No credentials!'); } for (let i = 0; i < items.length; i++) { const resource = this.getNodeParameter('resource', i); const operation = this.getNodeParameter('operation', i); if (resource === 'object' && operation === 'getAll') { const objects = await GenericFunctions_1.getAllObjects.call(this); returnData.push(...objects.map((o) => ({ json: o }))); return [this.helpers.returnJsonArray(returnData)]; } if (resource === 'object' && operation === 'getSingle') { const objectURL = this.getNodeParameter('objectURL', i); const objectData = await GenericFunctions_1.getSingleObject.call(this, objectURL); returnData.push({ json: objectData }); return [this.helpers.returnJsonArray(returnData)]; } if (resource === 'object' && operation === 'getByType') { const objectType = this.getNodeParameter('objectType', i); const objects = await GenericFunctions_1.getAllObjects.call(this); const filteredObjects = objects.filter((o) => o.definition.uiClass === objectType); returnData.push(...filteredObjects.map((o) => ({ json: o }))); return [this.helpers.returnJsonArray(returnData)]; } if (resource === 'object' && operation === 'executeCommand') { const objectURL = this.getNodeParameter('objectURL', i); const commandName = this.getNodeParameter('commandName', i); const objectData = await GenericFunctions_1.getSingleObject.call(this, objectURL); if (!objectData) return [this.helpers.returnJsonArray([])]; const commands = await GenericFunctions_1.getObjectAvailableCommands.call(this, objectData.widget); const command = commands.find((c) => c.value === commandName); const execCommands = (_a = command === null || command === void 0 ? void 0 : command.commands(this)) !== null && _a !== void 0 ? _a : []; if (!command || execCommands.length === 0) return [this.helpers.returnJsonArray([])]; await objectData.exec(...execCommands); await objectData.refreshAll(); return [this.helpers.returnJsonArray([{ json: objectData }])]; } } return [this.helpers.returnJsonArray(returnData)]; } } exports.Overkiz = Overkiz; //# sourceMappingURL=Overkiz.node.js.map