Pre-release
This release is a pre-release and may not be stable for production use.
# aiotplink
Library to communicate with TP-Link Smart Plugs and similar devices
## Features
* Supports TPLink Smart Switches and Lights
* Python API to interact with device at a low level using asyncio
## About this library
Based on the work done by [SoftSCheck](https://github.com/softScheck/tplink-smartplug)
and [GadgetReactor](https://github.com/GadgetReactor/pyHS100)
## Installation
```
$ sudo pip3 install aiotplink
```
At this point you should be able to use
You can try:
```
python3 -m aioyplink
```
And you should be able to turn On/Off your devices
## Using the library.
To make things simple, you create a class with 2 methods, "register" and "unregister"
class devices():
""" A simple class with a register and unregister methods
"""
def __init__(self):
self.devices={}
self.doi=None #device of interest
def register(self,info, addr):
if "mac" in info and info["mac"].lower() not in self.devices:
self.devices[info["mac"].lower()] = aiot.GetDevice(addr,info,hb=10)
else:
self.devices[info["mac"].lower()].addr = addr
def unregister(self,mac):
if mac.lower() in self.devices:
print ("%s is gone"% self.devices[mac.lower()].name)
self.devices[mac.lower()].stop()
del(self.devices[mac.lower()])
def stop(self):
for dev in self.devices.values():
dev.stop()
When registering, you get an dictionary with the flatten out info from a TP-Link device, and an address with
the format (ip address, port). You can pass those information directly to 'GetDevice' to get the correct object.
'GetDevice" is defined like so
GetDevice(addr,info,hb=HBTIMEOUT,on_change=lambda x: print(x))
With addr, the address pair, info, the flatten out informaton from discovery, hb, a heatbeat timeout in secs and
on_change a function that will react to whatever is produced by the heartbeat. Note that if the device has an energy meter,
those values will automatically be produced with the heartbeat.
After that it is quite simple.
MyDevices= devices()
loop = aio.get_event_loop()
discovery = aiot.TPLinkDiscovery(loop, MyDevices, repeat=15)
try:
loop.add_reader(sys.stdin,readin)
discovery.start()
print("Hit \"Enter\" to start")
print("Use Ctrl-C to quit")
loop.run_forever()
except:
print("Exiting at user's request.")
finally:
MyDevices.stop()
discovery.cleanup()
loop.remove_reader(sys.stdin)
loop.run_until_complete(aio.sleep(10))
loop.close()
Create a registrar instance
Create a TPLinkDiscovery instance passing the registrar and how often to run discovery
Start discovery, and you are on your merry way.
The various device object will have these methods available.
on(): Turning the device on
off(): Turning the device off
led_on(): Turn the LED light on (AKA "Night mode" off)
led_off : Turn the LED light off (AKA "Night mode" on)
set_name(name)
set_brighness)
set_temperature()
set_colour(hue, saturation, value)
depending on their capabilities.
Most commands are defined in the commands.py file.
## Troubleshooting
Open an issue and I'll try to help.
Library to communicate with TP-Link Smart Plugs and similar devices
## Features
* Supports TPLink Smart Switches and Lights
* Python API to interact with device at a low level using asyncio
## About this library
Based on the work done by [SoftSCheck](https://github.com/softScheck/tplink-smartplug)
and [GadgetReactor](https://github.com/GadgetReactor/pyHS100)
## Installation
```
$ sudo pip3 install aiotplink
```
At this point you should be able to use
You can try:
```
python3 -m aioyplink
```
And you should be able to turn On/Off your devices
## Using the library.
To make things simple, you create a class with 2 methods, "register" and "unregister"
class devices():
""" A simple class with a register and unregister methods
"""
def __init__(self):
self.devices={}
self.doi=None #device of interest
def register(self,info, addr):
if "mac" in info and info["mac"].lower() not in self.devices:
self.devices[info["mac"].lower()] = aiot.GetDevice(addr,info,hb=10)
else:
self.devices[info["mac"].lower()].addr = addr
def unregister(self,mac):
if mac.lower() in self.devices:
print ("%s is gone"% self.devices[mac.lower()].name)
self.devices[mac.lower()].stop()
del(self.devices[mac.lower()])
def stop(self):
for dev in self.devices.values():
dev.stop()
When registering, you get an dictionary with the flatten out info from a TP-Link device, and an address with
the format (ip address, port). You can pass those information directly to 'GetDevice' to get the correct object.
'GetDevice" is defined like so
GetDevice(addr,info,hb=HBTIMEOUT,on_change=lambda x: print(x))
With addr, the address pair, info, the flatten out informaton from discovery, hb, a heatbeat timeout in secs and
on_change a function that will react to whatever is produced by the heartbeat. Note that if the device has an energy meter,
those values will automatically be produced with the heartbeat.
After that it is quite simple.
MyDevices= devices()
loop = aio.get_event_loop()
discovery = aiot.TPLinkDiscovery(loop, MyDevices, repeat=15)
try:
loop.add_reader(sys.stdin,readin)
discovery.start()
print("Hit \"Enter\" to start")
print("Use Ctrl-C to quit")
loop.run_forever()
except:
print("Exiting at user's request.")
finally:
MyDevices.stop()
discovery.cleanup()
loop.remove_reader(sys.stdin)
loop.run_until_complete(aio.sleep(10))
loop.close()
Create a registrar instance
Create a TPLinkDiscovery instance passing the registrar and how often to run discovery
Start discovery, and you are on your merry way.
The various device object will have these methods available.
on(): Turning the device on
off(): Turning the device off
led_on(): Turn the LED light on (AKA "Night mode" off)
led_off : Turn the LED light off (AKA "Night mode" on)
set_name(name)
set_brighness)
set_temperature()
set_colour(hue, saturation, value)
depending on their capabilities.
Most commands are defined in the commands.py file.
## Troubleshooting
Open an issue and I'll try to help.
Metadata
Release files for aiotplink 0.1.0b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiotplink-0.1.0b1.tar.gz | 12.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiotplink-0.1.0b1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.7 kB
Release files / aiotplink-0.1.0b1.tar.gz
| Download URL | aiotplink-0.1.0b1.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63bba3a5142f6223fcb03aa92e410320eb79550ee2d44ec6f6893ad2408350f4
|
|
BLAKE2b-256 checksum How to use checksums |
2c8e0da9fb04d757a39263687d4e3725e53dfecd73a853a5e4b8a19b4053f43a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7
|
Release files / aiotplink-0.1.0b1-py3-none-any.whl
| Download URL | aiotplink-0.1.0b1-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
223091c74c55f742836d0a8157c0b35b9ed16ad4c54ec5ce82fab30139280e8e
|
|
BLAKE2b-256 checksum How to use checksums |
2439f80f712d06b40d8b208613b3803d2c5926505100b9943143fbd58fcd32d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.7
|