Code quality improvement for evohome (#43678)

This commit is contained in:
David Bonnes 2020-11-27 08:28:05 +00:00 committed by GitHub
parent c2cc605343
commit 5e3f4954f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -145,7 +145,6 @@ def _handle_exception(err) -> bool:
"Message is: %s", "Message is: %s",
err, err,
) )
return False
except aiohttp.ClientConnectionError: except aiohttp.ClientConnectionError:
# this appears to be a common occurrence with the vendor's servers # this appears to be a common occurrence with the vendor's servers
@ -155,7 +154,6 @@ def _handle_exception(err) -> bool:
"Message is: %s", "Message is: %s",
err, err,
) )
return False
except aiohttp.ClientResponseError: except aiohttp.ClientResponseError:
if err.status == HTTP_SERVICE_UNAVAILABLE: if err.status == HTTP_SERVICE_UNAVAILABLE:
@ -163,17 +161,16 @@ def _handle_exception(err) -> bool:
"The vendor says their server is currently unavailable. " "The vendor says their server is currently unavailable. "
"Check the vendor's service status page" "Check the vendor's service status page"
) )
return False
if err.status == HTTP_TOO_MANY_REQUESTS: elif err.status == HTTP_TOO_MANY_REQUESTS:
_LOGGER.warning( _LOGGER.warning(
"The vendor's API rate limit has been exceeded. " "The vendor's API rate limit has been exceeded. "
"If this message persists, consider increasing the %s", "If this message persists, consider increasing the %s",
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
) )
return False
raise # we don't expect/handle any other Exceptions else:
raise # we don't expect/handle any other Exceptions
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
@ -427,8 +424,8 @@ class EvoBroker:
try: try:
result = await api_function result = await api_function
except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err: except (aiohttp.ClientError, evohomeasync2.AuthenticationError) as err:
if not _handle_exception(err): _handle_exception(err)
return return
if update_state: # wait a moment for system to quiesce before updating state if update_state: # wait a moment for system to quiesce before updating state
self.hass.helpers.event.async_call_later(1, self._update_v2_api_state) self.hass.helpers.event.async_call_later(1, self._update_v2_api_state)