steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

Thermostat shows wrong temperature when multiple of 10 #60

Closed vthawkeye closed 4 years ago

vthawkeye commented 4 years ago

Describe the bug Thermostat shows wrong temperature when multiple of 10 and a Number:Temperature type. It will display 7 instead of 70. This is because Openhab's rest interface returns: "7E+1 °F". I'm unsure if it affects just Number types.

Expected behavior The temperature should be correct, in the above example it should be 70 and not 7.

Configurations Homebridge:

                {
                    "name": "Thermostat",
                    "type": "thermostat",
                    "currentTempItem": "ThermostatTemperature",
                    "targetTempItem": "ThermostatSetpointHeatingC",
                    "heatingItem": "HeatingItem",
                    "coolingItem": "CoolingItem",
                    "modeItem": "ThermostatMode",
                    "tempUnit": "Fahrenheit"
                },

Openhab item:

Number:Temperature  ThermostatTemperature   "Thermostat Temperature [%.1f °F]"  <temperature>   (gThermostat) {...}
vthawkeye commented 4 years ago

I found line 285 in util/OpenHAB.js has a regular expression:

let matchedValue =  value.match(/^\d+((\.|,)\d*)*/i)

I updated the regex in that line to:

let matchedValue =  value.match(/^\d+(?:[\.,]\d*)?(?:[eE][\+\-]\d+)?/i)

To match the digits and possibly the scientific notation. That appears to allow the number to be recognized.

Hope that helps

steilerDev commented 4 years ago

My latest commit (a5d21ecd10a76dae913c7e40a15baf5f7c22578d) supports scientifically notated numbers. Track the official npm releases if you cannot test directly from Github's source.