mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 22:54:05 -08:00
477b3598ea
* ✨ 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>
43 lines
1 KiB
TypeScript
43 lines
1 KiB
TypeScript
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);
|
|
}
|
|
}
|