SonnenladenGmbH / APsystems-EZ1-API

The APsystems EZ1 Python library offers a streamlined interface for interacting with the local API of APsystems EZ1 Microinverters.
MIT License
54 stars 7 forks source link

New ClientSession handling in V1.2 #20

Closed Sebastian-MrBeam closed 2 months ago

Sebastian-MrBeam commented 2 months ago

The new _request() Funktion is not closing the ClientSession (no matter if external or self generated). The "with" statement should do that automatically - in my opinion - but somehow does not. Finally it´s necessary behavior, because in difference to V1.1 were every request() call was creating a new ClientSession() in V1.2 this is done only once at class __init_\ . If a ClientSession can be closed by errors the EZ1M class (without external Session handling ) will stop working - monitoring will show if this is a relevant issue.

Overall the calls Monitoring for last 2 days shows less missed calls than V1.1 (on a daily base) - more stable = nice!

One idea for sanitizing - if a Funktion opens a Instanz of EZ1M (without external Session handling ) a open Session remains and raises an error when Funktion ends. This can be manually fixed with " EZ1M.session.close()
A class Funktion could be a improvement - EZ1M.close() is still manual work

async def close(self):
    if self.session.closed == False :
           await self.session.close()

the class del call looks not compatible to async, maybe someone with more experience have a idea to automate that for a careless destruction.

mawoka-myblock commented 2 months ago

That's a good point. Gonna check on that.

mawoka-myblock commented 2 months ago

Fixed that in #19

Sebastian-MrBeam commented 2 months ago

Nice solution! Thanks for fixing 😃