Forget auth token when going offline so we can reconnect (#26630)

When an amcrest camera was unplugged and then plugged again
it was impossible to reconnect to it, since the old
auth token was reused while we need to use a new one.

In fact, the method that is called every minute to check
the camera availability is going to fail always since we're
reusing an old token.

By forgetting the token (setting it to None) when going offline,
we ensure that we'll regenerate it in the next commands thus allowing
to reconnect to the camera when it comes back online.
pull/27794/head
Antonio Larrosa 2019-10-17 11:29:08 +02:00 committed by Pascal Vizeli
parent 46f1166edd
commit 2d6d6ba90e
1 changed files with 2 additions and 0 deletions

View File

@ -167,6 +167,8 @@ class AmcrestChecker(Http):
offline = not self.available
if offline and was_online:
_LOGGER.error("%s camera offline: Too many errors", self._wrap_name)
with self._token_lock:
self._token = None
dispatcher_send(
self._hass, service_signal(SERVICE_UPDATE, self._wrap_name)
)