magico13 / PyEmVue

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

SyntaxError: invalid syntax (0.10.1) & ImportError: No module named enums (0.9.9) #6

Closed ikishk closed 3 years ago

ikishk commented 3 years ago

installed using setup.py...

PyEmVue-0.10.1# python -m pyemvue ../keys.json
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
    mod_name, _Error)
  File "/usr/lib/python2.7/runpy.py", line 111, in _get_module_details
    __import__(mod_name)  # Do not catch exceptions initializing package
  File "pyemvue/__init__.py", line 2, in <module>
    from pyemvue.pyemvue import PyEmVue
  File "pyemvue/pyemvue.py", line 85
    raise ValueError(f'Scale of {scale} is invalid, must be 1S, 1MIN, 15MIN, or 1H.')
                                                                                   ^
SyntaxError: invalid syntax

# ls /usr/local/lib/python2.7/dist-packages|grep vue
pyemvue-0.10.1-py2.7.egg

tried downgrading,.. diff error:

PyEmVue-0.9.9# python -m pyemvue ../keys.json
 Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 163, in _run_module_as_main
    mod_name, _Error)
  File "/usr/lib/python2.7/runpy.py", line 111, in _get_module_details
    __import__(mod_name)  # Do not catch exceptions initializing package
  File "pyemvue/__init__.py", line 2, in <module>
    from pyemvue.pyemvue import PyEmVue
  File "pyemvue/pyemvue.py", line 12, in <module>
    from pyemvue.enums import Scale, Unit, TotalTimeFrame, TotalUnit
ImportError: No module named enums
# ls /usr/local/lib/python2.7/dist-packages|grep vue
pyemvue-0.9.9-py2.7.egg

# python --version
Python 2.7.12

also tried w/ python3 w/ same errors.

# python3 --version
Python 3.5.2
# ls /usr/local/lib/python3.5/dist-packages/|grep vue
pyemvue-0.10.1-py3.5.egg

any ideas?

magico13 commented 3 years ago

So it looks like because I use f-strings to do string formatting that requires python 3.6 or higher. I can swap all of those over to str.Format to possibly work with older python versions but I don't have time right now to do so, so you upgrading to 3.6+ might be quicker.

ikishk commented 3 years ago

excellent, that helped a bit. now showing something new:

# python3.7 -m pyemvue keys.json
Logged in. Authtoken follows:
[snip]
14419 A2032A04B3************ VUE002 Vue2-1598375990
         14419 None 1,2,3 1.0
14419 SXA2032A04************ WAT001 None
         14419 A/C Upstairs 1 2.0
[snip- all circuits shown, seems to be multiplier]
14782 B0000C89************ SSO001 Outlet-1594685591
         14782 None 1,2,3 1.0
[snip- all outlets]
680.9621060973697 kwh used month to date
680.9621060973697 kwh used total
Total usage for today in kwh:
14787 (1,2,3): 0.0 kwh
14786 (1,2,3): 1.136471128910556 kwh
14782 (1,2,3): 0.008774566296009943 kwh
14785 (1,2,3): 3.4460146545716683 kwh
14419 (1,2,3): 36.48905141789754 kwh
[snip- all circuits/outlets]
Total usage for yesterday in kwh:
14785 (1,2,3): 4.150696996170024 kwh
14419 (1,2,3): 113.06661549910652 kwh
[snip- 8 used circuits]
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/dist-packages/pyemvue/__main__.py", line 86, in <module>
    main()
  File "/usr/local/lib/python3.7/dist-packages/pyemvue/__main__.py", line 77, in main
    print(f'{chan.device_gid} ({chan.channel_num}): {usage[1]/1000} kwh')
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

# python3.7 --version
Python 3.7.9

seems when it hits circuit #9 is barfs on zero/none

magico13 commented 3 years ago

Sounds like the library is working at least but getting bad data for that particular channel. If you were planning on using the library within something else then you should be good to go.

ikishk commented 3 years ago

yup. thank you. any shortcuts to output raw json instead of depending on python formatting? ie. might be nice to have a big json dump for some ajax :)

magico13 commented 3 years ago

You can always make the calls against their APIs directly. You can get the token out of PyEmVue after logging in with it and then use that for those calls. Alternatively you can use the json library to take one of the response objects and just json.dumps() it. If you wanted to call their API I have some documentation on it here https://github.com/magico13/PyEmVue/blob/master/api_docs.md

ikishk commented 3 years ago

perfect and outside the box, love it :)