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