python-openevse-http 0.1.67__tar.gz → 0.1.69__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python_openevse_http
3
- Version: 0.1.67
3
+ Version: 0.1.69
4
4
  Summary: Python wrapper for OpenEVSE HTTP API
5
5
  Home-page: https://github.com/firstof9/python-openevse-http
6
6
  Author: firstof9
@@ -261,6 +261,7 @@ class OpenEVSE:
261
261
  self.websocket.uri,
262
262
  )
263
263
  self._ws_listening = False
264
+ self.ws_start()
264
265
  # Stopped websockets without errors are expected during shutdown
265
266
  # and ignored
266
267
  elif data == STATE_STOPPED and error:
@@ -270,6 +271,7 @@ class OpenEVSE:
270
271
  error,
271
272
  )
272
273
  self._ws_listening = False
274
+ await self.ws_disconnect()
273
275
 
274
276
  elif msgtype == "data":
275
277
  _LOGGER.debug("Websocket data: %s", data)
@@ -1,6 +1,7 @@
1
1
  """Websocket class for OpenEVSE HTTP."""
2
2
 
3
3
  import asyncio
4
+ import datetime
4
5
  import json
5
6
  import logging
6
7
 
@@ -13,6 +14,7 @@ MAX_FAILED_ATTEMPTS = 5
13
14
  ERROR_AUTH_FAILURE = "Authorization failure"
14
15
  ERROR_TOO_MANY_RETRIES = "Too many retries"
15
16
  ERROR_UNKNOWN = "Unknown"
17
+ ERROR_PING_TIMEOUT = "No pong reply"
16
18
 
17
19
  SIGNAL_CONNECTION_STATE = "websocket_state"
18
20
  STATE_CONNECTED = "connected"
@@ -41,6 +43,8 @@ class OpenEVSEWebsocket:
41
43
  self.failed_attempts = 0
42
44
  self._error_reason = None
43
45
  self._client = None
46
+ self._ping = None
47
+ self._pong = None
44
48
 
45
49
  @property
46
50
  def state(self):
@@ -86,6 +90,8 @@ class OpenEVSEWebsocket:
86
90
  msg = message.json()
87
91
  msgtype = "data"
88
92
  await self.callback(msgtype, msg, None)
93
+ if "pong" in msg.keys():
94
+ self._pong = datetime.datetime.now()
89
95
 
90
96
  elif message.type == aiohttp.WSMsgType.CLOSED:
91
97
  _LOGGER.warning("Websocket connection closed")
@@ -139,13 +145,22 @@ class OpenEVSEWebsocket:
139
145
 
140
146
  async def keepalive(self):
141
147
  """Send ping requests to websocket."""
148
+ if self._ping and self._pong:
149
+ time_delta = self._pong - self._ping
150
+ if time_delta < 0:
151
+ # Negitive time should indicate no pong reply so consider the
152
+ # websocket disconnected.
153
+ await OpenEVSEWebsocket.state.fset(self, STATE_DISCONNECTED)
154
+ self._error_reason = ERROR_PING_TIMEOUT
155
+
142
156
  data = json.dumps({"ping": 1})
143
157
  _LOGGER.debug("Sending message: %s to websocket.", data)
144
158
  try:
145
159
  await self._client.send_str(data)
160
+ self._ping = datetime.datetime.now()
146
161
  _LOGGER.debug("Ping message sent.")
147
162
  except TypeError as err:
148
163
  _LOGGER.error("Attempt to send ping data failed: %s", err)
149
164
  except Exception as err: # pylint: disable=broad-exception-caught
150
165
  _LOGGER.error("Problem sending ping request: %s", err)
151
- await OpenEVSEWebsocket.state.fset(self, STATE_STOPPED)
166
+ await OpenEVSEWebsocket.state.fset(self, STATE_DISCONNECTED)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-openevse-http
3
- Version: 0.1.67
3
+ Version: 0.1.69
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,7 +6,7 @@ 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.67"
9
+ VERSION = "0.1.69"
10
10
 
11
11
  setup(
12
12
  name="python_openevse_http",