jasonacox / tuyapower

Python module to read status and energy monitoring data from Tuya based WiFi smart devices. This includes state (on/off), current (mA), voltage (V), and power (wattage).
MIT License
136 stars 20 forks source link

AttributeError: module 'pytuya' has no attribute 'version' #5

Closed ferni7 closed 3 years ago

ferni7 commented 3 years ago

So trying to run this and I'm getting the below error. I can run the powermonitor version of this fine....

ferni@uvm:~/tuyapower$ docker run -e PLUGID='xxx' -e PLUGIP="192.168.1.x" -e PLUGKEY="yyy" -e PLUGVERS="3.3" -e verbose="true" tuyapower
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "tuyapower/__main__.py", line 12, in <module>
    import tuyapower
  File "/usr/local/lib/python3.8/site-packages/tuyapower/__init__.py", line 52, in <module>
    log.info("Using pytuya version %r", pytuya.version)
AttributeError: module 'pytuya' has no attribute 'version'
jasonacox commented 3 years ago

Thanks @Ferni7 ! You are right, there was a breaking update to the pytuya library. It was changed to use __version__ instead of version.

I have updated the tuyapower to version 0.0.20 and will be pushing the new module to PyPi. Please git pull the latest version and try again.

jason@home$ docker run -e PLUGID='xxx' -e PLUGIP="x" -e PLUGKEY="xxx" tuyapower
TuyaPower (Tuya Power Stats) [0.0.20]

Device 03200160dc4f2216f984 at 10.0.1.187 key 0123456789abcdef protocol 3.1:
    Switch On: True
    Power (W): 54.700000
    Current (mA): 477.000000
    Voltage (V): 120.300000
    Projected usage (kWh):  Day: 1.312800 Week: 9.189600  Month: 39.821600

{ "datetime": "2020-07-22T03:20:11Z", "switch": "True", "power": "54.7", "current": "477.0", "voltage": "120.3" }

Thanks for the report!

ferni7 commented 3 years ago

Thanks Jason - will give it a go :)

Also FYI - in your readme.md in the docker example down the bottom you have 'PLUGINVERS' as a parameter, that one cost me an hour of so until I realized it was meant to be PLUGVER :)

jasonacox commented 3 years ago

Doh!! Sorry about that but thanks for sharing! It should be PLUGVERS - I updated the readme.

ferni7 commented 3 years ago

All good - just tested latest and working great now :) Thanks!

jasonacox commented 3 years ago

Awesome! Thanks for the confirmation.