homebridge-nuheat2 1.2.27 → 1.3.0

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 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.3.0] - 2026-10-15
8
+
9
+ ### Added
10
+
11
+ - Opt-in `enableThermostatModeControl` setting that adds `Off` and `Auto` target states to each thermostat and routes those requests through Nuheat's v2 mode API (`PUT /api/v2/Mode/Manual`, `Mode/Hold`, `Mode/Auto`). Defaults to `false`, so existing installations keep advertising heat only
12
+
13
+ ### Changed
14
+
15
+ - Derive the HomeKit target state from Nuheat's `operatingMode`/`scheduleMode` fields, replacing a switch that returned `Heat` in every branch
16
+
17
+ ### Fixed
18
+
19
+ - Stop pushing the empty `204 No Content` response from setpoint writes into HomeKit, which briefly flashed `0.2 C` / `10 C` readings and a wrong target state after every change; write paths now re-read the thermostat and non-object payloads are ignored
20
+ - Stop sending a stale cached setpoint with heat-mode requests, which could silently clobber a concurrent setpoint write from the Home app; heat requests now omit the optional temperature field
21
+
22
+ ## [1.2.28] - 2026-09-14
23
+
24
+ ### Fixed
25
+
26
+ - Stop logging the raw thermostat update payload at info level on every setpoint change; the payload is now summarized at debug level
27
+
28
+ ### Changed
29
+
30
+ - Document that group away mode is applied by Nuheat's servers and that affected thermostats may be reported as being in Standby rather than Away
31
+
7
32
  ## [1.2.27] - 2026-09-14
8
33
 
9
34
  ### Changed
package/README.md CHANGED
@@ -64,6 +64,7 @@ The equivalent JSON looks like this:
64
64
  "groups": [{ "groupName": "Main Floor", "disabled": false }],
65
65
  "exposeScheduleSwitches": false,
66
66
  "enableNotifications": true,
67
+ "enableThermostatModeControl": false,
67
68
  "holdLength": 1440,
68
69
  "refresh": 60
69
70
  }
@@ -79,13 +80,14 @@ The equivalent JSON looks like this:
79
80
  - `devices`: Optional list of thermostats to expose. If omitted or empty, every thermostat on the account will be discovered automatically. Blank rows in the UI are ignored
80
81
  - `serialNumber`: Thermostat serial number from MyNuheat
81
82
  - `disabled`: Available on `devices` and `groups` rows. Keeps the row saved while preventing that thermostat or group from being exposed
82
- - `autoPopulateAwayModeSwitches`: Automatically expose away-mode switches for all groups on the account
83
+ - `autoPopulateAwayModeSwitches`: Automatically expose away-mode switches for all groups on the account. Away mode is applied by Nuheat's servers; affected thermostats may be reported as being in Standby rather than Away
83
84
  - `exposeScheduleSwitches`: Optionally expose a switch per thermostat that reflects whether the thermostat is following its schedule and can be turned on to resume the schedule
84
85
  - `groups`: Optional allow-list of groups to expose as away-mode switches. This only affects group/away-mode accessories. Blank rows in the UI are ignored
85
86
  - `groupName`: Group name as shown in MyNuheat
86
87
  - `holdLength`: Hold duration in minutes, default `1440`. Values are clamped from `0` to `1440`
87
88
  - `refresh`: Poll interval in seconds, default `60`. Values lower than `30` are raised to `30` to reduce API traffic
88
89
  - `enableNotifications`: Enables Nuheat SignalR notifications for faster updates. Defaults to `true`; set to `false` only while troubleshooting
