Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions openevsehttp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,11 @@ async def test_and_get(self) -> dict:

def ws_start(self) -> None:
"""Start the websocket listener."""
if self._ws_listening:
raise AlreadyListening
if self.websocket:
if self._ws_listening and self.websocket.state == "connected":
raise AlreadyListening
if self._ws_listening and self.websocket.state != "connected":
self._ws_listening = False
self._start_listening()

def _start_listening(self):
Expand Down
2 changes: 1 addition & 1 deletion openevsehttp/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
self._user = user
self._password = password
self.callback = callback
self._state = None
self._state = STATE_DISCONNECTED
self.failed_attempts = 0
self._error_reason = None
self._client = None
Expand Down
8 changes: 6 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
UnsupportedFeature,
)
from tests.common import load_fixture
from openevsehttp.websocket import SIGNAL_CONNECTION_STATE, STATE_CONNECTED
from openevsehttp.websocket import (
SIGNAL_CONNECTION_STATE,
STATE_CONNECTED,
STATE_DISCONNECTED,
)

pytestmark = pytest.mark.asyncio

Expand Down Expand Up @@ -53,7 +57,7 @@ async def test_ws_state(test_charger):
"""Test v4 Status reply."""
await test_charger.update()
value = test_charger.ws_state
assert value == None
assert value == STATE_DISCONNECTED
await test_charger.ws_disconnect()


Expand Down