ReagentX / purple_air_api

Python package to get and transform PurpleAir data
https://pypi.org/project/purpleair/
GNU General Public License v3.0
51 stars 19 forks source link

Bug converting last_seen to datetime #60

Closed beatriznunez closed 4 years ago

beatriznunez commented 4 years ago

Thanks for the package Christopher.

I have just started using it and it seems that there is an issue while parsing dates:

image

beatriznunez commented 4 years ago
>>> timestamp = 1597939978
>>> datetime.utcfromtimestamp(int(timestamp) / 1000)
datetime.datetime(1970, 1, 19, 11, 52, 19, 978000)

>>> datetime.utcfromtimestamp(int(timestamp))
datetime.datetime(2020, 8, 20, 16, 12, 58)
ReagentX commented 4 years ago

You are correct that I am dividing the UTC timestamp by 1000:

https://github.com/ReagentX/purple_air_api/blob/e07beb618530ff9fecb4cfb78aacea2f2d61ec40/purpleair/channel.py#L124-L126

I was doing this previously because the docs stated that the UTC stamp had millisecond precision. I guess at some point they changed that. Luckily, this is a simple fix.

ReagentX commented 4 years ago

Okay, so the last_seen value from the sensor does not have millisecond precision (i.e. 1601557479), but the one in the Statistics field does (i.e. 1601557442965). I will push a new build shortly.

ReagentX commented 4 years ago

The new build is now available in PyPI. Please update with pip install --upgrade purpleair.