90
+ - `enableThermostatModeControl`: Adds `Off` and `Auto` target states to each thermostat so HomeKit can request standby or resume the schedule. Defaults to `false`. Experimental; see [Thermostat Mode Control](#thermostat-mode-control)
89
91
  - `debug`: Enables verbose Nuheat API, notification, and accessory logging. Defaults to `false`
90
92
 
91
93
  ### Hold Length Behavior
@@ -94,6 +96,30 @@ The equivalent JSON looks like this:
94
96
  - `1-1439`: timed hold for the configured number of minutes
95
97
  - `1440`: permanent hold
96
98
 
99
+ ### Away Mode Behavior
100
+
101
+ Away-mode switches map directly to Nuheat's group away mode. Turning a switch on sends `PUT /api/v1/Group` with `{ groupId, awayMode: true }`, which is the only group-level control Nuheat exposes.
102
+
103
+ What the thermostats do while a group is in away mode is decided by Nuheat's servers, not by this plugin. Depending on the account and firmware, Nuheat may report the affected thermostats as being in **Standby** rather than showing an explicit "Away" state. Standby is Nuheat's own representation of the away setpoint; the plugin does not request standby and cannot request it, because Nuheat's thermostat update API has no operating-mode field.
104
+
105
+ If you need a specific temperature held while you are away, set that temperature on the thermostat itself. The plugin will hold it for `holdLength` minutes, or permanently when `holdLength` is `1440`.
106
+
107
+ ### Thermostat Mode Control
108
+
109
+ By default each thermostat advertises only `Heat` as a target state, because Nuheat's v1 thermostat update API has no operating-mode field and therefore cannot request standby.
110
+
111
+ Setting `enableThermostatModeControl` to `true` adds `Off` and `Auto` to the target states and routes those requests through Nuheat's v2 mode API:
112
+
113
+ | HomeKit target | Nuheat v2 request |
114
+ | --- | --- |
115
+ | `Off` | `PUT /api/v2/Mode/Manual` at the minimum target temperature (10 °C / 50 °F) |
116
+ | `Heat` | `PUT /api/v2/Mode/Hold` at the current target temperature, or `Mode/Manual` when `holdLength` is `1440` |
117
+ | `Auto` | `PUT /api/v2/Mode/Auto`, resuming the schedule |
118
+
119
+ Reads still come from the v1 API, which is the only version that reports `groupId` (needed for away mode) and `operatingMode`/`scheduleMode`. The plugin derives the HomeKit target state from those fields: an auto schedule combined with a manual operating mode is reported as `Off` (Nuheat's Standby), a hold is reported as `Heat`, and a normal scheduled run is reported as `Auto`.
120
+
121
+ This option is **experimental**. Nuheat has no explicit "off" concept, so `Off` is implemented as a permanent manual setpoint at the minimum temperature. The mapping above is inferred from Nuheat's API rather than verified against hardware, and it is unknown whether a v2 mode write is immediately reflected in a v1 read. Leave it disabled unless you want HomeKit to drive thermostat mode.
122
+
97
123
  ### Device Discovery
98
124
 
99
125
  If `devices` is omitted or empty, the plugin will automatically expose every thermostat on the authenticated account.
@@ -151,5 +177,4 @@ This project is maintained by `applemanj` and retains attribution to SenorShaun
151
177
  ## Future Work
152
178
 
153
179
  - Validate the PKCE public-client flow against more real-world Nuheat accounts.
154
- - Verify group and away-mode behavior against current live API responses.
155
180
  - Monitor Nuheat Conductor v2 notification behavior across more accounts and keep polling as the reliability fallback.
@@ -65,7 +65,7 @@
65
65
  "title": "Away Mode Group Allow-List",
66
66
  "type": "array",
67
67
  "default": [],
68
- "description": "Optional. Leave empty unless you want specific Nuheat groups exposed as away-mode switches.",
68
+ "description": "Optional. Leave empty unless you want specific Nuheat groups exposed as away-mode switches. Away mode is applied by Nuheat's servers; affected thermostats may be reported as being in Standby rather than Away.",
69
69
  "items": {
70
70
  "type": "object",
71
71
  "properties": {
@@ -87,7 +87,7 @@
87
87
  "title": "Expose Away Mode Switches For All Groups",
88
88
  "type": "boolean",
89
89
  "default": false,
90
- "description": "Automatically create HomeKit away-mode switches for every Nuheat group on the account."
90
+ "description": "Automatically create HomeKit away-mode switches for every Nuheat group on the account. Away mode is applied by Nuheat's servers; affected thermostats may be reported as being in Standby rather than Away."
91
91
  },
92
92
  "exposeScheduleSwitches": {
93
93
  "title": "Expose Schedule Switches",
@@ -95,6 +95,12 @@
95
95
  "default": false,
96
96
  "description": "Create one switch per thermostat. The switch is on when the thermostat follows its Nuheat schedule and can be turned on to resume the schedule."
97
97
  },
98
+ "enableThermostatModeControl": {
99
+ "title": "Enable Thermostat Mode Control (Off/Auto)",
100
+ "type": "boolean",
101
+ "default": false,
102
+ "description": "Adds Off and Auto target states to each thermostat using Nuheat's v2 mode API, so HomeKit can request standby or resume the schedule. Experimental: leave disabled unless you want HomeKit to drive thermostat mode."
103
+ },
98
104
  "holdLength": {
99
105
  "title": "Hold Length (minutes)",
100
106
  "type": "integer",
@@ -152,6 +158,7 @@
152
158
  "holdLength",
153
159
  "refresh",
154
160
  "enableNotifications",
161
+ "enableThermostatModeControl",
155
162
  "debug"
156
163
  ]
157
164
  }
@@ -146,6 +146,19 @@
146
146
  </span>
147
147
  </label>
148
148
 
149
+ <label class="checkbox">
150
+ <input id="enable-thermostat-mode-control" type="checkbox" />
151
+ <span>
152
+ Enable thermostat mode control (Off / Auto)
153
+ <small>
154
+ Adds Off and Auto target states to each thermostat using Nuheat's v2
155
+ mode API, so HomeKit can request standby or resume the schedule.
156
+ Experimental; leave off unless you want HomeKit to drive thermostat
157
+ mode.
158
+ </small>
159
+ </span>
160
+ </label>
161
+
149
162
  <label class="checkbox">
150
163
  <input id="debug" type="checkbox" />
151
164
  <span>
@@ -12,6 +12,9 @@ const elements = {
12
12
  holdLength: document.getElementById("hold-length"),
13
13
  refresh: document.getElementById("refresh"),
14
14
  enableNotifications: document.getElementById("enable-notifications"),
15
+ enableThermostatModeControl: document.getElementById(
16
+ "enable-thermostat-mode-control",
17
+ ),
15
18
  debug: document.getElementById("debug"),
16
19
  saveAccount: document.getElementById("save-account"),
17
20
  addDevice: document.getElementById("add-device"),
@@ -102,6 +105,7 @@ function createDefaultConfig() {
102
105
  autoPopulateAwayModeSwitches: false,
103
106
  exposeScheduleSwitches: false,
104
107
  enableNotifications: true,
108
+ enableThermostatModeControl: false,
105
109
  holdLength: 1440,
106
110
  refresh: 60,
107
111
  debug: false,
@@ -126,6 +130,9 @@ function renderConfig(config) {
126
130
  elements.holdLength.value = String(normalizeHoldLength(config.holdLength));
127
131
  elements.refresh.value = String(normalizeRefresh(config.refresh));
128
132
  elements.enableNotifications.checked = config.enableNotifications !== false;
133
+ elements.enableThermostatModeControl.checked = Boolean(
134
+ config.enableThermostatModeControl,
135
+ );
129
136
  elements.debug.checked = Boolean(config.debug);
130
137
 
131
138
  updateStatuses();
@@ -313,6 +320,9 @@ async function saveBehavior() {
313
320
  holdLength,
314
321
  refresh,
315
322
  enableNotifications: Boolean(elements.enableNotifications.checked),
323
+ enableThermostatModeControl: Boolean(
324
+ elements.enableThermostatModeControl.checked,
325
+ ),
316
326
  debug: Boolean(elements.debug.checked),
317
327
  });
318
328
  showToast("success", "Behavior settings saved.");
@@ -438,6 +448,10 @@ function renderDiagnostics() {
438
448
  "Notifications",
439
449
  config.enableNotifications === false ? "disabled" : "enabled",
440
450
  ],
451
+ [
452
+ "Mode Control",
453
+ config.enableThermostatModeControl ? "Off / Auto enabled" : "heat only",
454
+ ],
441
455
  ["Debug Logs", config.debug ? "enabled" : "disabled"],
442
456
  ]);
443
457
  }
@@ -475,6 +489,9 @@ function getDraftConfig() {
475
489
  holdLength: normalizeHoldLength(elements.holdLength.value),
476
490
  refresh: normalizeRefresh(elements.refresh.value),
477
491
  enableNotifications: Boolean(elements.enableNotifications.checked),
492
+ enableThermostatModeControl: Boolean(
493
+ elements.enableThermostatModeControl.checked,
494
+ ),
478
495
  debug: Boolean(elements.debug.checked),
479
496
  };
480
497
  }
