Can someone please explain or point me to an explanation of how the built-in convertTemperatureIfNeeded method is meant to work? I have previously included a call to this method in my code and thought I understood what it was meant to do, but am not so sure now.
It accepts three parameters:
Temperature reading,
Temperature scale (F or C)
Decimal places (optional?)
The code I originally used it in was, I suspect, already receiving a temperature reading in C, so it probably wasn't needing to do any conversion. I included it in a driver today that was receiving what I believe to be a Fahrenheit reading (75). I was passing in this temperature with a scale of "C" but was still getting the same 75 as the result. When I passed in a scale of "F" I got what I need, ~24 degrees. Just a little confusing. I currently have my temperature scale on the hub set to C.
It converts the submitted temperature to whatever measurement scale the hub is set for, but needs the scale it was to begin with.
So when you said the 75 was C, and your hub is set for C, it gave you 75.
When you told it that the 75 was F... Then it converted it to the C your hub displays.
No problem. I use my own method in my drivers that does pretty much the exact same thing because I wrote it in before I knew the command existed. There are a bunch of common functions I copy amongst many if my drivers (that is just one) so I have not bothered to use the built-in one.
One of these days I should clean it out... But it is pretty low on the priority list, because it works just fine.