homebridge-nuheat2 1.2.22 → 1.2.24
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 +16 -0
- package/README.md +3 -2
- package/lib/NuHeatAPI.js +166 -28
- package/lib/NuHeatListener.js +8 -4
- package/lib/settings.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,22 @@ All notable changes to this project should be documented in this file
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [1.2.24] - 2026-07-08
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Restore Nuheat SignalR notifications on the Conductor/NAM API by using the documented v2 notification hub
|
|
12
|
+
- Subscribe with Nuheat's numeric v2 notification IDs and direct WebSocket transport to avoid flaky negotiated connections behind the new backend
|
|
13
|
+
- Document the v2 notification host and `NUHEAT_NOTIFICATION_HUB_URL` emergency override
|
|
14
|
+
|
|
15
|
+
## [1.2.23] - 2026-07-08
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Follow Nuheat's updated OAuth browser redirects during login and consent so PKCE token exchange no longer fails with `invalid_grant`
|
|
20
|
+
- Preserve Nuheat consent cookies through the final authorization callback and select the correct login/consent forms when the identity page includes multiple forms
|
|
21
|
+
- Add regression tests for the Conductor/NAM OAuth login and consent flow
|
|
22
|
+
|
|
7
23
|
## [1.2.22] - 2026-07-07
|
|
8
24
|
|
|
9
25
|
### Fixed
|
package/README.md
CHANGED
|
@@ -110,6 +110,7 @@ Nuheat migrated Signature thermostats to the Conductor server architecture in Ju
|
|
|
110
110
|
|
|
111
111
|
- Identity: `https://identity.nam.mynuheat.com`
|
|
112
112
|
- OpenAPI: `https://api.nam.mynuheat.com`
|
|
113
|
+
- Notifications: `https://api.nam.mynuheat.com/v2/notificationsHost`
|
|
113
114
|
|
|
114
115
|
References:
|
|
115
116
|
|
|
@@ -121,7 +122,7 @@ References:
|
|
|
121
122
|
- Enable debug logging from the custom UI only while troubleshooting. Debug logs include detailed Nuheat API, notification, and accessory activity.
|
|
122
123
|
- If accessories do not appear after changing allow-lists, save the settings and restart the Nuheat child bridge.
|
|
123
124
|
- 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 `
|
|
125
|
+
- If Nuheat changes regional API routing again, advanced users can temporarily override the runtime hosts with `NUHEAT_API_BASE_URL`, `NUHEAT_IDENTITY_BASE_URL`, and `NUHEAT_NOTIFICATION_HUB_URL`.
|
|
125
126
|
- If Homebridge shows stale UI fields after an update, close and reopen the plugin settings page.
|
|
126
127
|
|
|
127
128
|
## Development
|
|
@@ -151,4 +152,4 @@ This project is maintained by `applemanj` and retains attribution to SenorShaun
|
|
|
151
152
|
|
|
152
153
|
- Validate the PKCE public-client flow against more real-world Nuheat accounts.
|
|
153
154
|
- Verify group and away-mode behavior against current live API responses.
|
|
154
|
-
-
|
|
155
|
+
- Monitor Nuheat Conductor v2 notification behavior across more accounts and keep polling as the reliability fallback.
|
package/lib/NuHeatAPI.js
CHANGED
|
@@ -272,6 +272,110 @@ class NuHeatAPI {
|
|
|
272
272
|
return "";
|
|
273
273
|
}
|
|
274
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
|
+
}
|
|
275
379
|
async oauthGetAuthPage() {
|
|
276
380
|
const authEndpoint = new URL(settings_1.NUHEAT_API_AUTHORIZE_URI);
|
|
277
381
|
authEndpoint.searchParams.set("response_type", "code");
|
|
@@ -300,19 +404,20 @@ class NuHeatAPI {
|
|
|
300
404
|
if (cookie) {
|
|
301
405
|
const htmlText = await authPage.text();
|
|
302
406
|
const loginPageHtml = parse(htmlText);
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
.querySelector("input[name=ReturnUrl]")
|
|
308
|
-
?.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");
|
|
309
411
|
if (!requestVerificationToken) {
|
|
310
412
|
this.log.error("NuHeatAPI: Unable to complete OAuth login. The verification token could not be retrieved.");
|
|
311
413
|
return null;
|
|
312
414
|
}
|
|
415
|
+
const usernameField = loginForm.querySelector("input[name=Email]")
|
|
416
|
+
? "Email"
|
|
417
|
+
: "Username";
|
|
313
418
|
const loginBody = new URLSearchParams({
|
|
314
419
|
ReturnUrl: requestReturnURL,
|
|
315
|
-
|
|
420
|
+
[usernameField]: this.email,
|
|
316
421
|
Password: this.password,
|
|
317
422
|
button: "login",
|
|
318
423
|
__RequestVerificationToken: requestVerificationToken,
|
|
@@ -341,26 +446,48 @@ class NuHeatAPI {
|
|
|
341
446
|
return null;
|
|
342
447
|
}
|
|
343
448
|
async oauthConfirm(authPage, sessionCookie) {
|
|
344
|
-
const redirectUrl =
|
|
345
|
-
|
|
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(), {
|
|
346
455
|
headers: {
|
|
347
456
|
Cookie: sessionCookie,
|
|
348
457
|
},
|
|
458
|
+
redirect: "manual",
|
|
349
459
|
});
|
|
350
460
|
if (!confirmPage) {
|
|
351
461
|
this.log.error("NuHeatAPI: Unable to complete the OAuth login redirect.");
|
|
352
462
|
return null;
|
|
353
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
|
+
}
|
|
354
482
|
const cookie = this.trimSetCookie(confirmPage.headers.raw?.()["set-cookie"]);
|
|
355
|
-
|
|
483
|
+
const consentSessionCookie = this.mergeCookies(callbackSessionCookie, cookie);
|
|
484
|
+
if (consentSessionCookie) {
|
|
356
485
|
const htmlText = await confirmPage.text();
|
|
357
486
|
const loginPageHtml = parse(htmlText);
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
.querySelector("input[name=ReturnUrl]")
|
|
363
|
-
?.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");
|
|
364
491
|
if (!requestVerificationToken) {
|
|
365
492
|
this.log.error("NuHeatAPI: Unable to complete OAuth login. The api access couldn't be confirmed.");
|
|
366
493
|
return null;
|
|
@@ -371,14 +498,19 @@ class NuHeatAPI {
|
|
|
371
498
|
RememberConsent: "true",
|
|
372
499
|
__RequestVerificationToken: requestVerificationToken,
|
|
373
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
|
+
}
|
|
374
506
|
this.log.debug("NuHeatAPI: OAuth consent required. Confirming scopes: " +
|
|
375
507
|
this.getRequestedScope());
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
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(),
|
|
379
511
|
headers: {
|
|
380
512
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
381
|
-
Cookie:
|
|
513
|
+
Cookie: consentSessionCookie,
|
|
382
514
|
},
|
|
383
515
|
method: "POST",
|
|
384
516
|
redirect: "manual",
|
|
@@ -387,17 +519,18 @@ class NuHeatAPI {
|
|
|
387
519
|
this.log.error("NuHeatAPI: Unable to complete OAuth login. API access confirmation not completed.");
|
|
388
520
|
return null;
|
|
389
521
|
}
|
|
390
|
-
|
|
522
|
+
const responseCookie = this.trimSetCookie(response.headers.raw?.()["set-cookie"]);
|
|
523
|
+
return await this.followHtmlMetaRefresh(response, this.mergeCookies(consentSessionCookie, responseCookie));
|
|
391
524
|
}
|
|
392
525
|
return null;
|
|
393
526
|
}
|
|
394
527
|
async oauthRedirect(loginResponse, sessionCookie) {
|
|
395
528
|
const redirectUrl = new URL(loginResponse.headers.get("location") || "", settings_1.NUHEAT_API_AUTHORIZE_URI);
|
|
396
|
-
const cookie = this.trimSetCookie(loginResponse.headers.raw?.()["set-cookie"]);
|
|
529
|
+
const cookie = this.mergeCookies(sessionCookie, this.trimSetCookie(loginResponse.headers.raw?.()["set-cookie"]));
|
|
397
530
|
if (cookie) {
|
|
398
531
|
const response = await this.fetch(redirectUrl.toString(), {
|
|
399
532
|
headers: {
|
|
400
|
-
Cookie: cookie
|
|
533
|
+
Cookie: cookie,
|
|
401
534
|
},
|
|
402
535
|
redirect: "manual",
|
|
403
536
|
});
|
|
@@ -420,16 +553,21 @@ class NuHeatAPI {
|
|
|
420
553
|
}
|
|
421
554
|
const sessionCookie = this.trimSetCookie(response.headers.raw?.()["set-cookie"]);
|
|
422
555
|
if (sessionCookie) {
|
|
423
|
-
|
|
424
|
-
|
|
556
|
+
response = await this.followHtmlMetaRefresh(response, sessionCookie);
|
|
557
|
+
if (!response) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
if (this.needsOAuthConsent(response)) {
|
|
425
561
|
response = await this.oauthConfirm(response, sessionCookie);
|
|
426
562
|
if (!response) {
|
|
427
563
|
return null;
|
|
428
564
|
}
|
|
429
565
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
566
|
+
if (!this.isFinalAuthorizationRedirect(response)) {
|
|
567
|
+
response = await this.oauthRedirect(response, sessionCookie);
|
|
568
|
+
if (!response) {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
433
571
|
}
|
|
434
572
|
const redirectUrl = new URL(response.headers.get("location") || "");
|
|
435
573
|
const requestBody = this.buildAuthorizationCodeTokenRequest(redirectUrl);
|
package/lib/NuHeatListener.js
CHANGED
|
@@ -8,19 +8,23 @@ class NuHeatListener {
|
|
|
8
8
|
log;
|
|
9
9
|
notificationTypes;
|
|
10
10
|
connection;
|
|
11
|
+
connectionOptions;
|
|
11
12
|
recentNotifications;
|
|
12
13
|
constructor(nuHeatAPI, nuheatPlatform) {
|
|
13
14
|
this.nuHeatAPI = nuHeatAPI;
|
|
14
15
|
this.nuHeatPlatform = nuheatPlatform;
|
|
15
16
|
this.log = nuheatPlatform.log;
|
|
16
|
-
this.notificationTypes = [
|
|
17
|
+
this.notificationTypes = [1, 2];
|
|
17
18
|
this.recentNotifications = new Map();
|
|
18
|
-
this.
|
|
19
|
-
.withUrl(settings_1.NUHEAT_NOTIFICATION_HUB_URL, {
|
|
19
|
+
this.connectionOptions = {
|
|
20
20
|
accessTokenFactory: async () => {
|
|
21
21
|
return (await this.nuHeatAPI.returnAccessToken()) || "";
|
|
22
22
|
},
|
|
23
|
-
|
|
23
|
+
skipNegotiation: true,
|
|
24
|
+
transport: signalR.HttpTransportType.WebSockets,
|
|
25
|
+
};
|
|
26
|
+
this.connection = new signalR.HubConnectionBuilder()
|
|
27
|
+
.withUrl(settings_1.NUHEAT_NOTIFICATION_HUB_URL, this.connectionOptions)
|
|
24
28
|
.withAutomaticReconnect()
|
|
25
29
|
.build();
|
|
26
30
|
}
|
package/lib/settings.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.NUHEAT_API_CLIENT_SECRET = "";
|
|
|
7
7
|
exports.NUHEAT_API_REDIRECT_URI = "http://localhost";
|
|
8
8
|
const DEFAULT_NUHEAT_API_BASE_URL = "https://api.nam.mynuheat.com";
|
|
9
9
|
const DEFAULT_NUHEAT_IDENTITY_BASE_URL = "https://identity.nam.mynuheat.com";
|
|
10
|
+
const DEFAULT_NUHEAT_NOTIFICATION_HUB_PATH = "/v2/notificationsHost";
|
|
10
11
|
function normalizeBaseUrl(url) {
|
|
11
12
|
return url.replace(/\/+$/, "");
|
|
12
13
|
}
|
|
@@ -18,4 +19,5 @@ function buildNuHeatApiUrl(path) {
|
|
|
18
19
|
exports.NUHEAT_API_AUTHORIZE_URI = exports.NUHEAT_IDENTITY_BASE_URL + "/connect/authorize";
|
|
19
20
|
exports.NUHEAT_API_TOKEN_URI = exports.NUHEAT_IDENTITY_BASE_URL + "/connect/token";
|
|
20
21
|
exports.NUHEAT_API_CONSENT_URI = exports.NUHEAT_IDENTITY_BASE_URL + "/consent";
|
|
21
|
-
exports.NUHEAT_NOTIFICATION_HUB_URL =
|
|
22
|
+
exports.NUHEAT_NOTIFICATION_HUB_URL = normalizeBaseUrl(process.env.NUHEAT_NOTIFICATION_HUB_URL ||
|
|
23
|
+
buildNuHeatApiUrl(DEFAULT_NUHEAT_NOTIFICATION_HUB_PATH));
|