magico13 / PyEmVue

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

get_devices() Typerror: Parser must be a string not NoneType #30

Closed leob19 closed 2 years ago

leob19 commented 2 years ago

Hi all,

I updated to latest package to solve auth issues but I am now having a date parsing issue when doing the following:

with open('keys.json') as f:
    data = json.load(f)

vue = em.PyEmVue()

token_storage_file='keys.json')
vue.login(id_token=data['idToken'],
   access_token=data['accessToken'],
   refresh_token=data['refreshToken'],
   token_storage_file='keys.json')

devices = vue.get_devices()

for device in devices:
    device = vue.populate_device_properties(device)
    print(device.device_name)

I get the following error: File "get_report.py", line 16, in devices = vue.get_devices() File "/env/lib/python3.9/site-packages/pyemvue/pyemvue.py", line 59, in get_devices devices.append(VueDevice().from_json_dictionary(dev)) File "/env/lib/python3.9/site-packages/pyemvue/device.py", line 68, in from_json_dictionary if 'offlineSince' in con: self.offline_since = parse(con['offlineSince']) File "env/lib/python3.9/site-packages/dateutil/parser/_parser.py", line 1374, in parse return DEFAULTPARSER.parse(timestr, kwargs) File "/env/lib/python3.9/site-packages/dateutil/parser/_parser.py", line 646, in parse res, skipped_tokens = self._parse(timestr, kwargs) File "env/lib/python3.9/site-packages/dateutil/parser/_parser.py", line 725, in _parse l = _timelex.split(timestr) # Splits the timestr into tokens File "env/lib/python3.9/site-packages/dateutil/parser/_parser.py", line 207, in split return list(cls(s)) File "env/lib/python3.9/site-packages/dateutil/parser/_parser.py", line 75, in init raise TypeError('Parser must be a string or character stream, not ' TypeError: Parser must be a string or character stream, not NoneType

Thanks for your help.

magico13 commented 2 years ago

Funny, someone just reported what is the same issue in the Home Assistant integration. I'm planning on fixing this tonight but if you have any devices that haven't been connected to the cloud in a while (smart plugs that have been unplugged for instance) then either reconnect them or remove them from your account. I'll get something out later to fix this properly so you can also just wait until then.

leob19 commented 2 years ago

Thanks Magico ! I do indeed have several plugs that have not been connected for some time.

kb8nh commented 2 years ago

I'm getting the same parser error starting at 4:00 PM EDT. I also noticed that in the Emporia App my Vue1 individual circuits are not showing now, either. Just has a default set of circuit names and no details for usage on these circuits.

kpnobvious commented 2 years ago

Hi Magico, i'm getting the same parser error after the API change and have updated pyemvue. I do have smart plugs but they are still on and connected. Not sure if anyone else has reported this again

magico13 commented 2 years ago

@kpnobvious if you can get me a full stack trace/error message I'd appreciate it. I was only aware of one location where this could come up and I added two safeties there to ensure it doesn't (null check and catching the exception). If I need to update a second location I can do that pretty easily and the stack trace will definitely show where that is.

kpnobvious commented 2 years ago

so interesting, i updated a basic test script that would pull the last 7 days of total usage ad added this for loop to print devices: for device in devices: device = vue.populate_device_properties(device) print(device.device_name)

When running just that, it outputs this: Home Home Plug Dehumidifier

The last 2 are smart plugs

When vuegraf runs to get usage data, it errors out here populateDevices(account) Traceback (most recent call last): File "", line 1, in File "src/vuegraf.py", line 66, in populateDevices devices = account['vue'].get_devices() File "/home/pi/.local/lib/python3.7/site-packages/pyemvue/pyemvue.py", line 59, in get_devices devices.append(VueDevice().from_json_dictionary(dev)) File "/home/pi/.local/lib/python3.7/site-packages/pyemvue/device.py", line 68, in from_json_dictionary if 'offlineSince' in con: self.offline_since = parse(con['offlineSince']) File "/home/pi/.local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 1356, in parse return DEFAULTPARSER.parse(timestr, kwargs) File "/home/pi/.local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 645, in parse res, skipped_tokens = self._parse(timestr, kwargs) File "/home/pi/.local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 721, in _parse l = _timelex.split(timestr) # Splits the timestr into tokens File "/home/pi/.local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 207, in split return list(cls(s)) File "/home/pi/.local/lib/python3.7/site-packages/dateutil/parser/_parser.py", line 76, in init '{itype}'.format(itype=instream.class.name)) TypeError: Parser must be a string or character stream, not NoneType

both plugs are showing on in the app and reporting usage.

when i updated i just did git pull and it updated teh source, maybe the python packaged is still cached?

kpnobvious commented 2 years ago

FYI, this was totally my issue. even though i updated pyemvue via git, and ran pip3 install pyemvue, it didn't update the local cache so that was still on vs 0.14.1. I had to add in the --upgrade command. No issues after that!