Fix error handling in switch.broadlink module (#20772)

* Fix error handling in switch.broadlink module

* Improve error messages
pull/20784/head
OleksandrBerchenko 2019-02-06 12:39:56 +02:00 committed by Daniel Høyer Iversen
parent b8cc547fa3
commit a1477fa156
1 changed files with 7 additions and 5 deletions

View File

@ -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