Skip to content

Commit

Permalink
feat: accept client session in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagruenstein committed Sep 22, 2024
1 parent d11df9a commit 457b46d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 8 additions & 5 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import asyncio
import os

from aiohttp import BasicAuth
from aiohttp import BasicAuth, ClientSession

from intellinet_pdu_ctrl.api import IPU
from intellinet_pdu_ctrl.types import OutletCommand


async def main() -> None:
async with IPU(
"http://192.168.194.23:50071",
auth=BasicAuth(
os.environ.get("PDU_USER", "admin"), os.environ.get("PDU_PASS", "admin")
),
ClientSession(
"http://192.168.194.23:50071",
auth=BasicAuth(
os.environ.get("PDU_USER", "admin"), os.environ.get("PDU_PASS", "admin")
),
)
) as ipu:
await ipu.set_outlets(OutletCommand.ON, 0)
print(await ipu.get_status())


if __name__ == "__main__":
Expand Down
7 changes: 2 additions & 5 deletions intellinet_pdu_ctrl/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ class IPU:

def __init__(
self,
url: str,
auth: aiohttp.BasicAuth | None = None,
session: aiohttp.ClientSession,
):
self.url = url
self.auth = auth or self.DEFAULT_CREDS
self.session = aiohttp.ClientSession(base_url=self.url, auth=self.auth)
self.session = session

async def __aenter__(self) -> "IPU":
return self
Expand Down

0 comments on commit 457b46d

Please sign in to comment.