mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-24 02:52:24 -08:00
⚡ Fixes to PhilipsHue Node
This commit is contained in:
parent
ea7f1c4b84
commit
06a5ed3690
|
@ -3,8 +3,8 @@ import {
|
|||
NodePropertyTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class PhilipHueOAuth2Api implements ICredentialType {
|
||||
name = 'philipHueOAuth2Api';
|
||||
export class PhilipsHueOAuth2Api implements ICredentialType {
|
||||
name = 'philipsHueOAuth2Api';
|
||||
extends = [
|
||||
'oAuth2Api',
|
||||
];
|
|
@ -1,6 +1,6 @@
|
|||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
|
@ -11,7 +11,7 @@ import {
|
|||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function philiphueApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -36,7 +36,7 @@ export async function philiphueApiRequest(this: IExecuteFunctions | ILoadOptions
|
|||
}
|
||||
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'philipHueOAuth2Api', options, { tokenType: 'Bearer' });
|
||||
return await this.helpers.requestOAuth2.call(this, 'philipsHueOAuth2Api', options, { tokenType: 'Bearer' });
|
||||
} catch (error) {
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
|
||||
|
@ -52,7 +52,7 @@ export async function philiphueApiRequest(this: IExecuteFunctions | ILoadOptions
|
|||
}
|
||||
|
||||
export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions): Promise<any> { // tslint:disable-line:no-any
|
||||
const { whitelist } = await philiphueApiRequest.call(this, 'GET', '/bridge/0/config', {}, {});
|
||||
const { whitelist } = await philipsHueApiRequest.call(this, 'GET', '/bridge/0/config', {}, {});
|
||||
//check if there is a n8n user
|
||||
for (const user of Object.keys(whitelist)) {
|
||||
if (whitelist[user].name === 'n8n') {
|
||||
|
@ -60,7 +60,7 @@ export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions):
|
|||
}
|
||||
}
|
||||
// n8n user was not fount then create the user
|
||||
await philiphueApiRequest.call(this, 'PUT', '/bridge/0/config', { linkbutton: true });
|
||||
const { success } = await philiphueApiRequest.call(this, 'POST', '/bridge', { devicetype: 'n8n' });
|
||||
await philipsHueApiRequest.call(this, 'PUT', '/bridge/0/config', { linkbutton: true });
|
||||
const { success } = await philipsHueApiRequest.call(this, 'POST', '/bridge', { devicetype: 'n8n' });
|
||||
return success.username;
|
||||
}
|
|
@ -42,6 +42,7 @@ export const lightOperations = [
|
|||
] as INodeProperties[];
|
||||
|
||||
export const lightFields = [
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* light:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -62,6 +63,7 @@ export const lightFields = [
|
|||
},
|
||||
default: '',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* light:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -106,6 +108,7 @@ export const lightFields = [
|
|||
default: 100,
|
||||
description: 'How many results to return.',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* light:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -126,6 +129,7 @@ export const lightFields = [
|
|||
},
|
||||
default: '',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* light:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -164,8 +168,8 @@ export const lightFields = [
|
|||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'On/Off state of the light. On=true, Off=false',
|
||||
default: true,
|
||||
description: 'On/Off state of the light.',
|
||||
},
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
|
@ -206,7 +210,7 @@ export const lightFields = [
|
|||
},
|
||||
],
|
||||
default: '',
|
||||
description: 'The alert effect,is a temporary change to the bulb’s state',
|
||||
description: 'The alert effect, is a temporary change to the bulb’s state',
|
||||
},
|
||||
{
|
||||
displayName: 'Brightness',
|
||||
|
@ -228,7 +232,7 @@ export const lightFields = [
|
|||
maxValue: 254,
|
||||
},
|
||||
default: 0,
|
||||
description: 'Increments or decrements the value of the brightness. bri_inc is ignored if the bri attribute is provided.',
|
||||
description: 'Increments or decrements the value of the brightness. This value is ignored if the Brightness attribute is provided.',
|
||||
},
|
||||
{
|
||||
displayName: 'Color Temperature',
|
||||
|
@ -248,6 +252,23 @@ export const lightFields = [
|
|||
default: 0,
|
||||
description: 'Increments or decrements the value of the ct. ct_inc is ignored if the ct attribute is provided',
|
||||
},
|
||||
{
|
||||
displayName: 'Coordinates',
|
||||
name: 'xy',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '0.64394,0.33069',
|
||||
description: `The x and y coordinates of a color in CIE color space.</br>
|
||||
The first entry is the x coordinate and the second entry is the y coordinate. Both x and y are between 0 and 1`,
|
||||
},
|
||||
{
|
||||
displayName: 'Coordinates Increments',
|
||||
name: 'xy_inc',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '0.5,0.5',
|
||||
description: `Increments or decrements the value of the xy. This value is ignored if the Coordinates attribute is provided. Any ongoing color transition is stopped. Max value [0.5, 0.5]`,
|
||||
},
|
||||
{
|
||||
displayName: 'Dynamic Effect',
|
||||
name: 'effect',
|
||||
|
@ -285,7 +306,7 @@ export const lightFields = [
|
|||
maxValue: 65534,
|
||||
},
|
||||
default: 0,
|
||||
description: 'Increments or decrements the value of the hue. hue_inc is ignored if the hue attribute is provided.',
|
||||
description: 'Increments or decrements the value of the hue. Hue Increments is ignored if the Hue attribute is provided.',
|
||||
},
|
||||
{
|
||||
displayName: 'Saturation',
|
||||
|
@ -307,7 +328,7 @@ export const lightFields = [
|
|||
maxValue: 254,
|
||||
},
|
||||
default: 0,
|
||||
description: 'Increments or decrements the value of the sat. sat_inc is ignored if the sat attribute is provided.',
|
||||
description: 'Increments or decrements the value of the sat. This value is ignored if the Saturation attribute is provided.',
|
||||
},
|
||||
{
|
||||
displayName: 'Transition Time',
|
||||
|
@ -319,23 +340,6 @@ export const lightFields = [
|
|||
default: 4,
|
||||
description: 'The duration in seconds of the transition from the light’s current state to the new state',
|
||||
},
|
||||
{
|
||||
displayName: 'Coordinates',
|
||||
name: 'xy',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '0.64394,0.33069',
|
||||
description: `The x and y coordinates of a color in CIE color space.</br>
|
||||
The first entry is the x coordinate and the second entry is the y coordinate. Both x and y are between 0 and 1`,
|
||||
},
|
||||
{
|
||||
displayName: 'Coordinates Increments',
|
||||
name: 'xy_inc',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: '0.5,0.5',
|
||||
description: `Increments or decrements the value of the xy. xy_inc is ignored if the xy attribute is provided. Any ongoing color transition is stopped. Max value [0.5, 0.5]`,
|
||||
},
|
||||
],
|
||||
},
|
||||
] as INodeProperties[];
|
|
@ -12,7 +12,7 @@ import {
|
|||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
philiphueApiRequest,
|
||||
philipsHueApiRequest,
|
||||
getUser,
|
||||
} from './GenericFunctions';
|
||||
|
||||
|
@ -21,24 +21,24 @@ import {
|
|||
lightFields,
|
||||
} from './LightDescription';
|
||||
|
||||
export class PhilipHue implements INodeType {
|
||||
export class PhilipsHue implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Philip Hue',
|
||||
name: 'philipHue',
|
||||
icon: 'file:philiphue.png',
|
||||
displayName: 'Philips Hue',
|
||||
name: 'philipsHue',
|
||||
icon: 'file:philipshue.png',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||
description: 'Consume Philip Hue API.',
|
||||
description: 'Consume Philips Hue API.',
|
||||
defaults: {
|
||||
name: 'Philip Hue',
|
||||
name: 'Philips Hue',
|
||||
color: '#063c9a',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'philipHueOAuth2Api',
|
||||
name: 'philipsHueOAuth2Api',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
@ -72,7 +72,7 @@ export class PhilipHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
const lights = await philiphueApiRequest.call(
|
||||
const lights = await philipsHueApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/bridge/${user}/lights`,
|
||||
|
@ -128,7 +128,7 @@ export class PhilipHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
const data = await philiphueApiRequest.call(
|
||||
const data = await philipsHueApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/bridge/${user}/lights/${lightId}/state`,
|
||||
|
@ -148,7 +148,7 @@ export class PhilipHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
responseData = await philiphueApiRequest.call(this, 'DELETE', `/bridge/${user}/lights/${lightId}`);
|
||||
responseData = await philipsHueApiRequest.call(this, 'DELETE', `/bridge/${user}/lights/${lightId}`);
|
||||
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
|
@ -156,7 +156,7 @@ export class PhilipHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
const lights = await philiphueApiRequest.call(this, 'GET', `/bridge/${user}/lights`);
|
||||
const lights = await philipsHueApiRequest.call(this, 'GET', `/bridge/${user}/lights`);
|
||||
|
||||
responseData = Object.values(lights);
|
||||
|
||||
|
@ -170,7 +170,7 @@ export class PhilipHue implements INodeType {
|
|||
|
||||
const user = await getUser.call(this);
|
||||
|
||||
responseData = await philiphueApiRequest.call(this, 'GET', `/bridge/${user}/lights/${lightId}`);
|
||||
responseData = await philipsHueApiRequest.call(this, 'GET', `/bridge/${user}/lights/${lightId}`);
|
||||
}
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 7 KiB After Width: | Height: | Size: 7 KiB |
|
@ -117,7 +117,7 @@
|
|||
"dist/credentials/PayPalApi.credentials.js",
|
||||
"dist/credentials/PipedriveApi.credentials.js",
|
||||
"dist/credentials/PipedriveOAuth2Api.credentials.js",
|
||||
"dist/credentials/PhilipHueOAuth2Api.credentials.js",
|
||||
"dist/credentials/PhilipsHueOAuth2Api.credentials.js",
|
||||
"dist/credentials/Postgres.credentials.js",
|
||||
"dist/credentials/PostmarkApi.credentials.js",
|
||||
"dist/credentials/QuestDb.credentials.js",
|
||||
|
@ -275,7 +275,7 @@
|
|||
"dist/nodes/Pipedrive/PipedriveTrigger.node.js",
|
||||
"dist/nodes/Postgres/Postgres.node.js",
|
||||
"dist/nodes/Postmark/PostmarkTrigger.node.js",
|
||||
"dist/nodes/PhilipHue/PhilipHue.node.js",
|
||||
"dist/nodes/PhilipsHue/PhilipsHue.node.js",
|
||||
"dist/nodes/QuestDb/QuestDb.node.js",
|
||||
"dist/nodes/ReadBinaryFile.node.js",
|
||||
"dist/nodes/ReadBinaryFiles.node.js",
|
||||
|
|
Loading…
Reference in a new issue