From 690af0e9fae925d388d2d8fb508a2c784e4c7b68 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Thu, 13 Feb 2020 22:30:01 -0800 Subject: [PATCH] docs: add additional websocket logging --- teslajsonpy/connection.py | 3 ++- teslajsonpy/controller.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/teslajsonpy/connection.py b/teslajsonpy/connection.py index 23bc5e72..6c1ba464 100644 --- a/teslajsonpy/connection.py +++ b/teslajsonpy/connection.py @@ -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: @@ -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", diff --git a/teslajsonpy/controller.py b/teslajsonpy/controller.py index 8d02b9fd..97be77be 100644 --- a/teslajsonpy/controller.py +++ b/teslajsonpy/controller.py @@ -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 @@ -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:])