Skip to content

Commit

Permalink
docs: add additional websocket logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Feb 14, 2020
1 parent d381d53 commit 690af0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion teslajsonpy/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async def _process_messages() -> None:
and msg_json["value"] == "disconnected"
):
if kwargs.get("on_disconnect"):
kwargs.get("on_disconnect")()
kwargs.get("on_disconnect")(msg_json)
if kwargs.get("on_message"):
kwargs.get("on_message")(msg_json)
elif msg.type == aiohttp.WSMsgType.ERROR:
Expand All @@ -213,6 +213,7 @@ async def _process_messages() -> None:
self.websocket = await self.websession.ws_connect(self.websocket_url)
loop = asyncio.get_event_loop()
loop.create_task(_process_messages())
_LOGGER.debug("%s:Trying to subscribe to websocket", vin[-5:])
await self.websocket.send_json(
data={
"msg_type": "data:subscribe_oauth",
Expand Down
6 changes: 6 additions & 0 deletions teslajsonpy/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ def _calculate_next_interval(vin: int) -> int:
vin[-5:],
self.__vin_vehicle_id_map[vin],
on_message=self._process_websocket_message,
on_disconnect=self._process_websocket_disconnect,
)
return update_succeeded

Expand Down Expand Up @@ -851,3 +852,8 @@ def _process_websocket_message(self, data):
_LOGGER.debug("Websocket for %s malformed: %s", vin[-5:], values)
for func in self.__websocket_listeners:
func(data)

def _process_websocket_disconnect(self, data):
vehicle_id = int(data["tag"])
vin = self.__vehicle_id_vin_map[vehicle_id]
_LOGGER.debug("Disconnected %s from websocket", vin[-5:])

0 comments on commit 690af0e

Please sign in to comment.