@@ -568,6 +585,7 @@ function bindEvents() {
568
585
  elements.holdLength,
569
586
  elements.refresh,
570
587
  elements.enableNotifications,
588
+ elements.enableThermostatModeControl,
571
589
  elements.debug,
572
590
  ].forEach((element) => {
573
591
  element.addEventListener("input", () => {
package/index.js CHANGED
@@ -192,7 +192,7 @@ class NuHeatPlatform {
192
192
  entry = { uuid };
193
193
  this.accessories.push(entry);
194
194
  }
195
- entry.accessory = new NuHeatThermostat(this.log, deviceData, this.config.holdLength || 1440, getPlatformAccessory(deviceAccessory), this.NuHeatAPI, Homebridge, this.account?.temperatureScale);
195
+ entry.accessory = new NuHeatThermostat(this.log, deviceData, this.config.holdLength || 1440, getPlatformAccessory(deviceAccessory), this.NuHeatAPI, Homebridge, this.account?.temperatureScale, this.config.enableThermostatModeControl === true);
196
196
  entry.existsInConfig = true;
197
197
  this.log.info("Loaded thermostat " +
198
198
  deviceData.serialNumber +
package/lib/NuHeatAPI.js CHANGED
@@ -144,7 +144,13 @@ class NuHeatAPI {
144
144
  if (holdSetPointDateTime) {
145
145
  callBody.holdSetPointDateTime = holdSetPointDateTime;
146
146
  }
147
- this.log.info(JSON.stringify(callBody));
147
+ this.log.debug("NuHeatAPI: Setting thermostat " +
148
+ serialNumber +
149
+ " to " +
150
+ setPointTemp +
151
+ " with schedule mode " +
152
+ scheduleMode +
153
+ ".");
148
154
  const callOptions = {
149
155
  body: JSON.stringify(callBody),
150
156
  method: "PUT",
@@ -157,6 +163,42 @@ class NuHeatAPI {
157
163
  scheduleMode: NuHeatModels_1.SCHEDULE_MODE.AUTO,
158
164
  });
159
165
  }
166
+ /**
167
+ * The v1 thermostat update model has no operating mode, so it cannot request
168
+ * standby. The v2 mode endpoints can, and they share the same account,
169
+ * identity provider, and `openapi` scope as v1.
170
+ */
171
+ async setThermostatMode(serialNumber, mode, options = {}) {
172
+ let callURL;
173
+ const callBody = { serialNumber };
174
+ if (mode === NuHeatModels_1.HEATING_MODE.AUTO) {
175
+ callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v2/Mode/Auto");
176
+ }
177
+ else if (mode === NuHeatModels_1.HEATING_MODE.HOLD) {
178
+ callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v2/Mode/Hold");
179
+ if (options.holdLength && options.holdLength > 0) {
180
+ callBody.holdUntil = new Date(Date.now() + options.holdLength * 60 * 1000).toISOString();
181
+ }
182
+ }
183
+ else {
184
+ // NuHeat has no off; standby is a permanent manual setpoint.
185
+ callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v2/Mode/Manual");
186
+ }
187
+ if (options.setPointTemp !== undefined) {
188
+ callBody.temperature = Number(options.setPointTemp);
189
+ callBody.temperatureType = NuHeatModels_1.TEMPERATURE_TYPE.ABSOLUTE;
190
+ }
191
+ this.log.debug("NuHeatAPI: Setting thermostat " +
192
+ serialNumber +
193
+ " to " +
194
+ mode +
195
+ " mode.");
196
+ const callOptions = {
197
+ body: JSON.stringify(callBody),
198
+ method: "PUT",
199
+ };
200
+ return await this.makeAPICall(callURL, callOptions);
201
+ }
160
202
  async updateThermostat(thermostatUpdate) {
161
203
  const callURL = (0, settings_1.buildNuHeatApiUrl)("/api/v1/Thermostat");
162
204
  const callOptions = {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OPERATING_MODE = exports.SCHEDULE_MODE = void 0;
3
+ exports.TEMPERATURE_TYPE = exports.HEATING_MODE = exports.OPERATING_MODE = exports.SCHEDULE_MODE = void 0;
4
+ exports.isThermostatOnline = isThermostatOnline;
5
+ exports.deriveHeatingMode = deriveHeatingMode;
4
6
  exports.normalizeAccount = normalizeAccount;
5
7
  exports.normalizeGroup = normalizeGroup;
6
8
  exports.normalizeSchedule = normalizeSchedule;
@@ -15,9 +17,56 @@ exports.OPERATING_MODE = {
15
17
  AUTO: 1,
16
18
  MANUAL: 2,
17
19
  };
20
+ exports.HEATING_MODE = {
21
+ OFF: "off",
22
+ MANUAL: "manual",
23
+ HOLD: "hold",
24
+ AUTO: "auto",
25
+ };
26
+ /** v2 `eTemperatureType`: 0 = absolute setpoint, 1 = relative to current. */
27
+ exports.TEMPERATURE_TYPE = {
28
+ ABSOLUTE: 0,
29
+ RELATIVE: 1,
30
+ };
18
31
  function coalesce(...values) {
19
32
  return values.find((value) => value !== undefined && value !== null);
20
33
  }
34
+ function isThermostatOnline(thermostat) {
35
+ const onlineValue = coalesce(thermostat.Online, thermostat.online, thermostat.isOnline);
36
+ if (typeof onlineValue === "boolean") {
37
+ return onlineValue;
38
+ }
39
+ if (typeof onlineValue === "string") {
40
+ return onlineValue.replace(/'/g, "").trim().toLowerCase() === "true";
41
+ }
42
+ return true;
43
+ }
44
+ /**
45
+ * NuHeat has no "off". Standby is reported as operating mode MANUAL paired
46
+ * with schedule mode AUTO; a real manual setpoint change always sends a hold
47
+ * schedule mode.
48
+ */
49
+ function deriveHeatingMode(thermostat) {
50
+ if (!isThermostatOnline(thermostat)) {
51
+ return exports.HEATING_MODE.OFF;
52
+ }
53
+ const scheduleMode = Number(thermostat.scheduleMode);
54
+ if (scheduleMode === exports.SCHEDULE_MODE.HOLD) {
55
+ return exports.HEATING_MODE.HOLD;
56
+ }
57
+ if (scheduleMode === exports.SCHEDULE_MODE.PERMANENT_HOLD) {
58
+ return exports.HEATING_MODE.MANUAL;
59
+ }
60
+ if (scheduleMode === exports.SCHEDULE_MODE.AUTO) {
61
+ return Number(thermostat.operatingMode) === exports.OPERATING_MODE.MANUAL
62
+ ? exports.HEATING_MODE.OFF
63
+ : exports.HEATING_MODE.AUTO;
64
+ }
65
+ // Unknown schedule mode: report whatever the hardware tells us.
66
+ return Number(thermostat.operatingMode) === exports.OPERATING_MODE.MANUAL
67
+ ? exports.HEATING_MODE.MANUAL
68
+ : exports.HEATING_MODE.AUTO;
69
+ }
21
70
  function normalizeAccount(account = {}) {
22
71
  return {
23
72
  firstName: coalesce(account.firstName, account.FirstName),
@@ -11,7 +11,8 @@ class NuHeatThermostat {
11
11
  accessory;
12
12
  NuHeatAPI;
13
13
  temperatureScale;
14
- constructor(log, deviceData, holdLength, accessory, NuHeatAPI, homebridge, temperatureScale) {
14
+ enableThermostatModeControl;
15
+ constructor(log, deviceData, holdLength, accessory, NuHeatAPI, homebridge, temperatureScale, enableThermostatModeControl = false) {
15
16
  Characteristic = homebridge.hap.Characteristic;
16
17
  ThermostatService = homebridge.hap.Service.Thermostat;
17
18
  this.log = log;
@@ -20,6 +21,7 @@ class NuHeatThermostat {
20
21
  this.accessory = accessory;
21
22
  this.NuHeatAPI = NuHeatAPI;
22
23
  this.temperatureScale = temperatureScale;
24
+ this.enableThermostatModeControl = enableThermostatModeControl;
23
25
  this.accessory
24
26
  .getService(homebridge.hap.Service.AccessoryInformation)
25
27
  .setCharacteristic(Characteristic.Manufacturer, "NuHeat")
@@ -31,10 +33,17 @@ class NuHeatThermostat {
31
33
  setupListeners() {
32
34
  const thermostatService = this.accessory.getService(ThermostatService);
33
35
  this.log.info("holdLength: " + this.holdLength, this.deviceData.name);
36
+ const targetHeatingCoolingStates = this.enableThermostatModeControl
37
+ ? [
38
+ Characteristic.TargetHeatingCoolingState.OFF,
39
+ Characteristic.TargetHeatingCoolingState.HEAT,
40
+ Characteristic.TargetHeatingCoolingState.AUTO,
41
+ ]
42
+ : [Characteristic.TargetHeatingCoolingState.HEAT];
34
43
  thermostatService
35
44
  .getCharacteristic(Characteristic.TargetHeatingCoolingState)
36
45
  .setProps({
37
- validValues: [Characteristic.TargetHeatingCoolingState.HEAT],
46
+ validValues: targetHeatingCoolingStates,
38
47
  })
39
48
  .on("set", this.setTargetHeatingCooling.bind(this));
40
49
  thermostatService.getCharacteristic(Characteristic.CurrentTemperature).setProps({
@@ -50,6 +59,10 @@ class NuHeatThermostat {
50
59
  this.updateTemperatureDisplayUnits();
51
60
  }
52
61
  async setTargetHeatingCooling(value, callback) {
62
+ if (this.enableThermostatModeControl) {
63
+ await this.setThermostatModeFromHomeKit(value, callback);
64
+ return;
65
+ }
53
66
  if (value !== Characteristic.TargetHeatingCoolingState.OFF) {
54
67
  callback(null);
55
68
  void this.updateAccessory();
@@ -62,7 +75,57 @@ class NuHeatThermostat {
62
75
  callback(new Error("Error: setTargetHeatingCooling"));
63
76
  return;
64
77
  }
65
- this.updateValues(response);
78
+ // The v1 write returns 204 with no content, so re-read the authoritative
79
+ // state instead of pushing the empty response into HomeKit.
80
+ await this.updateAccessory();
81
+ callback(null);
82
+ }
83
+ /**
84
+ * The v1 update model cannot request standby or an indefinite auto schedule,
85
+ * so mode changes go through the v2 mode endpoints. Those writes return no
86
+ * content, so the authoritative state is re-read through v1 afterwards.
87
+ */
88
+ async setThermostatModeFromHomeKit(value, callback) {
89
+ const { OFF, HEAT, AUTO } = Characteristic.TargetHeatingCoolingState;
90
+ let mode;
91
+ const options = {};
92
+ if (value === OFF) {
93
+ mode = NuHeatModels_1.HEATING_MODE.OFF;
94
+ options.setPointTemp = this.toNuHeatTemperature(MIN_TARGET_TEMPERATURE_C);
95
+ this.log.info("Setting the thermostat to standby (minimum target temperature).", this.deviceData.name);
96
+ }
97
+ else if (value === AUTO) {
98
+ mode = NuHeatModels_1.HEATING_MODE.AUTO;
99
+ this.log.info("Resuming the NuHeat schedule.", this.deviceData.name);
100
+ }
101
+ else if (value === HEAT) {
102
+ // Deliberately omit the setpoint: the v2 mode body's temperature field
103
+ // is optional, and HomeKit sends mode and temperature as separate
104
+ // concurrent writes. Sending a stale setpoint here can clobber the
105
+ // setpoint write that lands right after this one.
106
+ if (this.holdLength >= 1440) {
107
+ mode = NuHeatModels_1.HEATING_MODE.MANUAL;
108
+ }
109
+ else {
110
+ mode = NuHeatModels_1.HEATING_MODE.HOLD;
111
+ if (this.holdLength > 0) {
112
+ options.holdLength = this.holdLength;
113
+ }
114
+ }
115
+ this.log.info("Holding the thermostat target temperature.", this.deviceData.name);
116
+ }
117
+ else {
118
+ this.log.error("Unsupported target heating state " + value, this.deviceData.name);
119
+ callback(new Error("Error: setTargetHeatingCooling"));
120
+ return;
121
+ }
122
+ const response = await this.NuHeatAPI.setThermostatMode(this.deviceData.serialNumber ?? "", mode, options);
123
+ if (!response) {
124
+ this.log.error("Error setting thermostat mode", this.deviceData.name);
125
+ callback(new Error("Error: setTargetHeatingCooling"));
126
+ return;
127
+ }
128
+ await this.updateAccessory();
66
129
  callback(null);
67
130
  }
68
131
  async setTargetTemperature(value, callback) {
@@ -79,7 +142,9 @@ class NuHeatThermostat {
79
142
  callback(new Error("Error: setTargetTemperature"));
80
143
  }
81
144
  else {
82
- this.updateValues(response);
145
+ // The v1 write returns 204 with no content, so re-read the authoritative
146
+ // state instead of pushing the empty response into HomeKit.
147
+ await this.updateAccessory();
83
148
  callback(null);
84
149
  }
85
150
  }
@@ -93,6 +158,13 @@ class NuHeatThermostat {
93
158
  }
94
159
  }
95
160
  updateValues(newValues) {
161
+ // Write calls that return 204 No Content resolve to a literal `true`.
162
+ // That is not thermostat data; pushing it would flash garbage temperatures
163
+ // and blank the cached device data until the next poll.
164
+ if (!newValues || typeof newValues !== "object") {
165
+ this.log.debug("Ignoring a thermostat update without payload data", this.deviceData.name);
166
+ return;
167
+ }
96
168
  if (this.isOnline(newValues)) {
97
169
  this.updateTemperatureDisplayUnits();
98
170
  let currentTemperature = Number(this.toHBTemperature(newValues.currentTemperature ?? 0));
@@ -142,13 +214,22 @@ class NuHeatThermostat {
142
214
  return ((((temperature - 33) / 56 + 33 - 32) * 5) / 9).toFixed(1);
143
215
  }
144
216
  toHomeBridgeHeatingCoolingState(newValues) {
145
- if (!this.isOnline(newValues)) {
146
- return Characteristic.TargetHeatingCoolingState.OFF;
217
+ if (!this.enableThermostatModeControl) {
218
+ if (!this.isOnline(newValues)) {
219
+ return Characteristic.TargetHeatingCoolingState.OFF;
220
+ }
221
+ // The v1 read model cannot distinguish standby from a scheduled run, and
222
+ // the characteristic only advertises heat, so heat is the only safe
223
+ // report.
224
+ return Characteristic.TargetHeatingCoolingState.HEAT;
147
225
  }
148
- switch (newValues.operatingMode) {
149
- case NuHeatModels_1.OPERATING_MODE.AUTO:
150
- case NuHeatModels_1.OPERATING_MODE.MANUAL:
151
- return Characteristic.TargetHeatingCoolingState.HEAT;
226
+ switch ((0, NuHeatModels_1.deriveHeatingMode)(newValues)) {
227
+ case NuHeatModels_1.HEATING_MODE.OFF:
228
+ return Characteristic.TargetHeatingCoolingState.OFF;
229
+ case NuHeatModels_1.HEATING_MODE.AUTO:
230
+ return Characteristic.TargetHeatingCoolingState.AUTO;
231
+ case NuHeatModels_1.HEATING_MODE.MANUAL:
232
+ case NuHeatModels_1.HEATING_MODE.HOLD:
152
233
  default:
153
234
  return Characteristic.TargetHeatingCoolingState.HEAT;
154
235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-nuheat2",
3
- "version": "1.2.27",
3
+ "version": "1.3.0",
4
4
  "description": "Homebridge Platform for NuHeat Signature Thermostats",
5
5
  "main": "index.js",
6
6
  "scripts": {