10-14-2020 12:43
10-14-2020 12:43
I have a Settings page for my Companion. I'm saving a couple float values. However, it seems like sometimes when I reference the value it comes back as a JSON obj, i.e. {"name":"22.55"} and other times the value appears to come back as a String i.e. "22.55". I can't seem to figure out what causes the difference. Is there a best practice for handling floats from user settings?
10-14-2020 13:38
10-14-2020 13:38
I think I figured what was happening or at least part of it. It seems like when I retrieve a value from settingsStorage.getItem() it returns a JSON object, but when I'm working with events they seem to return the values.
10-14-2020 13:53
10-14-2020 13:53
Yes, there's definitely some variations in behaviour.
I think there's a setting property that can make the behaviour a bit more consistent (something like 'usesimplesetting', but I can't find it now).
I suspect that all settings are stored as strings, even if you specify type=float.
10-15-2020 03:29
10-15-2020 03:29
I agree that settings are probably stored as strings, however, it seems like when referencing the setting values either the value itself will be returned or an object containing the value will be returned and it seems to be intermittent on which is returned. I'll see if I can find the 'usesimplesetting' property you referred to.
thanks
10-15-2020 10:48
10-15-2020 10:48
According to Fitbit, there are inconsistencies and different components return different things -- some return the value and some return JSON. Here is an old thread ,,,
The way that I compensated for it was to wrap my code in a switch statement based on the key name. For some key names, return the value. For others, use JSON.parse to convert it into an object and return the property value. That way, my function always returns a simple value.