You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `python-openevse-http` library now supports passing an external `aiohttp.ClientSession` to the `OpenEVSE` class. This allows you to manage the session lifecycle yourself and share sessions across multiple API clients.
6
+
7
+
## Benefits
8
+
9
+
-**Session Reuse**: Share a single session across multiple OpenEVSE instances or other aiohttp-based clients
10
+
-**Custom Configuration**: Configure session settings like timeouts, connectors, and SSL verification
11
+
-**Resource Management**: Better control over connection pooling and resource cleanup
12
+
-**Integration**: Easier integration with existing applications that already manage aiohttp sessions
13
+
14
+
## Usage
15
+
16
+
### With External Session
17
+
18
+
```python
19
+
import aiohttp
20
+
from openevsehttp import OpenEVSE
21
+
22
+
asyncdefmain():
23
+
# Create your own session with custom settings
24
+
timeout = aiohttp.ClientTimeout(total=30)
25
+
asyncwith aiohttp.ClientSession(timeout=timeout) as session:
-`host` (str): The hostname or IP address of the OpenEVSE charger
90
+
-`user` (str, optional): Username for authentication
91
+
-`pwd` (str, optional): Password for authentication
92
+
-`session` (aiohttp.ClientSession | None, optional): External session to use for HTTP requests. If not provided, the library will create temporary sessions as needed.
93
+
94
+
### `OpenEVSEWebsocket.__init__()`
95
+
96
+
```python
97
+
def__init__(
98
+
self,
99
+
server,
100
+
callback,
101
+
user=None,
102
+
password=None,
103
+
session: aiohttp.ClientSession |None=None,
104
+
):
105
+
```
106
+
107
+
**Parameters:**
108
+
-`server`: The server URL
109
+
-`callback`: Callback function for websocket events
110
+
-`user` (optional): Username for authentication
111
+
-`password` (optional): Password for authentication
112
+
-`session` (aiohttp.ClientSession | None, optional): External session to use for websocket connections. If not provided, a new session will be created.
113
+
114
+
## Important Notes
115
+
116
+
1.**Session Lifecycle**: When you provide an external session, you are responsible for closing it. The library will NOT close externally provided sessions.
117
+
118
+
2.**Backward Compatibility**: This change is fully backward compatible. Existing code that doesn't provide a session will continue to work exactly as before.
119
+
120
+
3.**Websocket Sessions**: The websocket connection will also use the provided session, ensuring consistent session management across all HTTP and WebSocket operations.
121
+
122
+
4.**Thread Safety**: If you're using the same session across multiple OpenEVSE instances, ensure you're following aiohttp's thread safety guidelines.
123
+
124
+
## Migration Guide
125
+
126
+
If you want to migrate existing code to use external sessions:
0 commit comments