Make sure to clean up httpx session on failed connection to Axis device (#42428)

This commit is contained in:
Robert Svensson 2020-10-26 22:12:21 +01:00 committed by GitHub
parent 6f2b0c756a
commit f0e11f713e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -280,12 +280,15 @@ async def get_device(hass, host, port, username, password):
except axis.Unauthorized as err:
LOGGER.warning("Connected to device at %s but not registered.", host)
await device.vapix.close()
raise AuthenticationRequired from err
except (asyncio.TimeoutError, axis.RequestError) as err:
LOGGER.error("Error connecting to the Axis device at %s", host)
await device.vapix.close()
raise CannotConnect from err
except axis.AxisException as err:
LOGGER.exception("Unknown Axis communication error occurred")
await device.vapix.close()
raise AuthenticationRequired from err