PatrickE94 / pycalima

Python interface for Pax Calima Fan via Bluetooth LE
Apache License 2.0
43 stars 22 forks source link

getState not working with zero humidity #14

Open eresgit opened 4 years ago

eresgit commented 4 years ago

/pycalima/Calima.py", line 172, in getState return FanState(round(math.log2(v[0])*10, 2), v[1]/4, v[2], v[3], trigger) ValueError: math domain error

Looks like a problem when v[0] = 0

eresgit commented 4 years ago

I think replacing line 172 with this works: return FanState(round(math.log2(v[0] if v[0] > 0 else 1)*10, 2), v[1]/4, v[2], v[3], trigger)

PatrickE94 commented 4 years ago

You're completely correct that math.log2 does not handle 0. Only the open interval (i.e. not exactly zero). I fixed this in a commit referenced above (thus master should be properly working regarding this). I did however move out the if-case, as it seemed more logical to just report zero directly. However, it is essentially the same code. Thanks for reporting!