rahulpilani / homebridge-nexia-thermostat-ts

Collection of homebridge plugin examples
ISC License
4 stars 4 forks source link

Adjusting the temperature using Home app caused a Homebridge error #2

Closed gorathe closed 3 years ago

gorathe commented 3 years ago

Using the Home app control caused the following error on Homebridge:

[01/03/2021, 04:44:36] [Thermostat] Error setting target temperature Missing url property { method: 'POST', retry: { calculateDelay: [Function: calculateDelay], limit: 2, methods: [ 'GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE' ], statusCodes: [ 408, 413, 429, 500, 502, 503, 504, 521, 522, 524 ], errorCodes: [ 'ETIMEDOUT', 'ECONNRESET', 'EADDRINUSE', 'ECONNREFUSED', 'EPIPE', 'ENOTFOUND', 'ENETUNREACH', 'EAI_AGAIN' ], maxRetryAfter: Infinity }, timeout: {}, headers: { 'user-agent': 'got (https://github.com/sindresorhus/got)', 'x-mobileid': 'xxxxxxx', 'x-apikey': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'content-type': 'application/json' }, hooks: { init: [], beforeRequest: [], beforeRedirect: [], beforeRetry: [], beforeError: [], afterResponse: [] }, cache: undefined, dnsCache: undefined, decompress: true, throwHttpErrors: true, followRedirect: true, isStream: false, responseType: 'text', resolveBodyOnly: false, maxRedirects: 10, prefixUrl: '', methodRewriting: true, ignoreInvalidCookies: false, http2: false, allowGetBody: false, https: undefined, pagination: { transform: [Function: transform], paginate: [Function: paginate], filter: [Function: filter], shouldContinue: [Function: shouldContinue], countLimit: Infinity, backoff: 0, requestLimit: 10000, stackAllItems: true }, parseJson: [Function: parseJson], stringifyJson: [Function: stringifyJson], cacheOptions: {}, username: '', password: '',

}

I haven't dug into what's going on yet - I've posted this as a placeholder.

gorathe commented 3 years ago

Looking in accessory.js, in parseRawData(), the setpoint URL is obtained by looking for the set_heat_setpoint action; this doesn't exist if the current mode is COOL, instead, you need to use the set_cool_setpoint action.

gorathe commented 3 years ago

I have a local git copy. The following commit helps:

commit 201e69b3bc4ac77dd963a4038df45d6da581d3ce (HEAD -> jon/setPoint)
Author: Jon Brawn <jon@brawn.org>
Date:   Tue Mar 2 04:07:24 2021 -0600

    Try harder to set setPointUrl

    setPointUrl can only be set from action set_heat_setpoint when the
    thermostat is in a heating mode ('HEAT', 'AUTO'). If the thermostat
    is in 'COOL' mode then we can use the set_cool_setpoint action. If
    the thermostat is in 'OFF' mode then we fudge it by copying the
    zoneModeUrl and changing the last component to 'setpoints' instead
    of 'zone_mode'.

diff --git a/src/accessory.ts b/src/accessory.ts
index c65ab53..e96d378 100644
--- a/src/accessory.ts
+++ b/src/accessory.ts
@@ -184,6 +184,12 @@ class NexiaThermostat {
     if (rawThermostatFeature.actions.set_heat_setpoint != null) {
       setPointUrl = rawThermostatFeature.actions.set_heat_setpoint.href;
     }
+    else if (rawThermostatFeature.actions.set_cool_setpoint != null) {
+      setPointUrl = rawThermostatFeature.actions.set_cool_setpoint.href;
+    }
+    else {
+      setPointUrl = zoneModeUrl.replace('zone_mode', 'setpoints');
+    }
     const convertedScale = this.scaleMap.get(rawScale);
     const rawTemperature = rawData.temperature;
     const rawHeatingSetPoint = rawData.heating_setpoint;
rahulpilani commented 3 years ago

Makes sense. Since it’s winter in the northern hemisphere, not really got around to testing the cooling code yet :)

thanks for the bug report. Will patch and update soon!

rahulpilani commented 3 years ago

Fixed for now.