petretiandrea / plugp100

Work in progress implementation of tapo protocol in python.
GNU General Public License v3.0
71 stars 27 forks source link

KLAP handshake every time a request is sent #197

Open warp03 opened 2 months ago

warp03 commented 2 months ago

Hi

while using your library I noticed that it performs the entire KLAP handshake process every time a request is sent. This doesn't affect functionality, but impacts performance and creates a lot of unnecessary requests.

Looking into the code (plugp100/protocol/klap/klap_protocol.py), it seems like the issue is that it always thinks the KlapSession is expired, when sending a request using KlapProtocol::_send_request. In line 140, expire_at is set to the time in seconds when the session expires, but in KlapSession::is_handshake_session_expired (line 277), the comparison is done as if it is the time in milliseconds.

I'm not very familiar with the code, but removing both * 1000 in line 278 of klap_protocol.py seems to fix the issue.

Thanks and have a nice day :)