From 60e22783eeccdf974458831d786981582bc8303b Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 19:10:21 -0500 Subject: [PATCH 01/12] Reconnect when connection is lost --- homeassistant/components/device_tracker/mikrotik.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 320468159e0ba4..4bac4462c96a17 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -14,7 +14,7 @@ from homeassistant.const import ( CONF_HOST, CONF_PASSWORD, CONF_USERNAME, CONF_PORT) -REQUIREMENTS = ['librouteros==2.1.1'] +REQUIREMENTS = ['librouteros==2.2.0'] MTK_DEFAULT_API_PORT = '8728' @@ -134,7 +134,10 @@ def connect_to_device(self): def scan_devices(self): """Scan for new devices and return a list with found device MACs.""" - self._update_info() + try: + self._update_info() + except: + self.connect_to_device() return [device for device in self.last_results] def get_device_name(self, device): From 39d2320d68893de8e80bb60bcfda491854b47e09 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 19:13:57 -0500 Subject: [PATCH 02/12] Fix tabs --- homeassistant/components/device_tracker/mikrotik.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 4bac4462c96a17..74714648e5315b 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -134,7 +134,7 @@ def connect_to_device(self): def scan_devices(self): """Scan for new devices and return a list with found device MACs.""" - try: + try: self._update_info() except: self.connect_to_device() From 5f04f826dc6b7e65f8623bbd64b32ef925ad5ef5 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 21:49:59 -0500 Subject: [PATCH 03/12] add librouteros.exceptions --- homeassistant/components/device_tracker/mikrotik.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 74714648e5315b..e02d7514eee24e 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -136,7 +136,9 @@ def scan_devices(self): """Scan for new devices and return a list with found device MACs.""" try: self._update_info() - except: + except (librouteros.exceptions.TrapError, + librouteros.exceptions.MultiTrapError, + librouteros.exceptions.ConnectionError): self.connect_to_device() return [device for device in self.last_results] From c976aaf1fb68d7b64eb966fff4473f65b1508be5 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 21:53:09 -0500 Subject: [PATCH 04/12] add logger --- homeassistant/components/device_tracker/mikrotik.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index e02d7514eee24e..f24646563ec194 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -136,9 +136,8 @@ def scan_devices(self): """Scan for new devices and return a list with found device MACs.""" try: self._update_info() - except (librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ConnectionError): + except (librouteros.exceptions.TrapError, librouteros.exceptions.MultiTrapError, librouteros.exceptions.ConnectionError) as api_error: + _LOGGER.error("Connection error: %s", api_error) self.connect_to_device() return [device for device in self.last_results] From 0c34095194cbffe8b71fd7ef96ced2bfd0e3eb0a Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 21:54:25 -0500 Subject: [PATCH 05/12] fix line too long --- homeassistant/components/device_tracker/mikrotik.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index f24646563ec194..59e35de11b021c 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -136,7 +136,9 @@ def scan_devices(self): """Scan for new devices and return a list with found device MACs.""" try: self._update_info() - except (librouteros.exceptions.TrapError, librouteros.exceptions.MultiTrapError, librouteros.exceptions.ConnectionError) as api_error: + except (librouteros.exceptions.TrapError, + librouteros.exceptions.MultiTrapError, + librouteros.exceptions.ConnectionError) as api_error: _LOGGER.error("Connection error: %s", api_error) self.connect_to_device() return [device for device in self.last_results] From ee35bccdaeedede9bd58e8e78f7a61a7138b5495 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 22:06:32 -0500 Subject: [PATCH 06/12] added import librouteros --- homeassistant/components/device_tracker/mikrotik.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 59e35de11b021c..2639ca43feb40c 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -134,6 +134,7 @@ def connect_to_device(self): def scan_devices(self): """Scan for new devices and return a list with found device MACs.""" + import librouteros try: self._update_info() except (librouteros.exceptions.TrapError, From a394112bbc875b3757b62a53183d88809bd41f7d Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Mon, 12 Nov 2018 22:30:50 -0500 Subject: [PATCH 07/12] Update librouteros version --- requirements_all.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_all.txt b/requirements_all.txt index c91b41278802af..c6e73d5dcdd8d0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -536,7 +536,7 @@ libpurecoollink==0.4.2 libpyfoscam==1.0 # homeassistant.components.device_tracker.mikrotik -librouteros==2.1.1 +librouteros==2.2.0 # homeassistant.components.media_player.soundtouch libsoundtouch==0.7.2 From 738ada31207c476519dcde0f78c9ec57472b4ce8 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Tue, 13 Nov 2018 06:49:27 -0500 Subject: [PATCH 08/12] Update mikrotik.py --- homeassistant/components/device_tracker/mikrotik.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 2639ca43feb40c..1c7c7ab76fe349 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -128,8 +128,7 @@ def connect_to_device(self): except (librouteros.exceptions.TrapError, librouteros.exceptions.MultiTrapError, librouteros.exceptions.ConnectionError) as api_error: - _LOGGER.error("Connection error: %s", api_error) - + _LOGGER.error("Connection error: %s",api_error) return self.connected def scan_devices(self): From a9e80c6596eb237306c9b70fd7be4e6538f85b3d Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Tue, 13 Nov 2018 06:53:56 -0500 Subject: [PATCH 09/12] Update mikrotik.py --- homeassistant/components/device_tracker/mikrotik.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 1c7c7ab76fe349..91719e394d739d 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -128,7 +128,7 @@ def connect_to_device(self): except (librouteros.exceptions.TrapError, librouteros.exceptions.MultiTrapError, librouteros.exceptions.ConnectionError) as api_error: - _LOGGER.error("Connection error: %s",api_error) + _LOGGER.error("Connection error: %s", api_error) return self.connected def scan_devices(self): From 7058d708d13816999a442be8272671385020b242 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Tue, 13 Nov 2018 17:04:36 -0500 Subject: [PATCH 10/12] Fix trailing whitespace --- homeassistant/components/device_tracker/mikrotik.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 91719e394d739d..f1f86d7f74a65e 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -127,8 +127,7 @@ def connect_to_device(self): except (librouteros.exceptions.TrapError, librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ConnectionError) as api_error: - _LOGGER.error("Connection error: %s", api_error) + librouteros.exceptions.ConnectionError): return self.connected def scan_devices(self): From ac963463f9d77eb737061bee3e63d7b05c71b702 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Tue, 13 Nov 2018 21:48:20 -0500 Subject: [PATCH 11/12] Update mikrotik.py --- homeassistant/components/device_tracker/mikrotik.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index f1f86d7f74a65e..91719e394d739d 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -127,7 +127,8 @@ def connect_to_device(self): except (librouteros.exceptions.TrapError, librouteros.exceptions.MultiTrapError, - librouteros.exceptions.ConnectionError): + librouteros.exceptions.ConnectionError) as api_error: + _LOGGER.error("Connection error: %s", api_error) return self.connected def scan_devices(self): From fff8434bf03b4e2052f5abc4e97b984b305aaaa1 Mon Sep 17 00:00:00 2001 From: Robert Dunmire III Date: Wed, 14 Nov 2018 06:53:12 -0500 Subject: [PATCH 12/12] Update mikrotik.py --- homeassistant/components/device_tracker/mikrotik.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 91719e394d739d..09fb5c7ca57f6c 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -136,8 +136,8 @@ def scan_devices(self): import librouteros try: self._update_info() - except (librouteros.exceptions.TrapError, - librouteros.exceptions.MultiTrapError, + except (librouteros.exceptions.TrapError, + librouteros.exceptions.MultiTrapError, librouteros.exceptions.ConnectionError) as api_error: _LOGGER.error("Connection error: %s", api_error) self.connect_to_device()