Moved more logic from tplink.py into a library.