mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
✨ Add Home AssistantIO node (#1974)
* ✨ Add Home Assistant io node * Implement continueOnFail * Add Camera Proxy resource * Clean up * Minor improvements * Remove 'Io' from the node name & code * Fix generic functions naming * ⚡ Improvements * Apply review changes & fix minor bugs * Reduce nesting for additional attributes * Minor changes * ⚡ Minor improvements and deactivate "Event" resource Co-authored-by: dali <servfrdali@yahoo.fr> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
parent
b4f4ecc77e
commit
477b3598ea
|
@ -0,0 +1,36 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export class HomeAssistantApi implements ICredentialType {
|
||||||
|
name = 'homeAssistantApi';
|
||||||
|
displayName = 'Home Assistant API';
|
||||||
|
documentationUrl = 'homeAssistant';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Host',
|
||||||
|
name: 'host',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Port',
|
||||||
|
name: 'port',
|
||||||
|
type: 'number' as NodePropertyTypes,
|
||||||
|
default: 8123,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'SSL',
|
||||||
|
name: 'ssl',
|
||||||
|
type: 'boolean' as NodePropertyTypes,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token',
|
||||||
|
name: 'accessToken',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const cameraProxyOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'cameraProxy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get Screenshot',
|
||||||
|
value: 'getScreenshot',
|
||||||
|
description: 'Get the camera screenshot',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getScreenshot',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const cameraProxyFields = [
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* cameraProxy:getScreenshot */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Camera Entity ID',
|
||||||
|
name: 'cameraEntityId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getScreenshot',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'cameraProxy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The camera entity ID.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Binary Property',
|
||||||
|
name: 'binaryPropertyName',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: 'data',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getScreenshot',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'cameraProxy',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'Name of the binary property to which to<br />write the data of the read file.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
32
packages/nodes-base/nodes/HomeAssistant/ConfigDescription.ts
Normal file
32
packages/nodes-base/nodes/HomeAssistant/ConfigDescription.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const configOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'config',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get',
|
||||||
|
value: 'get',
|
||||||
|
description: 'Get the configuration',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Check Configuration',
|
||||||
|
value: 'check',
|
||||||
|
description: 'Check the configuration',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'get',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
144
packages/nodes-base/nodes/HomeAssistant/EventDescription.ts
Normal file
144
packages/nodes-base/nodes/HomeAssistant/EventDescription.ts
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const eventOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'event',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all events',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Post',
|
||||||
|
value: 'post',
|
||||||
|
description: 'Post an event',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getAll',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const eventFields = [
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* event:getAll */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'event',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'event',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
default: 50,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* event:post */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Event Type',
|
||||||
|
name: 'eventType',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'post',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'event',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'The Entity ID for which an event will be created.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Event Attributes',
|
||||||
|
name: 'eventAttributes',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
placeholder: 'Add Attribute',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'event',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'post',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Attributes',
|
||||||
|
name: 'attributes',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Name of the attribute.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Value of the attribute.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
42
packages/nodes-base/nodes/HomeAssistant/GenericFunctions.ts
Normal file
42
packages/nodes-base/nodes/HomeAssistant/GenericFunctions.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
import {
|
||||||
|
OptionsWithUri
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IExecuteFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IDataObject,
|
||||||
|
NodeApiError,
|
||||||
|
NodeOperationError,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export async function homeAssistantApiRequest(this: IExecuteFunctions, method: string, resource: string, body: IDataObject = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}) {
|
||||||
|
const credentials = this.getCredentials('homeAssistantApi');
|
||||||
|
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new NodeOperationError(this.getNode(), 'No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
|
let options: OptionsWithUri = {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${credentials.accessToken}`,
|
||||||
|
},
|
||||||
|
method,
|
||||||
|
qs,
|
||||||
|
body,
|
||||||
|
uri: uri ?? `${credentials.ssl === true ? 'https' : 'http'}://${credentials.host}:${credentials.port}/api${resource}`,
|
||||||
|
json: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
options = Object.assign({}, options, option);
|
||||||
|
if (Object.keys(options.body).length === 0) {
|
||||||
|
delete options.body;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return await this.helpers.request(options);
|
||||||
|
} catch (error) {
|
||||||
|
throw new NodeApiError(this.getNode(), error);
|
||||||
|
}
|
||||||
|
}
|
128
packages/nodes-base/nodes/HomeAssistant/HistoryDescription.ts
Normal file
128
packages/nodes-base/nodes/HomeAssistant/HistoryDescription.ts
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const historyOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'history',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all state changes',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getAll',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const historyFields = [
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* history:getLogbookEntries */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'history',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'history',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
default: 50,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'history',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'End Time',
|
||||||
|
name: 'endTime',
|
||||||
|
type: 'dateTime',
|
||||||
|
default: '',
|
||||||
|
description: 'The end of the period.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Entity IDs',
|
||||||
|
name: 'entityIds',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'The entities IDs separated by comma.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Minimal Response',
|
||||||
|
name: 'minimalResponse',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'To only return <code>last_changed</code> and state for states.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Significant Changes Only',
|
||||||
|
name: 'significantChangesOnly',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Only return significant state changes.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Start Time',
|
||||||
|
name: 'startTime',
|
||||||
|
type: 'dateTime',
|
||||||
|
default: '',
|
||||||
|
description: 'The beginning of the period.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"node": "n8n-nodes-base.homeAssistant",
|
||||||
|
"nodeVersion": "1.0",
|
||||||
|
"codexVersion": "1.0",
|
||||||
|
"categories": [
|
||||||
|
"Miscellaneous"
|
||||||
|
],
|
||||||
|
"resources": {
|
||||||
|
"credentialDocumentation": [
|
||||||
|
{
|
||||||
|
"url": "https://docs.n8n.io/credentials/homeAssistant"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryDocumentation": [
|
||||||
|
{
|
||||||
|
"url": "https://docs.n8n.io/nodes/n8n-nodes-base.homeAssistant/"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
377
packages/nodes-base/nodes/HomeAssistant/HomeAssistant.node.ts
Normal file
377
packages/nodes-base/nodes/HomeAssistant/HomeAssistant.node.ts
Normal file
|
@ -0,0 +1,377 @@
|
||||||
|
import {
|
||||||
|
IExecuteFunctions,
|
||||||
|
} from 'n8n-core';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IDataObject,
|
||||||
|
INodeExecutionData,
|
||||||
|
INodeType,
|
||||||
|
INodeTypeDescription,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
import {
|
||||||
|
configOperations,
|
||||||
|
} from './ConfigDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
serviceFields,
|
||||||
|
serviceOperations,
|
||||||
|
} from './ServiceDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
stateFields,
|
||||||
|
stateOperations,
|
||||||
|
} from './StateDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
eventFields,
|
||||||
|
eventOperations,
|
||||||
|
} from './EventDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
logFields,
|
||||||
|
logOperations,
|
||||||
|
} from './LogDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
templateFields,
|
||||||
|
templateOperations,
|
||||||
|
} from './TemplateDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
historyFields,
|
||||||
|
historyOperations,
|
||||||
|
} from './HistoryDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
cameraProxyFields,
|
||||||
|
cameraProxyOperations,
|
||||||
|
} from './CameraProxyDescription';
|
||||||
|
|
||||||
|
import {
|
||||||
|
homeAssistantApiRequest,
|
||||||
|
} from './GenericFunctions';
|
||||||
|
|
||||||
|
export class HomeAssistant implements INodeType {
|
||||||
|
description: INodeTypeDescription = {
|
||||||
|
displayName: 'Home Assistant',
|
||||||
|
name: 'homeAssistant',
|
||||||
|
icon: 'file:homeAssistant.svg',
|
||||||
|
group: ['output'],
|
||||||
|
version: 1,
|
||||||
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
|
description: 'Consume Home Assistant API',
|
||||||
|
defaults: {
|
||||||
|
name: 'Home Assistant',
|
||||||
|
color: '#3578e5',
|
||||||
|
},
|
||||||
|
inputs: ['main'],
|
||||||
|
outputs: ['main'],
|
||||||
|
credentials: [
|
||||||
|
{
|
||||||
|
name: 'homeAssistantApi',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Resource',
|
||||||
|
name: 'resource',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Camera Proxy',
|
||||||
|
value: 'cameraProxy',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Config',
|
||||||
|
value: 'config',
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// name: 'Event',
|
||||||
|
// value: 'event',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'History',
|
||||||
|
// value: 'history',
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
name: 'Log',
|
||||||
|
value: 'log',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Service',
|
||||||
|
value: 'service',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'State',
|
||||||
|
value: 'state',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Template',
|
||||||
|
value: 'template',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'config',
|
||||||
|
description: 'Resource to consume.',
|
||||||
|
},
|
||||||
|
...cameraProxyOperations,
|
||||||
|
...cameraProxyFields,
|
||||||
|
...configOperations,
|
||||||
|
...eventOperations,
|
||||||
|
...eventFields,
|
||||||
|
...historyOperations,
|
||||||
|
...historyFields,
|
||||||
|
...logOperations,
|
||||||
|
...logFields,
|
||||||
|
...serviceOperations,
|
||||||
|
...serviceFields,
|
||||||
|
...stateOperations,
|
||||||
|
...stateFields,
|
||||||
|
...templateOperations,
|
||||||
|
...templateFields,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
|
const items = this.getInputData();
|
||||||
|
const returnData: IDataObject[] = [];
|
||||||
|
const length = items.length;
|
||||||
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
|
const qs: IDataObject = {};
|
||||||
|
let responseData;
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
try {
|
||||||
|
if (resource === 'config') {
|
||||||
|
if (operation === 'get') {
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', '/config');
|
||||||
|
} else if (operation === 'check') {
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'POST', '/config/core/check_config');
|
||||||
|
}
|
||||||
|
} else if (resource === 'service') {
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', '/services') as IDataObject[];
|
||||||
|
if (!returnAll) {
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
} else if (operation === 'call') {
|
||||||
|
const domain = this.getNodeParameter('domain', i) as string;
|
||||||
|
const service = this.getNodeParameter('service', i) as string;
|
||||||
|
const serviceAttributes = this.getNodeParameter('serviceAttributes', i) as {
|
||||||
|
attributes: IDataObject[],
|
||||||
|
};
|
||||||
|
|
||||||
|
const body: IDataObject = {};
|
||||||
|
|
||||||
|
if (Object.entries(serviceAttributes).length) {
|
||||||
|
if (serviceAttributes.attributes !== undefined) {
|
||||||
|
serviceAttributes.attributes.map(
|
||||||
|
attribute => {
|
||||||
|
// @ts-ignore
|
||||||
|
body[attribute.name as string] = attribute.value;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'POST', `/services/${domain}/${service}`, body);
|
||||||
|
if (Array.isArray(responseData) && responseData.length === 0) {
|
||||||
|
responseData = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (resource === 'state') {
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', '/states') as IDataObject[];
|
||||||
|
if (!returnAll) {
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
} else if (operation === 'get') {
|
||||||
|
const entityId = this.getNodeParameter('entityId', i) as string;
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', `/states/${entityId}`);
|
||||||
|
} else if (operation === 'upsert') {
|
||||||
|
const entityId = this.getNodeParameter('entityId', i) as string;
|
||||||
|
const state = this.getNodeParameter('state', i) as string;
|
||||||
|
const stateAttributes = this.getNodeParameter('stateAttributes', i) as {
|
||||||
|
attributes: IDataObject[],
|
||||||
|
};
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
state,
|
||||||
|
attributes: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Object.entries(stateAttributes).length) {
|
||||||
|
if (stateAttributes.attributes !== undefined) {
|
||||||
|
stateAttributes.attributes.map(
|
||||||
|
attribute => {
|
||||||
|
// @ts-ignore
|
||||||
|
body.attributes[attribute.name as string] = attribute.value;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'POST', `/states/${entityId}`, body);
|
||||||
|
}
|
||||||
|
} else if (resource === 'event') {
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', '/events') as IDataObject[];
|
||||||
|
if (!returnAll) {
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
} else if (operation === 'post') {
|
||||||
|
const eventType = this.getNodeParameter('eventType', i) as string;
|
||||||
|
const eventAttributes = this.getNodeParameter('eventAttributes', i) as {
|
||||||
|
attributes: IDataObject[],
|
||||||
|
};
|
||||||
|
|
||||||
|
const body = {};
|
||||||
|
|
||||||
|
if (Object.entries(eventAttributes).length) {
|
||||||
|
if (eventAttributes.attributes !== undefined) {
|
||||||
|
eventAttributes.attributes.map(
|
||||||
|
attribute => {
|
||||||
|
// @ts-ignore
|
||||||
|
body[attribute.name as string] = attribute.value;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'POST', `/events/${eventType}`, body);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (resource === 'log') {
|
||||||
|
if (operation === 'getErroLogs') {
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', '/error_log');
|
||||||
|
if (responseData) {
|
||||||
|
responseData = {
|
||||||
|
errorLog: responseData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (operation === 'getLogbookEntries') {
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
let endpoint = '/logbook';
|
||||||
|
|
||||||
|
if (Object.entries(additionalFields).length) {
|
||||||
|
if (additionalFields.startTime) {
|
||||||
|
endpoint = `/logbook/${additionalFields.startTime}`;
|
||||||
|
}
|
||||||
|
if (additionalFields.endTime) {
|
||||||
|
qs.end_time = additionalFields.endTime;
|
||||||
|
}
|
||||||
|
if (additionalFields.entityId) {
|
||||||
|
qs.entity = additionalFields.entityId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if (resource === 'template') {
|
||||||
|
if (operation === 'create') {
|
||||||
|
const body = {
|
||||||
|
template: this.getNodeParameter('template', i) as string,
|
||||||
|
};
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'POST', '/template', body);
|
||||||
|
if (responseData) {
|
||||||
|
responseData = { renderedTemplate: responseData };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (resource === 'history') {
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
let endpoint = '/history/period';
|
||||||
|
|
||||||
|
if (Object.entries(additionalFields).length) {
|
||||||
|
if (additionalFields.startTime) {
|
||||||
|
endpoint = `/history/period/${additionalFields.startTime}`;
|
||||||
|
}
|
||||||
|
if (additionalFields.endTime) {
|
||||||
|
qs.end_time = additionalFields.endTime;
|
||||||
|
}
|
||||||
|
if (additionalFields.entityIds) {
|
||||||
|
qs.filter_entity_id = additionalFields.entityIds;
|
||||||
|
}
|
||||||
|
if (additionalFields.minimalResponse === true) {
|
||||||
|
qs.minimal_response = additionalFields.minimalResponse;
|
||||||
|
}
|
||||||
|
if (additionalFields.significantChangesOnly === true) {
|
||||||
|
qs.significant_changes_only = additionalFields.significantChangesOnly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', endpoint, {}, qs) as IDataObject[];
|
||||||
|
if (!returnAll) {
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
responseData = responseData.slice(0, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (resource === 'cameraProxy') {
|
||||||
|
if (operation === 'getScreenshot') {
|
||||||
|
const cameraEntityId = this.getNodeParameter('cameraEntityId', i) as string;
|
||||||
|
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||||
|
const endpoint = `/camera_proxy/${cameraEntityId}`;
|
||||||
|
|
||||||
|
let mimeType: string | undefined;
|
||||||
|
|
||||||
|
responseData = await homeAssistantApiRequest.call(this, 'GET', endpoint, {}, {}, undefined, {
|
||||||
|
encoding: null,
|
||||||
|
resolveWithFullResponse: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const newItem: INodeExecutionData = {
|
||||||
|
json: items[i].json,
|
||||||
|
binary: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (mimeType === undefined && responseData.headers['content-type']) {
|
||||||
|
mimeType = responseData.headers['content-type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (items[i].binary !== undefined) {
|
||||||
|
// Create a shallow copy of the binary data so that the old
|
||||||
|
// data references which do not get changed still stay behind
|
||||||
|
// but the incoming data does not get changed.
|
||||||
|
Object.assign(newItem.binary, items[i].binary);
|
||||||
|
}
|
||||||
|
|
||||||
|
items[i] = newItem;
|
||||||
|
|
||||||
|
const data = Buffer.from(responseData.body as string);
|
||||||
|
|
||||||
|
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data, 'screenshot.jpg', mimeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (this.continueOnFail()) {
|
||||||
|
if (resource === 'cameraProxy' && operation === 'get') {
|
||||||
|
items[i].json = { error: error.message };
|
||||||
|
} else {
|
||||||
|
returnData.push({ error: error.message });
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.isArray(responseData)
|
||||||
|
? returnData.push(...responseData)
|
||||||
|
: returnData.push(responseData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource === 'cameraProxy' && operation === 'getScreenshot') {
|
||||||
|
return this.prepareOutputData(items);
|
||||||
|
} else {
|
||||||
|
return [this.helpers.returnJsonArray(returnData)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
packages/nodes-base/nodes/HomeAssistant/LogDescription.ts
Normal file
78
packages/nodes-base/nodes/HomeAssistant/LogDescription.ts
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const logOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'log',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Get Error Logs',
|
||||||
|
value: 'getErroLogs',
|
||||||
|
description: 'Get a log for a specific entity',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Get Logbook Entries',
|
||||||
|
value: 'getLogbookEntries',
|
||||||
|
description: 'Get all logs',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getErroLogs',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const logFields = [
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* log:getLogbookEntries */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'log',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getLogbookEntries',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'End Time',
|
||||||
|
name: 'endTime',
|
||||||
|
type: 'dateTime',
|
||||||
|
default: '',
|
||||||
|
description: 'The end of the period.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Entity ID',
|
||||||
|
name: 'entityId',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'The entity ID.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Start Time',
|
||||||
|
name: 'startTime',
|
||||||
|
type: 'dateTime',
|
||||||
|
default: '',
|
||||||
|
description: 'The beginning of the period.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
159
packages/nodes-base/nodes/HomeAssistant/ServiceDescription.ts
Normal file
159
packages/nodes-base/nodes/HomeAssistant/ServiceDescription.ts
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const serviceOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'service',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Call',
|
||||||
|
value: 'call',
|
||||||
|
description: 'Call a service within a specific domain',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all services',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'getAll',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const serviceFields = [
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* service:getAll */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'service',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'service',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
default: 50,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* service:Call */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Domain',
|
||||||
|
name: 'domain',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'service',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'call',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Service',
|
||||||
|
name: 'service',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'service',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'call',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Service Attributes',
|
||||||
|
name: 'serviceAttributes',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
placeholder: 'Add Attribute',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'service',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'call',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'attributes',
|
||||||
|
displayName: 'Attributes',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Name of the field.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Value of the field.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
187
packages/nodes-base/nodes/HomeAssistant/StateDescription.ts
Normal file
187
packages/nodes-base/nodes/HomeAssistant/StateDescription.ts
Normal file
|
@ -0,0 +1,187 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const stateOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Create or update',
|
||||||
|
value: 'upsert',
|
||||||
|
description: 'Create a new record, or update the current one if it already exists (upsert)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Get',
|
||||||
|
value: 'get',
|
||||||
|
description: 'Get a state for a specific entity',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Get All',
|
||||||
|
value: 'getAll',
|
||||||
|
description: 'Get all states',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'get',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const stateFields = [
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* state:get */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Entity ID',
|
||||||
|
name: 'entityId',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'get',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'The entity ID.',
|
||||||
|
},
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* state:getAll */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 100,
|
||||||
|
},
|
||||||
|
default: 50,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* state:upsert */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Entity ID',
|
||||||
|
name: 'entityId',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'upsert',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'The entity ID for which a state will be created.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'State',
|
||||||
|
name: 'state',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'upsert',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'State Attributes',
|
||||||
|
name: 'stateAttributes',
|
||||||
|
type: 'fixedCollection',
|
||||||
|
typeOptions: {
|
||||||
|
multipleValues: true,
|
||||||
|
},
|
||||||
|
placeholder: 'Add Attribute',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'state',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'upsert',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Attributes',
|
||||||
|
name: 'attributes',
|
||||||
|
values: [
|
||||||
|
{
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Name of the attribute.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Value',
|
||||||
|
name: 'value',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Value of the attribute.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
|
@ -0,0 +1,52 @@
|
||||||
|
import {
|
||||||
|
INodeProperties
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const templateOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'template',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Create',
|
||||||
|
value: 'create',
|
||||||
|
description: 'create a template',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'create',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const templateFields = [
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* template:create */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'Template',
|
||||||
|
name: 'template',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'template',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
description: 'Render a Home Assistant template. <a href="https://www.home-assistant.io/docs/configuration/templating/" target="_blank">See template docs for more information.</a>',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
16
packages/nodes-base/nodes/HomeAssistant/homeAssistant.svg
Normal file
16
packages/nodes-base/nodes/HomeAssistant/homeAssistant.svg
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||||
|
<defs>
|
||||||
|
<path d="M44.041 343.222V209.58H9.288a9.333 9.333 0 0 1-6.655-15.876L189.639 3.497c4.517-4.594 11.903-4.657 16.498-.14l.12.12 97.601 98.794V83.974a7.778 7.778 0 0 1 7.778-7.778h32.41a7.778 7.778 0 0 1 7.779 7.778v67.138l41.568 42.618a9.333 9.333 0 0 1-6.682 15.85h-34.886v133.642a7.778 7.778 0 0 1-7.778 7.778H51.819a7.778 7.778 0 0 1-7.778-7.778zm206.393-163.26a15.029 15.029 0 0 0 1.46-6.486c0-8.308-6.71-15.043-14.989-15.043-8.278 0-14.989 6.735-14.989 15.043s6.711 15.044 14.99 15.044c2.314 0 4.505-.527 6.462-1.467l21.518 21.596v20.918l-26.981 27.078v-19.84a15.046 15.046 0 0 0 9.993-14.187c0-8.308-6.711-15.044-14.99-15.044-8.278 0-14.99 6.736-14.99 15.044 0 6.55 4.172 12.122 9.994 14.187v29.868l-24.983 25.073V144.464l20.519-20.592a14.886 14.886 0 0 0 6.462 1.466c8.279 0 14.99-6.735 14.99-15.044 0-8.308-6.711-15.043-14.99-15.043-8.278 0-14.989 6.735-14.989 15.043 0 2.323.524 4.522 1.46 6.486l-18.448 18.515-18.449-18.515a15.029 15.029 0 0 0 1.46-6.486c0-8.308-6.71-15.043-14.989-15.043-8.278 0-14.989 6.735-14.989 15.043 0 8.309 6.711 15.044 14.99 15.044 2.314 0 4.505-.527 6.462-1.466l20.518 20.592v105.16l-35.974-36.104v-28.865a15.046 15.046 0 0 0 9.993-14.187c0-8.309-6.711-15.044-14.99-15.044-8.278 0-14.99 6.735-14.99 15.044 0 6.55 4.172 12.122 9.994 14.187v18.837l-27.98-28.081v-27.863a15.046 15.046 0 0 0 9.993-14.187c0-8.308-6.711-15.044-14.99-15.044-8.278 0-14.99 6.736-14.99 15.044 0 6.55 4.172 12.122 9.994 14.187v32.017l30.907 31.018h-17.77c-2.058-5.843-7.61-10.029-14.137-10.029-8.278 0-14.99 6.735-14.99 15.043 0 8.309 6.712 15.044 14.99 15.044 6.527 0 12.08-4.186 14.137-10.03h27.763l43.04 43.196v75.074l-22.983-23.066v-28.866a15.046 15.046 0 0 0 9.993-14.187c0-8.308-6.711-15.043-14.99-15.043-8.278 0-14.99 6.735-14.99 15.043 0 6.55 4.172 12.122 9.994 14.187v18.837l-33.439-33.558a15.029 15.029 0 0 0 1.461-6.486c0-8.308-6.71-15.043-14.99-15.043-8.278 0-14.989 6.735-14.989 15.043s6.711 15.043 14.99 15.043c2.314 0 4.506-.526 6.462-1.466l33.439 33.559h-17.77c-2.058-5.843-7.61-10.03-14.137-10.03-8.278 0-14.99 6.736-14.99 15.044s6.712 15.043 14.99 15.043c6.527 0 12.079-4.186 14.137-10.029h27.763l27.98 28.081h14.132l28.98-29.083h26.763c2.058 5.842 7.61 10.028 14.137 10.028 8.278 0 14.99-6.735 14.99-15.043s-6.712-15.043-14.99-15.043c-6.527 0-12.079 4.186-14.137 10.029H229.84l-26.91 27.006V305.93l32.049-32.164h51.746c2.058 5.843 7.61 10.029 14.136 10.029 8.279 0 14.99-6.735 14.99-15.043 0-8.309-6.711-15.044-14.99-15.044-6.526 0-12.078 4.186-14.136 10.03H244.97l29.908-30.016v-25.072l21.517-21.596a14.886 14.886 0 0 0 6.463 1.467c8.278 0 14.99-6.736 14.99-15.044s-6.712-15.043-14.99-15.043-14.99 6.735-14.99 15.043c0 2.323.525 4.522 1.461 6.486l-14.451 14.504V148.55a15.046 15.046 0 0 0 9.993-14.187c0-8.309-6.711-15.044-14.99-15.044-8.278 0-14.99 6.735-14.99 15.044 0 6.55 4.172 12.122 9.994 14.187v45.915l-14.452-14.504zM120.987 323.909c-3.311 0-5.996-2.694-5.996-6.017 0-3.323 2.685-6.017 5.996-6.017 3.312 0 5.996 2.694 5.996 6.017 0 3.323-2.684 6.017-5.996 6.017zm43.97-45.13c-3.312 0-5.997-2.694-5.997-6.017 0-3.323 2.685-6.017 5.996-6.017 3.312 0 5.996 2.694 5.996 6.017 0 3.323-2.684 6.017-5.996 6.017zm-51.964-7.02c-3.312 0-5.996-2.694-5.996-6.017 0-3.323 2.684-6.017 5.996-6.017 3.311 0 5.996 2.694 5.996 6.017 0 3.323-2.685 6.017-5.996 6.017zm-4.997-50.144c-3.311 0-5.995-2.694-5.995-6.018 0-3.323 2.684-6.017 5.995-6.017 3.312 0 5.996 2.694 5.996 6.017 0 3.324-2.684 6.018-5.996 6.018zm124.912 7.02c-3.311 0-5.995-2.694-5.995-6.017 0-3.324 2.684-6.018 5.995-6.018 3.312 0 5.996 2.694 5.996 6.018 0 3.323-2.684 6.017-5.996 6.017zm67.952 46.133c-3.31 0-5.995-2.694-5.995-6.017 0-3.324 2.684-6.018 5.995-6.018 3.312 0 5.996 2.694 5.996 6.018 0 3.323-2.684 6.017-5.996 6.017zm-25.981 48.138c-3.312 0-5.996-2.694-5.996-6.017 0-3.323 2.684-6.017 5.996-6.017 3.311 0 5.996 2.694 5.996 6.017 0 3.323-2.685 6.017-5.996 6.017zm27.98-143.412c-3.311 0-5.996-2.695-5.996-6.018s2.685-6.017 5.996-6.017c3.311 0 5.996 2.694 5.996 6.017 0 3.323-2.685 6.018-5.996 6.018zm-32.977-39.113c-3.311 0-5.996-2.694-5.996-6.017 0-3.324 2.685-6.018 5.996-6.018 3.312 0 5.996 2.694 5.996 6.018 0 3.323-2.684 6.017-5.996 6.017zm-39.972-24.07c-3.311 0-5.995-2.693-5.995-6.017 0-3.323 2.684-6.017 5.995-6.017 3.312 0 5.996 2.694 5.996 6.017 0 3.324-2.684 6.018-5.996 6.018zm-63.955 0c-3.31 0-5.995-2.693-5.995-6.017 0-3.323 2.684-6.017 5.995-6.017 3.312 0 5.996 2.694 5.996 6.017 0 3.324-2.684 6.018-5.996 6.018zm-51.963 23.067c-3.311 0-5.996-2.694-5.996-6.017 0-3.324 2.685-6.018 5.996-6.018 3.311 0 5.996 2.694 5.996 6.018 0 3.323-2.685 6.017-5.996 6.017zm37.973 37.107c-3.311 0-5.995-2.694-5.995-6.017 0-3.324 2.684-6.018 5.995-6.018 3.312 0 5.996 2.694 5.996 6.018 0 3.323-2.684 6.017-5.996 6.017zm84.94 3.009c-3.31 0-5.995-2.695-5.995-6.018s2.684-6.017 5.995-6.017c3.312 0 5.996 2.694 5.996 6.017 0 3.323-2.684 6.018-5.996 6.018z" id="a"/>
|
||||||
|
</defs>
|
||||||
|
<g fill="none" fill-rule="evenodd">
|
||||||
|
<path d="M0 0h500v500H0z" fill="#41BDF5"/>
|
||||||
|
<g transform="translate(52 70)">
|
||||||
|
<mask id="b" fill="#fff">
|
||||||
|
<use xlink:href="#a"/>
|
||||||
|
</mask>
|
||||||
|
<g mask="url(#b)" fill="#FFF">
|
||||||
|
<path d="M0 0h396v351H0z"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 5.2 KiB |
|
@ -119,6 +119,7 @@
|
||||||
"dist/credentials/HarvestApi.credentials.js",
|
"dist/credentials/HarvestApi.credentials.js",
|
||||||
"dist/credentials/HarvestOAuth2Api.credentials.js",
|
"dist/credentials/HarvestOAuth2Api.credentials.js",
|
||||||
"dist/credentials/HelpScoutOAuth2Api.credentials.js",
|
"dist/credentials/HelpScoutOAuth2Api.credentials.js",
|
||||||
|
"dist/credentials/HomeAssistantApi.credentials.js",
|
||||||
"dist/credentials/HttpBasicAuth.credentials.js",
|
"dist/credentials/HttpBasicAuth.credentials.js",
|
||||||
"dist/credentials/HttpDigestAuth.credentials.js",
|
"dist/credentials/HttpDigestAuth.credentials.js",
|
||||||
"dist/credentials/HttpHeaderAuth.credentials.js",
|
"dist/credentials/HttpHeaderAuth.credentials.js",
|
||||||
|
@ -403,6 +404,7 @@
|
||||||
"dist/nodes/Harvest/Harvest.node.js",
|
"dist/nodes/Harvest/Harvest.node.js",
|
||||||
"dist/nodes/HelpScout/HelpScout.node.js",
|
"dist/nodes/HelpScout/HelpScout.node.js",
|
||||||
"dist/nodes/HelpScout/HelpScoutTrigger.node.js",
|
"dist/nodes/HelpScout/HelpScoutTrigger.node.js",
|
||||||
|
"dist/nodes/HomeAssistant/HomeAssistant.node.js",
|
||||||
"dist/nodes/HtmlExtract/HtmlExtract.node.js",
|
"dist/nodes/HtmlExtract/HtmlExtract.node.js",
|
||||||
"dist/nodes/HttpRequest.node.js",
|
"dist/nodes/HttpRequest.node.js",
|
||||||
"dist/nodes/Hubspot/Hubspot.node.js",
|
"dist/nodes/Hubspot/Hubspot.node.js",
|
||||||
|
|
Loading…
Reference in a new issue