python-openevse-http 0.1.65__tar.gz → 0.1.66__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (15) hide show
  1. {python-openevse-http-0.1.65/python_openevse_http.egg-info → python_openevse_http-0.1.66}/PKG-INFO +2 -2
  2. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/openevsehttp/__main__.py +15 -0
  3. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/openevsehttp/const.py +2 -1
  4. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/openevsehttp/websocket.py +16 -0
  5. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66/python_openevse_http.egg-info}/PKG-INFO +1 -1
  6. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/setup.py +2 -2
  7. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/README.md +0 -0
  8. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/openevsehttp/__init__.py +0 -0
  9. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/openevsehttp/exceptions.py +0 -0
  10. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/python_openevse_http.egg-info/SOURCES.txt +0 -0
  11. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/python_openevse_http.egg-info/dependency_links.txt +0 -0
  12. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/python_openevse_http.egg-info/not-zip-safe +0 -0
  13. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/python_openevse_http.egg-info/requires.txt +0 -0
  14. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/python_openevse_http.egg-info/top_level.txt +0 -0
  15. {python-openevse-http-0.1.65 → python_openevse_http-0.1.66}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
- Name: python-openevse-http
3
- Version: 0.1.65
2
+ Name: python_openevse_http
3
+ Version: 0.1.66
4
4
  Summary: Python wrapper for OpenEVSE HTTP API
5
5
  Home-page: https://github.com/firstof9/python-openevse-http
6
6
  Author: firstof9
@@ -240,6 +240,7 @@ class OpenEVSE:
240
240
 
241
241
  if not self._ws_listening:
242
242
  self._loop.create_task(self.websocket.listen())
243
+ self._loop.create_task(self.repeat(300, self.websocket.keepalive()))
243
244
  pending = asyncio.all_tasks()
244
245
  self._ws_listening = True
245
246
  try:
@@ -301,6 +302,20 @@ class OpenEVSE:
301
302
  assert self.websocket
302
303
  return self.websocket.state
303
304
 
305
+ async def repeat(self, interval, func, *args, **kwargs):
306
+ """Run func every interval seconds.
307
+
308
+ If func has not finished before *interval*, will run again
309
+ immediately when the previous iteration finished.
310
+
311
+ *args and **kwargs are passed as the arguments to func.
312
+ """
313
+ while True:
314
+ await asyncio.gather(
315
+ func(*args, **kwargs),
316
+ asyncio.sleep(interval),
317
+ )
318
+
304
319
  async def get_schedule(self) -> Union[Dict[str, str], Dict[str, Any]]:
305
320
  """Return the current schedule."""
306
321
  url = f"{self.url}schedule"
@@ -14,4 +14,5 @@ SHAPER_LIVE = "shaper_live_pwr"
14
14
  TYPE = "type"
15
15
  VALUE = "value"
16
16
  RELEASE = "release"
17
- CLIENT = 4
17
+ # https://github.com/OpenEVSE/openevse_esp32_firmware/blob/master/src/evse_man.h#L28
18
+ CLIENT = 20
@@ -1,6 +1,7 @@
1
1
  """Websocket class for OpenEVSE HTTP."""
2
2
 
3
3
  import asyncio
4
+ import json
4
5
  import logging
5
6
 
6
7
  import aiohttp # type: ignore
@@ -39,6 +40,7 @@ class OpenEVSEWebsocket:
39
40
  self._state = None
40
41
  self.failed_attempts = 0
41
42
  self._error_reason = None
43
+ self._client = None
42
44
 
43
45
  @property
44
46
  def state(self):
@@ -74,6 +76,7 @@ class OpenEVSEWebsocket:
74
76
  ) as ws_client:
75
77
  await OpenEVSEWebsocket.state.fset(self, STATE_CONNECTED)
76
78
  self.failed_attempts = 0
79
+ self._client = ws_client
77
80
 
78
81
  async for message in ws_client:
79
82
  if self.state == STATE_STOPPED:
@@ -133,3 +136,16 @@ class OpenEVSEWebsocket:
133
136
  async def close(self):
134
137
  """Close the listening websocket."""
135
138
  await OpenEVSEWebsocket.state.fset(self, STATE_STOPPED)
139
+
140
+ async def keepalive(self):
141
+ """Send ping requests to websocket."""
142
+ data = json.dumps({"ping": 1})
143
+ _LOGGER.debug("Sending message: %s to websocket.", data)
144
+ try:
145
+ await self._client.send_str(data)
146
+ _LOGGER.debug("Ping message sent.")
147
+ except TypeError as err:
148
+ _LOGGER.error("Attempt to send ping data failed: %s", err)
149
+ except Exception as err: # pylint: disable=broad-exception-caught
150
+ _LOGGER.error("Problem sending ping request: %s", err)
151
+ await OpenEVSEWebsocket.state.fset(self, STATE_STOPPED)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-openevse-http
3
- Version: 0.1.65
3
+ Version: 0.1.66
4
4
  Summary: Python wrapper for OpenEVSE HTTP API
5
5
  Home-page: https://github.com/firstof9/python-openevse-http
6
6
  Author: firstof9
@@ -6,10 +6,10 @@ from setuptools import find_packages, setup
6
6
 
7
7
  PROJECT_DIR = Path(__file__).parent.resolve()
8
8
  README_FILE = PROJECT_DIR / "README.md"
9
- VERSION = "0.1.65"
9
+ VERSION = "0.1.66"
10
10
 
11
11
  setup(
12
- name="python-openevse-http",
12
+ name="python_openevse_http",
13
13
  version=VERSION,
14
14
  url="https://github.com/firstof9/python-openevse-http",
15
15
  download_url="https://github.com/firstof9/python-openevse-http",