powermonitor icon indicating copy to clipboard operation
powermonitor copied to clipboard

PyPi Release Version

Open codeclinic opened this issue 6 years ago • 4 comments

Hi Jason,

I'm thinking that this library would be a lot more useful if people could find it on PyPi as this would make it easier to install but also mean it could be used directly in Home assistant and probably other system without the need for the user to install/setup.

I'm just glancing at the process and I've already noticed that it would require removing all "print" statements and removing the dockerfile. So, I'm just wondering if you have any thoughts on the best way to proceed. The last thing I want to do is just fork this and create a separate PyPi version without seeing if you have any preferences/ideas on the best way to go.

codeclinic avatar Oct 11 '19 21:10 codeclinic

That's a great idea! Take a look at this and let me know if the interface would be appropriate for Home Assistant and other systems: https://github.com/jasonacox/tuyapower/tree/master/tuyapower

I'll submit it if this looks like it would work. Something like this:

import tuyapower

# Poll Smart Swich for Power Data
(on, w, mA, V, err) = tuyapower.deviceInfo(PLUGID,PLUGIP,PLUGKEY,PLUGVERS)

# Check for error
if err != 'OK':
        print(' ERROR: %s\n' % err)

# Print Output
print('    Switch On: %r' % on)
print('    Power (W): %f' % w)
print('    Current (mA): %f' % mA)
print('    Voltage (V): %f' % V)

jasonacox avatar Oct 12 '19 22:10 jasonacox

Give this a try:

# Install required libraries
 sudo apt-get install python-crypto python-pip		
 pip install pycrypto
 pip install pytuya
 pip install Crypto		# some systems will need this
 pip install pyaes		# some systems will need this
 pip install tuyapower  

# Run a test
 $ python
 Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tuyapower
>>> PLUGID = '01234567891234567890'
>>> PLUGIP = '10.0.0.10'
>>> PLUGKEY = '0123456789abcdef'
>>> tuyapower.deviceInfo(PLUGID,PLUGIP,PLUGKEY,'3.1')
(True, 1.2, 70.0, 121.1, 'OK')
>>> tuyapower.deviceInfo(PLUGID,PLUGIP,PLUGKEY,'3.3')
(False, -99.0, -99.0, -99.0, 'Timeout polling device')
>>> 

jasonacox avatar Oct 13 '19 01:10 jasonacox

Unfortunately I don't think that would work for inclusion in PyPi which is arguably the best way to get it into Home Assistant (and possibly others). However, it might be ok for inclusion in HACS, but I've not looked into that.

I did however, start working on something myself for PyPi, that reports the stats via MQTT which -speaking from my own perspective- is a more complete way of dealing with things. The less the end user needs to do to get this up and pulling stats into HA the better it will be for them and for general uptake.

codeclinic avatar Oct 13 '19 16:10 codeclinic

Understood. I uploaded it to PyPi as others may want to use it (https://pypi.org/project/tuyapower/). Good luck with your project! Let me know how it goes.

jasonacox avatar Oct 13 '19 22:10 jasonacox