magico13 / PyEmVue

Python Library for the Emporia Vue Energy Monitor
MIT License
185 stars 36 forks source link

Bug in date parsing #2

Closed magico13 closed 3 years ago

magico13 commented 3 years ago

Observed in a project I'm working on, making an issue so I can get back to this easily later and for visibility.

channel_usage_list = vue.get_recent_usage(scale=Scale.SECOND.value, unit=Unit.WATTS.value)
File "/var/task/pyemvue/pyemvue.py", line 94, in get_recent_usage
return self.get_usage_for_time_scale(now, scale, unit)[0]
File "/var/task/pyemvue/pyemvue.py", line 110, in get_usage_for_time_scale
realStart = datetime.datetime.strptime(j['start'], '%Y-%m-%dT%H:%M:%SZ')
File "/var/lang/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/var/lang/lib/python3.7/_strptime.py", line 359, in _strptime
(data_string, format))
ValueError: time data '2020-07-09T17:07:24.419489Z' does not match format '%Y-%m-%dT%H:%M:%SZ'
magico13 commented 3 years ago

Hmm, it seems they broke their own API for getting the day usage. https://api.emporiaenergy.com/usage/devices?start=2020-06-01T22:51:54Z&end=2020-06-05T22:51:54Z&scale=1D&unit=WATTS&customerGid={{customerGid}} returns a 400 with "message": "End instant must be equal or after start instant". Even in the official app viewing the day usage doesn't update. Viewing the historical usage in the graph view does work though but that data might be cached or using a different call.

magico13 commented 3 years ago

Date parsing fixed with v0.9.9 by using dateutil instead. Issue with the day call is on their api. I reported it via email so we'll see how they respond.