add reconnect retry and longer timeouts for verisure (#1944)
parent
4643dcde9c
commit
4850a65ed0
|
@ -48,6 +48,11 @@ class VerisureAlarm(alarm.AlarmControlPanel):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return hub.available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self):
|
||||||
"""The code format as regex."""
|
"""The code format as regex."""
|
||||||
|
|
|
@ -46,6 +46,11 @@ class VerisureDoorlock(LockDevice):
|
||||||
"""Return the state of the lock."""
|
"""Return the state of the lock."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return hub.available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self):
|
||||||
"""Return the required six digit code."""
|
"""Return the required six digit code."""
|
||||||
|
|
|
@ -65,6 +65,11 @@ class VerisureThermometer(Entity):
|
||||||
# Remove ° character
|
# Remove ° character
|
||||||
return hub.climate_status[self._id].temperature[:-1]
|
return hub.climate_status[self._id].temperature[:-1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return hub.available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this entity."""
|
"""Return the unit of measurement of this entity."""
|
||||||
|
@ -95,6 +100,11 @@ class VerisureHygrometer(Entity):
|
||||||
# remove % character
|
# remove % character
|
||||||
return hub.climate_status[self._id].humidity[:-1]
|
return hub.climate_status[self._id].humidity[:-1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return hub.available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this sensor."""
|
"""Return the unit of measurement of this sensor."""
|
||||||
|
@ -124,6 +134,11 @@ class VerisureMouseDetection(Entity):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return hub.mouse_status[self._id].count
|
return hub.mouse_status[self._id].count
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return hub.available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this sensor."""
|
"""Return the unit of measurement of this sensor."""
|
||||||
|
|
|
@ -42,6 +42,11 @@ class VerisureSmartplug(SwitchDevice):
|
||||||
"""Return true if on."""
|
"""Return true if on."""
|
||||||
return hub.smartplug_status[self._id].status == 'on'
|
return hub.smartplug_status[self._id].status == 'on'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if entity is available."""
|
||||||
|
return hub.available
|
||||||
|
|
||||||
def turn_on(self):
|
def turn_on(self):
|
||||||
"""Set smartplug status on."""
|
"""Set smartplug status on."""
|
||||||
hub.my_pages.smartplug.set(self._id, 'on')
|
hub.my_pages.smartplug.set(self._id, 'on')
|
||||||
|
|
|
@ -77,7 +77,7 @@ class VerisureHub(object):
|
||||||
# "wrong password" message. We will continue to retry after maintenance
|
# "wrong password" message. We will continue to retry after maintenance
|
||||||
# regardless of that error.
|
# regardless of that error.
|
||||||
self._disable_wrong_password_error = False
|
self._disable_wrong_password_error = False
|
||||||
self._wrong_password_given = False
|
self._password_retries = 1
|
||||||
self._reconnect_timeout = time.time()
|
self._reconnect_timeout = time.time()
|
||||||
|
|
||||||
self.my_pages = verisure.MyPages(
|
self.my_pages = verisure.MyPages(
|
||||||
|
@ -128,11 +128,13 @@ class VerisureHub(object):
|
||||||
self.my_pages.smartplug.get,
|
self.my_pages.smartplug.get,
|
||||||
self.smartplug_status)
|
self.smartplug_status)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return True if hub is available."""
|
||||||
|
return self._password_retries >= 0
|
||||||
|
|
||||||
def update_component(self, get_function, status):
|
def update_component(self, get_function, status):
|
||||||
"""Update the status of Verisure components."""
|
"""Update the status of Verisure components."""
|
||||||
if self._wrong_password_given:
|
|
||||||
_LOGGER.error('Wrong password for Verisure, update config')
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
for overview in get_function():
|
for overview in get_function():
|
||||||
try:
|
try:
|
||||||
|
@ -145,25 +147,26 @@ class VerisureHub(object):
|
||||||
|
|
||||||
def reconnect(self):
|
def reconnect(self):
|
||||||
"""Reconnect to Verisure MyPages."""
|
"""Reconnect to Verisure MyPages."""
|
||||||
if self._reconnect_timeout > time.time():
|
if (self._reconnect_timeout > time.time() or
|
||||||
return
|
not self._lock.acquire(blocking=False) or
|
||||||
if not self._lock.acquire(blocking=False):
|
self._password_retries < 0):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.my_pages.login()
|
self.my_pages.login()
|
||||||
self._disable_wrong_password_error = False
|
self._disable_wrong_password_error = False
|
||||||
|
self._password_retries = 1
|
||||||
except self._verisure.LoginError as ex:
|
except self._verisure.LoginError as ex:
|
||||||
_LOGGER.error("Wrong user name or password for Verisure MyPages")
|
_LOGGER.error("Wrong user name or password for Verisure MyPages")
|
||||||
if self._disable_wrong_password_error:
|
if self._disable_wrong_password_error:
|
||||||
self._reconnect_timeout = time.time() + 60
|
self._reconnect_timeout = time.time() + 60*60
|
||||||
else:
|
else:
|
||||||
self._wrong_password_given = True
|
self._password_retries = self._password_retries - 1
|
||||||
except self._verisure.MaintenanceError:
|
except self._verisure.MaintenanceError:
|
||||||
self._disable_wrong_password_error = True
|
self._disable_wrong_password_error = True
|
||||||
self._reconnect_timeout = time.time() + 60
|
self._reconnect_timeout = time.time() + 60*60
|
||||||
_LOGGER.error("Verisure MyPages down for maintenance")
|
_LOGGER.error("Verisure MyPages down for maintenance")
|
||||||
except self._verisure.Error as ex:
|
except self._verisure.Error as ex:
|
||||||
_LOGGER.error("Could not login to Verisure MyPages, %s", ex)
|
_LOGGER.error("Could not login to Verisure MyPages, %s", ex)
|
||||||
self._reconnect_timeout = time.time() + 5
|
self._reconnect_timeout = time.time() + 60
|
||||||
finally:
|
finally:
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
|
|
Loading…
Reference in New Issue