🐛 Fix Philips Hue API Connection (#2631)

* 🐛 Fix Philips Hue API Connection

* Philips Hue Node: Fixed typo in  update operation description
This commit is contained in:
Tom 2022-01-13 07:51:58 +01:00 committed by GitHub
parent c9e1892cd9
commit e0ef645514
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

View file

@ -21,13 +21,13 @@ export class PhilipsHueOAuth2Api implements ICredentialType {
displayName: 'Authorization URL', displayName: 'Authorization URL',
name: 'authUrl', name: 'authUrl',
type: 'hidden', type: 'hidden',
default: 'https://api.meethue.com/oauth2/auth', default: 'https://api.meethue.com/v2/oauth2/authorize',
}, },
{ {
displayName: 'Access Token URL', displayName: 'Access Token URL',
name: 'accessTokenUrl', name: 'accessTokenUrl',
type: 'hidden', type: 'hidden',
default: 'https://api.meethue.com/oauth2/token', default: 'https://api.meethue.com/v2/oauth2/token',
}, },
{ {
displayName: 'Auth URI Query Parameters', displayName: 'Auth URI Query Parameters',

View file

@ -19,7 +19,7 @@ export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOption
method, method,
body, body,
qs, qs,
uri: uri || `https://api.meethue.com${resource}`, uri: uri || `https://api.meethue.com/route${resource}`,
json: true, json: true,
}; };
try { try {
@ -36,14 +36,15 @@ export async function philipsHueApiRequest(this: IExecuteFunctions | ILoadOption
} }
//@ts-ignore //@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) { } catch (error) {
throw new NodeApiError(this.getNode(), error); throw new NodeApiError(this.getNode(), error);
} }
} }
export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions): Promise<any> { // tslint:disable-line:no-any export async function getUser(this: IExecuteFunctions | ILoadOptionsFunctions): Promise<any> { // 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 //check if there is a n8n user
for (const user of Object.keys(whitelist)) { for (const user of Object.keys(whitelist)) {
if (whitelist[user].name === 'n8n') { 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 // n8n user was not fount then create the user
await philipsHueApiRequest.call(this, 'PUT', '/bridge/0/config', { linkbutton: true }); await philipsHueApiRequest.call(this, 'PUT', '/api/0/config', { linkbutton: true });
const { success } = await philipsHueApiRequest.call(this, 'POST', '/bridge', { devicetype: 'n8n' }); const { success } = await philipsHueApiRequest.call(this, 'POST', '/api', { devicetype: 'n8n' });
return success.username; return success.username;
} }

View file

@ -33,7 +33,7 @@ export const lightOperations: INodeProperties[] = [
{ {
name: 'Update', name: 'Update',
value: 'update', value: 'update',
description: 'Update an light', description: 'Update a light',
}, },
], ],
default: 'update', default: 'update',

View file

@ -74,13 +74,13 @@ export class PhilipsHue implements INodeType {
const lights = await philipsHueApiRequest.call( const lights = await philipsHueApiRequest.call(
this, this,
'GET', 'GET',
`/bridge/${user}/lights`, `/api/${user}/lights`,
); );
const groups = await philipsHueApiRequest.call( const groups = await philipsHueApiRequest.call(
this, this,
'GET', 'GET',
`/bridge/${user}/groups`, `/api/${user}/groups`,
); );
for (const light of Object.keys(lights)) { for (const light of Object.keys(lights)) {
@ -144,7 +144,7 @@ export class PhilipsHue implements INodeType {
const data = await philipsHueApiRequest.call( const data = await philipsHueApiRequest.call(
this, this,
'PUT', 'PUT',
`/bridge/${user}/lights/${lightId}/state`, `/api/${user}/lights/${lightId}/state`,
body, body,
); );
@ -161,7 +161,7 @@ export class PhilipsHue implements INodeType {
const user = await getUser.call(this); 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') { if (operation === 'getAll') {
@ -169,7 +169,7 @@ export class PhilipsHue implements INodeType {
const user = await getUser.call(this); 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); responseData = Object.values(lights);
@ -183,7 +183,7 @@ export class PhilipsHue implements INodeType {
const user = await getUser.call(this); 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}`);
} }
} }
} }