From a1477fa15681d03a60e4fd7538b79406b4c1aa28 Mon Sep 17 00:00:00 2001 From: OleksandrBerchenko Date: Wed, 6 Feb 2019 12:39:56 +0200 Subject: [PATCH] Fix error handling in switch.broadlink module (#20772) * Fix error handling in switch.broadlink module * Improve error messages --- homeassistant/components/switch/broadlink.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/switch/broadlink.py b/homeassistant/components/switch/broadlink.py index 9c17767f033..2237a0a2977 100644 --- a/homeassistant/components/switch/broadlink.py +++ b/homeassistant/components/switch/broadlink.py @@ -235,7 +235,7 @@ class BroadlinkRMSwitch(SwitchDevice): self._device.send_data(packet) except (socket.timeout, ValueError) as error: if retry < 1: - _LOGGER.error(error) + _LOGGER.error("Error during sending a packet: %s", error) return False if not self._auth(): return False @@ -247,6 +247,8 @@ class BroadlinkRMSwitch(SwitchDevice): auth = self._device.auth() except socket.timeout: auth = False + if retry < 1: + _LOGGER.error("Timeout during authorization") if not auth and retry > 0: return self._auth(retry-1) return auth @@ -268,7 +270,7 @@ class BroadlinkSP1Switch(BroadlinkRMSwitch): self._device.set_power(packet) except (socket.timeout, ValueError) as error: if retry < 1: - _LOGGER.error(error) + _LOGGER.error("Error during sending a packet: %s", error) return False if not self._auth(): return False @@ -308,7 +310,7 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch): load_power = self._device.get_energy() except (socket.timeout, ValueError) as error: if retry < 1: - _LOGGER.error(error) + _LOGGER.error("Error during updating the state: %s", error) return if not self._auth(): return @@ -341,7 +343,7 @@ class BroadlinkMP1Slot(BroadlinkRMSwitch): self._device.set_power(self._slot, packet) except (socket.timeout, ValueError) as error: if retry < 1: - _LOGGER.error(error) + _LOGGER.error("Error during sending a packet: %s", error) return False if not self._auth(): return False @@ -382,7 +384,7 @@ class BroadlinkMP1Switch: states = self._device.check_power() except (socket.timeout, ValueError) as error: if retry < 1: - _LOGGER.error(error) + _LOGGER.error("Error during updating the state: %s", error) return if not self._auth(): return