Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasnicolaas committed Dec 1, 2021
1 parent 9149c01 commit 4536e3c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions omnikinverter/omnikinverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ async def request(
"Accept": "text/html,application/xhtml+xml,application/xml",
}

if self._session is None:
self._session = ClientSession()
self._close_session = True
# Don't reuse session as Wifi stick does not seem to support it
self._session = ClientSession()

auth = None
if self.username and self.password:
Expand Down Expand Up @@ -112,7 +111,10 @@ async def request(
{"Content-Type": content_type, "response": text},
)

return await response.text()
raw_response = await response.read()
# Close the client session
await self._session.close()
return raw_response.decode("ascii", "ignore")

async def inverter(self) -> Inverter:
"""Get values from your Omnik Inverter.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bandit = "^1.7.0"
Changelog = "https://github.com/klaasnicolaas/python-omnikinverter/releases"

[tool.black]
target-version = ['py37']
target-version = ['py38']

[tool.coverage.paths]
source = ["omnikinverter"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_omnik.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def response_handler(_):
aresponses.add("example.com", "/js/status.js", "GET", response_handler)

async with aiohttp.ClientSession() as session:
client = OmnikInverter(host="example.com", session=session)
client = OmnikInverter(host="example.com", session=session, request_timeout=0.1)
with pytest.raises(OmnikInverterConnectionError):
assert await client.inverter()

Expand Down

0 comments on commit 4536e3c

Please sign in to comment.