From 399f8a786205dca24e5ad0441bc52fe0f468c185 Mon Sep 17 00:00:00 2001 From: Sebastian Muszynski Date: Mon, 17 Jul 2017 23:23:51 +0200 Subject: [PATCH] Reconnect on connection failure. --- xiaomiplug/device.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xiaomiplug/device.py b/xiaomiplug/device.py index 0a990c5..13eb35e 100644 --- a/xiaomiplug/device.py +++ b/xiaomiplug/device.py @@ -138,9 +138,10 @@ def send(self, command: str, parameters: Any=None) -> Any: m.data.value["id"], m.data.value)) return m.data.value["result"] - except OSError as ex: + except Exception as ex: _LOGGER.error("got error when receiving: %s", ex) - raise DeviceException from ex + self.__enter__() + raise @property def _id(self) -> int: