I am trying to evaluate a ENUM preference to do a Celcius to Fahrenheit conversion and for some reason, all I get is “null”. Here is the preference code. Does anyone know how to retrieve the proper value of an ENUM preference option? I verified it’s being stored in the Device properly int he IDE. I also tried settings.tempscale and that didn’t work either.
In a “def” further down below int he code. If I change the preference to text, it reads it perfect. It’s just when it’s a “enum”, does it return “null”.
I think this has been identified as a bug, try the more explicit version of Input…
Example:
input(
name : “dimDark”
,title : “When it’s Dark out…”
,multiple : false
,required : true
,type : “enum”
,options : [[“10”:“10%”],[“20”:“20%”],[“30”:“30%”],[“40”:“40%”],[“50”:“50%”],[“60”:“60%”]]
)
My issue is that the ENUM options, settings.tempScale are not being retrieved throughout the entire portion of my code. When I reference it from certain areas of my code, the value shows null, but in other areas it’s showing up with the proper value. I assume it’s some sort of lack of defining it globally somewhere, but I am unclear how to make it globally available.
This is what I can’t wrap my head around. It’s extremely frustrating! I’ve seen other working code all over GH and this forum and I am literally doing the same thing and it’s returning null! If I reference it in my refresh method, it reads properly. If I call it from another method in my code, it will return null.
It can be frustrating! Device Handler preferences are only available to command methods (which is why it works inside refresh()) as documented here.
Sorry for the confusion, that is why I asked earlier about where in the code you were referencing the preferences, but I should have been more explicit/direct
Thanks @Jim. Makes sense. So how do get that value to be used in another method? I tried storing it in another variable, and that didn’t work either. Is there any option? I am basically trying to determine temperature scale of the end user and doing the necessary calculations based on preference.
What about using the Location temperatureScale and then using unit option when sending the temp event? You can see an example of this in this commit.
(More theoretical, but it’s possible you could store the preference variable in state and reference it later, but that would be pretty gross because you’d have to do that inside a command method to begin with, and might have other downsides)
It turns out, Tesla (this is for a DH I am currently working on) allows you to poll the Temp Units from the car itself and I can pull that into my DH. That probably makes more sense since the owner of the car is going to want the temperature in the DH to match without explicitly stating so. You would think an American car company would default to Fahrenheit for units, huh?