From 06a5ed369023e84f96794990cae4812c9f429a03 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Mon, 3 Aug 2020 10:06:46 +0200 Subject: [PATCH] :zap: Fixes to PhilipsHue Node --- ....ts => PhilipsHueOAuth2Api.credentials.ts} | 4 +- .../GenericFunctions.ts | 12 ++--- .../LightDescription.ts | 50 ++++++++++-------- .../PhilipsHue.node.ts} | 26 ++++----- .../philipshue.png} | Bin packages/nodes-base/package.json | 4 +- 6 files changed, 50 insertions(+), 46 deletions(-) rename packages/nodes-base/credentials/{PhilipHueOAuth2Api.credentials.ts => PhilipsHueOAuth2Api.credentials.ts} (91%) rename packages/nodes-base/nodes/{PhilipHue => PhilipsHue}/GenericFunctions.ts (67%) rename packages/nodes-base/nodes/{PhilipHue => PhilipsHue}/LightDescription.ts (93%) rename packages/nodes-base/nodes/{PhilipHue/PhilipHue.node.ts => PhilipsHue/PhilipsHue.node.ts} (85%) rename packages/nodes-base/nodes/{PhilipHue/philiphue.png => PhilipsHue/philipshue.png} (100%) diff --git a/packages/nodes-base/credentials/PhilipHueOAuth2Api.credentials.ts b/packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts similarity index 91% rename from packages/nodes-base/credentials/PhilipHueOAuth2Api.credentials.ts rename to packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts index cef236a8ac..bfb4198ae6 100644 --- a/packages/nodes-base/credentials/PhilipHueOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts @@ -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', ]; diff --git a/packages/nodes-base/nodes/PhilipHue/GenericFunctions.ts b/packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts similarity index 67% rename from packages/nodes-base/nodes/PhilipHue/GenericFunctions.ts rename to packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts index d092018e8a..73b1e1b7ad 100644 --- a/packages/nodes-base/nodes/PhilipHue/GenericFunctions.ts +++ b/packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts @@ -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 { // 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 { // 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 { // 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; } diff --git a/packages/nodes-base/nodes/PhilipHue/LightDescription.ts b/packages/nodes-base/nodes/PhilipsHue/LightDescription.ts similarity index 93% rename from packages/nodes-base/nodes/PhilipHue/LightDescription.ts rename to packages/nodes-base/nodes/PhilipsHue/LightDescription.ts index b2d9cf059e..b48108deda 100644 --- a/packages/nodes-base/nodes/PhilipHue/LightDescription.ts +++ b/packages/nodes-base/nodes/PhilipsHue/LightDescription.ts @@ -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.
+ 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.
- 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[]; diff --git a/packages/nodes-base/nodes/PhilipHue/PhilipHue.node.ts b/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts similarity index 85% rename from packages/nodes-base/nodes/PhilipHue/PhilipHue.node.ts rename to packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts index 7420bda3f4..27189d4b3c 100644 --- a/packages/nodes-base/nodes/PhilipHue/PhilipHue.node.ts +++ b/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts @@ -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}`); } } } diff --git a/packages/nodes-base/nodes/PhilipHue/philiphue.png b/packages/nodes-base/nodes/PhilipsHue/philipshue.png similarity index 100% rename from packages/nodes-base/nodes/PhilipHue/philiphue.png rename to packages/nodes-base/nodes/PhilipsHue/philipshue.png diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 613411a391..bca833fb84 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -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",