From e0ef645514e584d70797a498d60b52dd3a284920 Mon Sep 17 00:00:00 2001 From: Tom <19203795+that-one-tom@users.noreply.github.com> Date: Thu, 13 Jan 2022 07:51:58 +0100 Subject: [PATCH] :bug: Fix Philips Hue API Connection (#2631) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 Fix Philips Hue API Connection * Philips Hue Node: Fixed typo in update operation description --- .../credentials/PhilipsHueOAuth2Api.credentials.ts | 4 ++-- .../nodes-base/nodes/PhilipsHue/GenericFunctions.ts | 11 ++++++----- .../nodes-base/nodes/PhilipsHue/LightDescription.ts | 2 +- .../nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts b/packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts index 653e1df6be..c93712e4c5 100644 --- a/packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/PhilipsHueOAuth2Api.credentials.ts @@ -21,13 +21,13 @@ export class PhilipsHueOAuth2Api implements ICredentialType { displayName: 'Authorization URL', name: 'authUrl', type: 'hidden', - default: 'https://api.meethue.com/oauth2/auth', + default: 'https://api.meethue.com/v2/oauth2/authorize', }, { displayName: 'Access Token URL', name: 'accessTokenUrl', type: 'hidden', - default: 'https://api.meethue.com/oauth2/token', + default: 'https://api.meethue.com/v2/oauth2/token', }, { displayName: 'Auth URI Query Parameters', diff --git a/packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts b/packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts index b7bd4fd1ab..77987f40ef 100644 --- a/packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts +++ b/packages/nodes-base/nodes/PhilipsHue/GenericFunctions.ts @@ -19,7 +19,7 @@ export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOption method, body, qs, - uri: uri || `https://api.meethue.com${resource}`, + uri: uri || `https://api.meethue.com/route${resource}`, json: true, }; try { @@ -36,14 +36,15 @@ export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOption } //@ts-ignore - return await this.helpers.requestOAuth2.call(this, 'philipsHueOAuth2Api', options, { tokenType: 'Bearer' }); + const response = await this.helpers.requestOAuth2.call(this, 'philipsHueOAuth2Api', options, { tokenType: 'Bearer' }); + return response; } catch (error) { throw new NodeApiError(this.getNode(), error); } } export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions): Promise { // tslint:disable-line:no-any - const { whitelist } = await philipsHueApiRequest.call(this, 'GET', '/bridge/0/config', {}, {}); + const { whitelist } = await philipsHueApiRequest.call(this, 'GET', '/api/0/config', {}, {}); //check if there is a n8n user for (const user of Object.keys(whitelist)) { if (whitelist[user].name === 'n8n') { @@ -51,7 +52,7 @@ export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions): } } // n8n user was not fount then create the user - await philipsHueApiRequest.call(this, 'PUT', '/bridge/0/config', { linkbutton: true }); - const { success } = await philipsHueApiRequest.call(this, 'POST', '/bridge', { devicetype: 'n8n' }); + await philipsHueApiRequest.call(this, 'PUT', '/api/0/config', { linkbutton: true }); + const { success } = await philipsHueApiRequest.call(this, 'POST', '/api', { devicetype: 'n8n' }); return success.username; } diff --git a/packages/nodes-base/nodes/PhilipsHue/LightDescription.ts b/packages/nodes-base/nodes/PhilipsHue/LightDescription.ts index 23b4f329aa..4e155f01ec 100644 --- a/packages/nodes-base/nodes/PhilipsHue/LightDescription.ts +++ b/packages/nodes-base/nodes/PhilipsHue/LightDescription.ts @@ -33,7 +33,7 @@ export const lightOperations: INodeProperties[] = [ { name: 'Update', value: 'update', - description: 'Update an light', + description: 'Update a light', }, ], default: 'update', diff --git a/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts b/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts index 4068c32cf8..f23a3d276a 100644 --- a/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts +++ b/packages/nodes-base/nodes/PhilipsHue/PhilipsHue.node.ts @@ -74,13 +74,13 @@ export class PhilipsHue implements INodeType { const lights = await philipsHueApiRequest.call( this, 'GET', - `/bridge/${user}/lights`, + `/api/${user}/lights`, ); const groups = await philipsHueApiRequest.call( this, 'GET', - `/bridge/${user}/groups`, + `/api/${user}/groups`, ); for (const light of Object.keys(lights)) { @@ -144,7 +144,7 @@ export class PhilipsHue implements INodeType { const data = await philipsHueApiRequest.call( this, 'PUT', - `/bridge/${user}/lights/${lightId}/state`, + `/api/${user}/lights/${lightId}/state`, body, ); @@ -161,7 +161,7 @@ export class PhilipsHue implements INodeType { const user = await getUser.call(this); - responseData = await philipsHueApiRequest.call(this, 'DELETE', `/bridge/${user}/lights/${lightId}`); + responseData = await philipsHueApiRequest.call(this, 'DELETE', `/api/${user}/lights/${lightId}`); } if (operation === 'getAll') { @@ -169,7 +169,7 @@ export class PhilipsHue implements INodeType { const user = await getUser.call(this); - const lights = await philipsHueApiRequest.call(this, 'GET', `/bridge/${user}/lights`); + const lights = await philipsHueApiRequest.call(this, 'GET', `/api/${user}/lights`); responseData = Object.values(lights); @@ -183,7 +183,7 @@ export class PhilipsHue implements INodeType { const user = await getUser.call(this); - responseData = await philipsHueApiRequest.call(this, 'GET', `/bridge/${user}/lights/${lightId}`); + responseData = await philipsHueApiRequest.call(this, 'GET', `/api/${user}/lights/${lightId}`); } } }