homebridge-nuheat2 1.2.21 → 1.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +7 -1
- package/lib/NuHeatAPI.js +180 -51
- package/lib/NuHeatListener.js +2 -1
- package/lib/settings.js +16 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,31 @@ All notable changes to this project should be documented in this file
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [1.2.23] - 2026-07-08
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Follow Nuheat's updated OAuth browser redirects during login and consent so PKCE token exchange no longer fails with `invalid_grant`
|
|
12
|
+
- Preserve Nuheat consent cookies through the final authorization callback and select the correct login/consent forms when the identity page includes multiple forms
|
|
13
|
+
- Add regression tests for the Conductor/NAM OAuth login and consent flow
|
|
14
|
+
|
|
15
|
+
## [1.2.22] - 2026-07-07
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Switch Nuheat OAuth, REST, and notification defaults to the Conductor North America hosts after the July 2026 Signature thermostat migration
|
|
20
|
+
- Centralize Nuheat endpoint construction and add environment-variable host overrides for emergency troubleshooting
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Document the Conductor/NAM API host migration in the README
|
|
25
|
+
|
|
26
|
+
## [1.2.21] - 2026-06-25
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Add explicit package author metadata so npm identifies Joshua Appleman as the package author
|
|
31
|
+
|
|
7
32
|
## [1.2.20] - 2026-04-30
|
|
8
33
|
|
|
9
34
|
### Changed
|
package/README.md
CHANGED
|
@@ -106,9 +106,14 @@ If `exposeScheduleSwitches` is enabled, the plugin will also create one switch p
|
|
|
106
106
|
|
|
107
107
|
This plugin uses Nuheat's PKCE-based public client for normal authentication. The built-in public `clientId` is `homebridge-nuheat2_260421`; there is no distributable client secret and no user API key setup is required.
|
|
108
108
|
|
|
109
|
+
Nuheat migrated Signature thermostats to the Conductor server architecture in July 2026. Current plugin releases use the North America Conductor API hosts by default:
|
|
110
|
+
|
|
111
|
+
- Identity: `https://identity.nam.mynuheat.com`
|
|
112
|
+
- OpenAPI: `https://api.nam.mynuheat.com`
|
|
113
|
+
|
|
109
114
|
References:
|
|
110
115
|
|
|
111
|
-
- [Nuheat OpenAPI docs](https://api.mynuheat.com/)
|
|
116
|
+
- [Nuheat OpenAPI docs](https://api.nam.mynuheat.com/)
|
|
112
117
|
- [Nuheat API access request page](https://www.nuheat.com/openapi)
|
|
113
118
|
|
|
114
119
|
## Troubleshooting
|
|
@@ -116,6 +121,7 @@ References:
|
|
|
116
121
|
- Enable debug logging from the custom UI only while troubleshooting. Debug logs include detailed Nuheat API, notification, and accessory activity.
|
|
117
122
|
- If accessories do not appear after changing allow-lists, save the settings and restart the Nuheat child bridge.
|
|
118
123
|
- If login fails, confirm the same email and password work in the Nuheat app or web portal.
|
|
124
|
+
- If Nuheat changes regional API routing again, advanced users can temporarily override the runtime hosts with `NUHEAT_API_BASE_URL` and `NUHEAT_IDENTITY_BASE_URL`.
|
|
119
125
|
- If Homebridge shows stale UI fields after an update, close and reopen the plugin settings page.
|
|
120
126
|
|
|
121
127
|
## Development
|
package/lib/NuHeatAPI.js
CHANGED
|
@@ -108,7 +108,7 @@ class NuHeatAPI {
|
|
|
108
108
|
return requestBody;
|
|
109
109
|
}
|
|
110
110
|
async setAwayMode(groupId, awayMode) {
|
|
111
|
-
const callURL = "
|
|
111
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Group");
|
|
112
112
|
const callOptions = {
|
|
113
113
|
body: JSON.stringify({
|
|
114
114
|
groupId,
|
|
@@ -135,7 +135,7 @@ class NuHeatAPI {
|
|
|
135
135
|
else {
|
|
136
136
|
scheduleMode = NuHeatModels_1.SCHEDULE_MODE.AUTO;
|
|
137
137
|
}
|
|
138
|
-
const callURL = "
|
|
138
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Thermostat");
|
|
139
139
|
const callBody = {
|
|
140
140
|
serialNumber,
|
|
141
141
|
setPointTemp,
|
|
@@ -158,7 +158,7 @@ class NuHeatAPI {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
async updateThermostat(thermostatUpdate) {
|
|
161
|
-
const callURL = "
|
|
161
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Thermostat");
|
|
162
162
|
const callOptions = {
|
|
163
163
|
body: JSON.stringify(thermostatUpdate),
|
|
164
164
|
method: "PUT",
|
|
@@ -168,48 +168,48 @@ class NuHeatAPI {
|
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
async refreshGroup(groupId) {
|
|
171
|
-
const callURL = "
|
|
171
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Group/" + groupId);
|
|
172
172
|
return await this.makeAPICall(callURL, {}, { normalize: NuHeatModels_1.normalizeGroup });
|
|
173
173
|
}
|
|
174
174
|
async refreshGroups() {
|
|
175
|
-
const callURL = "
|
|
175
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Group");
|
|
176
176
|
return await this.makeAPICall(callURL, {}, {
|
|
177
177
|
normalize: NuHeatModels_1.normalizeGroup,
|
|
178
178
|
normalizeArray: true,
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
async refreshThermostat(serialNumber) {
|
|
182
|
-
const callURL = "
|
|
182
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Thermostat/" + serialNumber);
|
|
183
183
|
return await this.makeAPICall(callURL, {}, {
|
|
184
184
|
normalize: NuHeatModels_1.normalizeThermostat,
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
async refreshThermostats() {
|
|
188
|
-
const callURL = "
|
|
188
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Thermostat");
|
|
189
189
|
return await this.makeAPICall(callURL, {}, {
|
|
190
190
|
normalize: NuHeatModels_1.normalizeThermostat,
|
|
191
191
|
normalizeArray: true,
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
async getAccount() {
|
|
195
|
-
const callURL = "
|
|
195
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Account");
|
|
196
196
|
return await this.makeAPICall(callURL, {}, { normalize: NuHeatModels_1.normalizeAccount });
|
|
197
197
|
}
|
|
198
198
|
async refreshSchedule(serialNumber) {
|
|
199
|
-
const callURL = "
|
|
199
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Schedule/" + serialNumber);
|
|
200
200
|
return await this.makeAPICall(callURL, {}, {
|
|
201
201
|
normalize: NuHeatModels_1.normalizeSchedule,
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
204
|
async refreshSchedules() {
|
|
205
|
-
const callURL = "
|
|
205
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Schedule");
|
|
206
206
|
return await this.makeAPICall(callURL, {}, {
|
|
207
207
|
normalize: NuHeatModels_1.normalizeSchedule,
|
|
208
208
|
normalizeArray: true,
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
async updateSchedule(scheduleModel) {
|
|
212
|
-
const callURL = "
|
|
212
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Schedule");
|
|
213
213
|
return await this.makeAPICall(callURL, {
|
|
214
214
|
body: JSON.stringify(scheduleModel),
|
|
215
215
|
method: "PUT",
|
|
@@ -218,28 +218,19 @@ class NuHeatAPI {
|
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
220
|
async refreshEnergyLogDay(serialNumber, date) {
|
|
221
|
-
const callURL = "
|
|
222
|
-
serialNumber +
|
|
223
|
-
"/" +
|
|
224
|
-
date;
|
|
221
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/EnergyLog/Day/" + serialNumber + "/" + date);
|
|
225
222
|
return await this.makeAPICall(callURL, {}, {
|
|
226
223
|
normalize: NuHeatModels_1.normalizeEnergyUsage,
|
|
227
224
|
});
|
|
228
225
|
}
|
|
229
226
|
async refreshEnergyLogWeek(serialNumber, date) {
|
|
230
|
-
const callURL = "
|
|
231
|
-
serialNumber +
|
|
232
|
-
"/" +
|
|
233
|
-
date;
|
|
227
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/EnergyLog/Week/" + serialNumber + "/" + date);
|
|
234
228
|
return await this.makeAPICall(callURL, {}, {
|
|
235
229
|
normalize: NuHeatModels_1.normalizeEnergyUsage,
|
|
236
230
|
});
|
|
237
231
|
}
|
|
238
232
|
async refreshEnergyLogMonth(serialNumber, year) {
|
|
239
|
-
const callURL = "
|
|
240
|
-
serialNumber +
|
|
241
|
-
"/" +
|
|
242
|
-
year;
|
|
233
|
+
const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/EnergyLog/Month/" + serialNumber + "/" + year);
|
|
243
234
|
return await this.makeAPICall(callURL, {}, {
|
|
244
235
|
normalize: NuHeatModels_1.normalizeEnergyUsage,
|
|
245
236
|
});
|
|
@@ -281,6 +272,110 @@ class NuHeatAPI {
|
|
|
281
272
|
return "";
|
|
282
273
|
}
|
|
283
274
|
}
|
|
275
|
+
findForm(html, selector) {
|
|
276
|
+
return (html
|
|
277
|
+
.querySelectorAll("form")
|
|
278
|
+
.find((form) => form.querySelector(selector)) || html);
|
|
279
|
+
}
|
|
280
|
+
getFormAction(form, baseUrl, fallbackUrl) {
|
|
281
|
+
return new URL(form.getAttribute?.("action") || fallbackUrl, baseUrl).toString();
|
|
282
|
+
}
|
|
283
|
+
getInputValue(html, name) {
|
|
284
|
+
return (html.querySelector("input[name=" + name + "]")?.getAttribute("value") ||
|
|
285
|
+
"");
|
|
286
|
+
}
|
|
287
|
+
getCheckedInputValues(html, name) {
|
|
288
|
+
const values = [];
|
|
289
|
+
for (const input of html.querySelectorAll("input[name=" + name + "]")) {
|
|
290
|
+
const type = (input.getAttribute("type") || "").toLowerCase();
|
|
291
|
+
const value = input.getAttribute("value") || "";
|
|
292
|
+
if (value &&
|
|
293
|
+
((type === "checkbox" && input.hasAttribute("checked")) ||
|
|
294
|
+
type === "hidden")) {
|
|
295
|
+
if (!values.includes(value)) {
|
|
296
|
+
values.push(value);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return values;
|
|
301
|
+
}
|
|
302
|
+
getHtmlMetaRefreshUrl(htmlText, baseUrl) {
|
|
303
|
+
const html = parse(htmlText);
|
|
304
|
+
const metaRefresh = html
|
|
305
|
+
.querySelectorAll("meta")
|
|
306
|
+
.find((node) => (node.getAttribute("http-equiv") || "").toLowerCase() === "refresh");
|
|
307
|
+
const refreshContent = metaRefresh?.getAttribute("content") || "";
|
|
308
|
+
const redirectMatch = refreshContent.match(/url\s*=\s*([^;]+)/i);
|
|
309
|
+
if (!redirectMatch) {
|
|
310
|
+
return "";
|
|
311
|
+
}
|
|
312
|
+
const redirectUrl = redirectMatch[1]
|
|
313
|
+
.trim()
|
|
314
|
+
.replace(/^['"]|['"]$/g, "");
|
|
315
|
+
return new URL(redirectUrl, baseUrl).toString();
|
|
316
|
+
}
|
|
317
|
+
mergeCookies(...cookies) {
|
|
318
|
+
const cookiePairs = new Map();
|
|
319
|
+
for (const cookie of cookies) {
|
|
320
|
+
if (!cookie) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
for (const cookiePair of cookie.split(/;\s*/)) {
|
|
324
|
+
const cookieName = cookiePair.split("=")[0];
|
|
325
|
+
if (cookieName) {
|
|
326
|
+
cookiePairs.set(cookieName, cookiePair);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return Array.from(cookiePairs.values()).join("; ");
|
|
331
|
+
}
|
|
332
|
+
async followHtmlMetaRefresh(response, cookie) {
|
|
333
|
+
if (response.headers.get("location")) {
|
|
334
|
+
return response;
|
|
335
|
+
}
|
|
336
|
+
const redirectUrl = this.getHtmlMetaRefreshUrl(await response.text(), response.url);
|
|
337
|
+
if (!redirectUrl) {
|
|
338
|
+
return response;
|
|
339
|
+
}
|
|
340
|
+
this.log.debug("NuHeatAPI: Following OAuth browser redirect to " +
|
|
341
|
+
new URL(redirectUrl).pathname +
|
|
342
|
+
".");
|
|
343
|
+
const redirectResponse = await this.fetch(redirectUrl, {
|
|
344
|
+
headers: {
|
|
345
|
+
Cookie: cookie,
|
|
346
|
+
},
|
|
347
|
+
redirect: "manual",
|
|
348
|
+
});
|
|
349
|
+
if (!redirectResponse) {
|
|
350
|
+
this.log.error("NuHeatAPI: Unable to follow the OAuth browser redirect.");
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return redirectResponse;
|
|
354
|
+
}
|
|
355
|
+
getRedirectUrl(response) {
|
|
356
|
+
const location = response.headers.get("location");
|
|
357
|
+
if (!location) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
return new URL(location, settings_1.NUHEAT_API_AUTHORIZE_URI);
|
|
361
|
+
}
|
|
362
|
+
isFinalAuthorizationRedirect(response) {
|
|
363
|
+
const redirectUrl = this.getRedirectUrl(response);
|
|
364
|
+
if (!redirectUrl) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
return (redirectUrl.searchParams.has("code") ||
|
|
368
|
+
redirectUrl.searchParams.has("error"));
|
|
369
|
+
}
|
|
370
|
+
needsOAuthConsent(response) {
|
|
371
|
+
const redirectUrl = this.getRedirectUrl(response);
|
|
372
|
+
if (!redirectUrl || this.isFinalAuthorizationRedirect(response)) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
const redirectPath = redirectUrl.pathname.toLowerCase();
|
|
376
|
+
return (redirectPath === "/connect/authorize/callback" ||
|
|
377
|
+
redirectPath === "/consent");
|
|
378
|
+
}
|
|
284
379
|
async oauthGetAuthPage() {
|
|
285
380
|
const authEndpoint = new URL(settings_1.NUHEAT_API_AUTHORIZE_URI);
|
|
286
381
|
authEndpoint.searchParams.set("response_type", "code");
|
|
@@ -309,19 +404,20 @@ class NuHeatAPI {
|
|
|
309
404
|
if (cookie) {
|
|
310
405
|
const htmlText = await authPage.text();
|
|
311
406
|
const loginPageHtml = parse(htmlText);
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
.querySelector("input[name=ReturnUrl]")
|
|
317
|
-
?.getAttribute("value") || "";
|
|
407
|
+
const loginForm = this.findForm(loginPageHtml, "input[name=Password]");
|
|
408
|
+
const requestVerificationToken = this.getInputValue(loginForm, "__RequestVerificationToken");
|
|
409
|
+
const requestReturnURL = this.getInputValue(loginForm, "ReturnUrl") ||
|
|
410
|
+
this.getInputValue(loginPageHtml, "ReturnUrl");
|
|
318
411
|
if (!requestVerificationToken) {
|
|
319
412
|
this.log.error("NuHeatAPI: Unable to complete OAuth login. The verification token could not be retrieved.");
|
|
320
413
|
return null;
|
|
321
414
|
}
|
|
415
|
+
const usernameField = loginForm.querySelector("input[name=Email]")
|
|
416
|
+
? "Email"
|
|
417
|
+
: "Username";
|
|
322
418
|
const loginBody = new URLSearchParams({
|
|
323
419
|
ReturnUrl: requestReturnURL,
|
|
324
|
-
|
|
420
|
+
[usernameField]: this.email,
|
|
325
421
|
Password: this.password,
|
|
326
422
|
button: "login",
|
|
327
423
|
__RequestVerificationToken: requestVerificationToken,
|
|
@@ -350,26 +446,48 @@ class NuHeatAPI {
|
|
|
350
446
|
return null;
|
|
351
447
|
}
|
|
352
448
|
async oauthConfirm(authPage, sessionCookie) {
|
|
353
|
-
const redirectUrl =
|
|
354
|
-
|
|
449
|
+
const redirectUrl = this.getRedirectUrl(authPage);
|
|
450
|
+
if (!redirectUrl) {
|
|
451
|
+
this.log.error("NuHeatAPI: Unable to complete the OAuth login redirect.");
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
let confirmPage = await this.fetch(redirectUrl.toString(), {
|
|
355
455
|
headers: {
|
|
356
456
|
Cookie: sessionCookie,
|
|
357
457
|
},
|
|
458
|
+
redirect: "manual",
|
|
358
459
|
});
|
|
359
460
|
if (!confirmPage) {
|
|
360
461
|
this.log.error("NuHeatAPI: Unable to complete the OAuth login redirect.");
|
|
361
462
|
return null;
|
|
362
463
|
}
|
|
464
|
+
const callbackCookie = this.trimSetCookie(confirmPage.headers.raw?.()["set-cookie"]);
|
|
465
|
+
const callbackSessionCookie = this.mergeCookies(sessionCookie, callbackCookie);
|
|
466
|
+
if (this.isFinalAuthorizationRedirect(confirmPage)) {
|
|
467
|
+
return confirmPage;
|
|
468
|
+
}
|
|
469
|
+
const confirmRedirectUrl = this.getRedirectUrl(confirmPage);
|
|
470
|
+
if (confirmRedirectUrl?.pathname.toLowerCase() === "/consent") {
|
|
471
|
+
confirmPage = await this.fetch(confirmRedirectUrl.toString(), {
|
|
472
|
+
headers: {
|
|
473
|
+
Cookie: callbackSessionCookie,
|
|
474
|
+
},
|
|
475
|
+
redirect: "manual",
|
|
476
|
+
});
|
|
477
|
+
if (!confirmPage) {
|
|
478
|
+
this.log.error("NuHeatAPI: Unable to access the OAuth consent confirmation page.");
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
363
482
|
const cookie = this.trimSetCookie(confirmPage.headers.raw?.()["set-cookie"]);
|
|
364
|
-
|
|
483
|
+
const consentSessionCookie = this.mergeCookies(callbackSessionCookie, cookie);
|
|
484
|
+
if (consentSessionCookie) {
|
|
365
485
|
const htmlText = await confirmPage.text();
|
|
366
486
|
const loginPageHtml = parse(htmlText);
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
.querySelector("input[name=ReturnUrl]")
|
|
372
|
-
?.getAttribute("value") || "";
|
|
487
|
+
const consentForm = this.findForm(loginPageHtml, "input[name=ScopesConsented]");
|
|
488
|
+
const requestVerificationToken = this.getInputValue(consentForm, "__RequestVerificationToken");
|
|
489
|
+
const requestReturnURL = this.getInputValue(consentForm, "ReturnUrl") ||
|
|
490
|
+
this.getInputValue(loginPageHtml, "ReturnUrl");
|
|
373
491
|
if (!requestVerificationToken) {
|
|
374
492
|
this.log.error("NuHeatAPI: Unable to complete OAuth login. The api access couldn't be confirmed.");
|
|
375
493
|
return null;
|
|
@@ -380,14 +498,19 @@ class NuHeatAPI {
|
|
|
380
498
|
RememberConsent: "true",
|
|
381
499
|
__RequestVerificationToken: requestVerificationToken,
|
|
382
500
|
});
|
|
501
|
+
const checkedScopes = this.getCheckedInputValues(consentForm, "ScopesConsented");
|
|
502
|
+
const scopes = checkedScopes.length > 0 ? checkedScopes : [...OAUTH_SCOPES];
|
|
503
|
+
for (const scope of scopes) {
|
|
504
|
+
loginBody.append("ScopesConsented", scope);
|
|
505
|
+
}
|
|
383
506
|
this.log.debug("NuHeatAPI: OAuth consent required. Confirming scopes: " +
|
|
384
507
|
this.getRequestedScope());
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
508
|
+
const consentUrl = this.getFormAction(consentForm, confirmPage.url, settings_1.NUHEAT_API_CONSENT_URI);
|
|
509
|
+
const response = await this.fetch(consentUrl, {
|
|
510
|
+
body: loginBody.toString(),
|
|
388
511
|
headers: {
|
|
389
512
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
390
|
-
Cookie:
|
|
513
|
+
Cookie: consentSessionCookie,
|
|
391
514
|
},
|
|
392
515
|
method: "POST",
|
|
393
516
|
redirect: "manual",
|
|
@@ -396,17 +519,18 @@ class NuHeatAPI {
|
|
|
396
519
|
this.log.error("NuHeatAPI: Unable to complete OAuth login. API access confirmation not completed.");
|
|
397
520
|
return null;
|
|
398
521
|
}
|
|
399
|
-
|
|
522
|
+
const responseCookie = this.trimSetCookie(response.headers.raw?.()["set-cookie"]);
|
|
523
|
+
return await this.followHtmlMetaRefresh(response, this.mergeCookies(consentSessionCookie, responseCookie));
|
|
400
524
|
}
|
|
401
525
|
return null;
|
|
402
526
|
}
|
|
403
527
|
async oauthRedirect(loginResponse, sessionCookie) {
|
|
404
528
|
const redirectUrl = new URL(loginResponse.headers.get("location") || "", settings_1.NUHEAT_API_AUTHORIZE_URI);
|
|
405
|
-
const cookie = this.trimSetCookie(loginResponse.headers.raw?.()["set-cookie"]);
|
|
529
|
+
const cookie = this.mergeCookies(sessionCookie, this.trimSetCookie(loginResponse.headers.raw?.()["set-cookie"]));
|
|
406
530
|
if (cookie) {
|
|
407
531
|
const response = await this.fetch(redirectUrl.toString(), {
|
|
408
532
|
headers: {
|
|
409
|
-
Cookie: cookie
|
|
533
|
+
Cookie: cookie,
|
|
410
534
|
},
|
|
411
535
|
redirect: "manual",
|
|
412
536
|
});
|
|
@@ -429,16 +553,21 @@ class NuHeatAPI {
|
|
|
429
553
|
}
|
|
430
554
|
const sessionCookie = this.trimSetCookie(response.headers.raw?.()["set-cookie"]);
|
|
431
555
|
if (sessionCookie) {
|
|
432
|
-
|
|
433
|
-
|
|
556
|
+
response = await this.followHtmlMetaRefresh(response, sessionCookie);
|
|
557
|
+
if (!response) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
if (this.needsOAuthConsent(response)) {
|
|
434
561
|
response = await this.oauthConfirm(response, sessionCookie);
|
|
435
562
|
if (!response) {
|
|
436
563
|
return null;
|
|
437
564
|
}
|
|
438
565
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
566
|
+
if (!this.isFinalAuthorizationRedirect(response)) {
|
|
567
|
+
response = await this.oauthRedirect(response, sessionCookie);
|
|
568
|
+
if (!response) {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
442
571
|
}
|
|
443
572
|
const redirectUrl = new URL(response.headers.get("location") || "");
|
|
444
573
|
const requestBody = this.buildAuthorizationCodeTokenRequest(redirectUrl);
|
package/lib/NuHeatListener.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const signalR = require("@microsoft/signalr");
|
|
3
|
+
const settings_1 = require("./settings");
|
|
3
4
|
const NOTIFICATION_DEDUPE_WINDOW_MS = 2000;
|
|
4
5
|
class NuHeatListener {
|
|
5
6
|
nuHeatAPI;
|
|
@@ -15,7 +16,7 @@ class NuHeatListener {
|
|
|
15
16
|
this.notificationTypes = ["2", "3", "4"];
|
|
16
17
|
this.recentNotifications = new Map();
|
|
17
18
|
this.connection = new signalR.HubConnectionBuilder()
|
|
18
|
-
.withUrl(
|
|
19
|
+
.withUrl(settings_1.NUHEAT_NOTIFICATION_HUB_URL, {
|
|
19
20
|
accessTokenFactory: async () => {
|
|
20
21
|
return (await this.nuHeatAPI.returnAccessToken()) || "";
|
|
21
22
|
},
|
package/lib/settings.js
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NUHEAT_API_CONSENT_URI = exports.NUHEAT_API_TOKEN_URI = exports.NUHEAT_API_AUTHORIZE_URI = exports.NUHEAT_API_REDIRECT_URI = exports.NUHEAT_API_CLIENT_SECRET = exports.NUHEAT_API_CLIENT_ID = void 0;
|
|
3
|
+
exports.NUHEAT_NOTIFICATION_HUB_URL = exports.NUHEAT_API_CONSENT_URI = exports.NUHEAT_API_TOKEN_URI = exports.NUHEAT_API_AUTHORIZE_URI = exports.NUHEAT_IDENTITY_BASE_URL = exports.NUHEAT_API_BASE_URL = exports.NUHEAT_API_REDIRECT_URI = exports.NUHEAT_API_CLIENT_SECRET = exports.NUHEAT_API_CLIENT_ID = void 0;
|
|
4
|
+
exports.buildNuHeatApiUrl = buildNuHeatApiUrl;
|
|
4
5
|
exports.NUHEAT_API_CLIENT_ID = "homebridge-nuheat2_260421";
|
|
5
6
|
exports.NUHEAT_API_CLIENT_SECRET = "";
|
|
6
7
|
exports.NUHEAT_API_REDIRECT_URI = "http://localhost";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const DEFAULT_NUHEAT_API_BASE_URL = "https://api.nam.mynuheat.com";
|
|
9
|
+
const DEFAULT_NUHEAT_IDENTITY_BASE_URL = "https://identity.nam.mynuheat.com";
|
|
10
|
+
function normalizeBaseUrl(url) {
|
|
11
|
+
return url.replace(/\/+$/, "");
|
|
12
|
+
}
|
|
13
|
+
exports.NUHEAT_API_BASE_URL = normalizeBaseUrl(process.env.NUHEAT_API_BASE_URL || DEFAULT_NUHEAT_API_BASE_URL);
|
|
14
|
+
exports.NUHEAT_IDENTITY_BASE_URL = normalizeBaseUrl(process.env.NUHEAT_IDENTITY_BASE_URL || DEFAULT_NUHEAT_IDENTITY_BASE_URL);
|
|
15
|
+
function buildNuHeatApiUrl(path) {
|
|
16
|
+
return exports.NUHEAT_API_BASE_URL + (path.startsWith("/") ? path : "/" + path);
|
|
17
|
+
}
|
|
18
|
+
exports.NUHEAT_API_AUTHORIZE_URI = exports.NUHEAT_IDENTITY_BASE_URL + "/connect/authorize";
|
|
19
|
+
exports.NUHEAT_API_TOKEN_URI = exports.NUHEAT_IDENTITY_BASE_URL + "/connect/token";
|
|
20
|
+
exports.NUHEAT_API_CONSENT_URI = exports.NUHEAT_IDENTITY_BASE_URL + "/consent";
|
|
21
|
+
exports.NUHEAT_NOTIFICATION_HUB_URL = exports.NUHEAT_API_BASE_URL + "/notificationsHost";
|