jvmahon / Homebridge-HomeSeer4

Homebridge Plugin for HomeSeer 3 and 4
29 stars 8 forks source link

Error setting up Temperature Sensor. Scale is not Celsius or Fahrenheit #110

Closed teladog01 closed 4 years ago

teladog01 commented 4 years ago

I am trying to add a Temperature Sensor and am getting the following error at Homebridge startup:

[9/3/2020, 10:21:01 AM] Initializing platform accessory 'Dark Sky Temperature'...
(node:15406) UnhandledPromiseRejectionWarning: RangeError: Error setting up Temperature Sensor. Scale is not Celsius or Fahrenheit
    at Object.exports.setupSensor (/usr/local/lib/node_modules/homebridge-homeseer4/lib/Sensor Setup.js:267:12)
    at Object.exports.setupServices (/usr/local/lib/node_modules/homebridge-homeseer4/lib/HomeKitDeviceSetup.js:170:12)
    at HomeSeerAccessory.getServices (/usr/local/lib/node_modules/homebridge-homeseer4/index.js:218:11)
    at Server.createHAPAccessory (/usr/local/lib/node_modules/homebridge/src/server.ts:442:41)
    at /usr/local/lib/node_modules/homebridge/src/server.ts:427:34
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/homebridge/src/server.ts:417:21
    at /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/src/lib/util/once.ts:10:18
    at HomeSeerPlatform.accessories (/usr/local/lib/node_modules/homebridge-homeseer4/index.js:182:5)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:15406) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15406) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The HomeSeer device is a virtual device I created and update with a script. I have tried setting ScaleText to "F" but got the same error.

How does the plugin determine whether a Temperature Sensor has values in Celsius or Fahrenheit?

Screen Shot 2020-09-03 at 11 55 00 AM
teladog01 commented 4 years ago

After skimming the code, I see that the plugin simply checks the end of the device string to determine the unit. So I tried setting the ScaleText to "F" again, and sure enough it adds correctly with that. My mistake on that.

I am using the suffix "℉", which is the Unicode character "U+2109", so that's why the plugin was throwing the error above. "U+2103" (℃) is the Celsius equivalent. Could you add these to the scale detection?

jvmahon commented 4 years ago

Got it - I thought that was two characters, a degree symbol followed by F or C. Now I see that in Unicode its one. Thanks. Yes, I can fix that.

teladog01 commented 4 years ago

Got it - I thought that was two characters, a degree symbol followed by F or C. Now I see that in Unicode its one. Thanks. Yes, I can fix that.

Yes, it's a single Unicode character. I prefer to use it instead of the two characters (degree symbol + "F") because it takes up less space and works better for my HSTouch screens. Thank you for adding this.

jvmahon commented 4 years ago

Upgrade to 1.0.7 and try again. Please close out the comment if it works (or let me know if it doesn't).

teladog01 commented 4 years ago

Still getting the error in 1.0.7. I've never done any Javascript coding, but through trial and error I was able to get it working with this code:

case statusField.endsWith("F") || statusField.endsWith(String.fromCharCode(8457)):

U+2109 is the hex code, but fromCharCode() takes the decimal code, which is 8457. The celsius code in decimal is 8451.

https://www.w3schools.com/charsets/ref_utf_letterlike.asp

jvmahon commented 4 years ago

Now published as version 1.0.8. Please give it a try and confirm that it works. If it does, please go ahead and close this issue. Thanks. Jim

teladog01 commented 4 years ago

Looks good, thanks very much 👍