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:])