JaouherK / streamDeck-weatherPlugin

Popular Stream Deck plugin for Weather reporting
https://jaouherk.github.io/streamDeck-weatherPlugin/
GNU General Public License v3.0
44 stars 15 forks source link

Bug report - NaN on 0ºC temp #167

Open jsoucheiron opened 9 months ago

jsoucheiron commented 9 months ago

Hey, really nice plugin.

Today I had a NaN temp. I can't be 100% sure but I'm almost sure it's caused by a 0ºC temperature.

dutchtom91 commented 9 months ago

I have the same issue on my stream deck.

ingie commented 8 months ago

NaN at 0C here too.

it's due to main.js func prepareTemperature, which uses a conditional for undefined/null without testing the type - and so treats zero as "false"

e.g. if (unit === 'celsius') { temp = response.current.temp_c ? response.current.temp_c.toFixed(roundDegree ? 0 : 2) + '°C' : 'NaN'; }

needs to be : if (unit === 'celsius') { temp = typeof response.current.temp_c == 'number' ? response.current.temp_c.toFixed(roundDegree ? 0 : 2) + '°C' : 'NaN'; }

(and also do this for the other api and fahrenheit, if you need)

Sorry I can't do a PR, as I wouldn't be able to assert that the other apis still work, but I'd assume it would - and I leave this here so in the meantime folk can workaround if needed.

ingie commented 8 months ago

snip comment about current codebase fix being not sufficient

my mistake, i note that as the fix on github is not checking pure type equality with !==, it will work as expected even for undefined vars... I read too quickly and jumped to conclusions :)

additionally - my above "work around" failed entirely when the temperature last night at my local METAR went below zero 🤦