petretiandrea / plugp100

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

Closing things down cleanly #191

Open pcollinson opened 5 months ago

pcollinson commented 5 months ago

If I run your second example on the README page, to connect with an IP address, the output ends with:

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f254e230390>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f254e248910>, 1996610.550300446)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f254f0e2710>

I've got a daemon running that talks to several plugs and I want to cleanly close things down when I am done with one plug.

I'm unsure to how to do this. Ideally I'd just like to call close() on the class that initialises things, and have this call close() on the object returned by the connect() calls - and for that to get rid of the running aiohttp session.

Well, after some confusion, I've found a reference to close the session.

If self._client is the object returned by connect(), then

await self._client.client.protocol.close()

finds the lurking aiohttp() session. This seems to be some way down the tree of code, can we have a more transparent way?

_client is a TapoPlug _client.client is a TapoClient

If TapoClient had a close() function then it would be transparent. Is this a possibility?