mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Nuki: add support for unique id (#31824)
* Nuki support unique id and the battery level attribute * Fix isort * Address comments * Cache attribute * Cleanup * Restore false * Fix isort
This commit is contained in:
parent
4e765398cc
commit
6f8f23238a
@ -77,26 +77,28 @@ class NukiLock(LockDevice):
|
|||||||
def __init__(self, nuki_lock):
|
def __init__(self, nuki_lock):
|
||||||
"""Initialize the lock."""
|
"""Initialize the lock."""
|
||||||
self._nuki_lock = nuki_lock
|
self._nuki_lock = nuki_lock
|
||||||
self._locked = nuki_lock.is_locked
|
|
||||||
self._name = nuki_lock.name
|
|
||||||
self._battery_critical = nuki_lock.battery_critical
|
|
||||||
self._available = nuki_lock.state not in ERROR_STATES
|
self._available = nuki_lock.state not in ERROR_STATES
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the lock."""
|
"""Return the name of the lock."""
|
||||||
return self._name
|
return self._nuki_lock.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self) -> str:
|
||||||
|
"""Return a unique ID."""
|
||||||
|
return self._nuki_lock.nuki_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_locked(self):
|
def is_locked(self):
|
||||||
"""Return true if lock is locked."""
|
"""Return true if lock is locked."""
|
||||||
return self._locked
|
return self._nuki_lock.is_locked
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the device specific state attributes."""
|
"""Return the device specific state attributes."""
|
||||||
data = {
|
data = {
|
||||||
ATTR_BATTERY_CRITICAL: self._battery_critical,
|
ATTR_BATTERY_CRITICAL: self._nuki_lock.battery_critical,
|
||||||
ATTR_NUKI_ID: self._nuki_lock.nuki_id,
|
ATTR_NUKI_ID: self._nuki_lock.nuki_id,
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
@ -119,17 +121,13 @@ class NukiLock(LockDevice):
|
|||||||
except RequestException:
|
except RequestException:
|
||||||
_LOGGER.warning("Network issues detect with %s", self.name)
|
_LOGGER.warning("Network issues detect with %s", self.name)
|
||||||
self._available = False
|
self._available = False
|
||||||
return
|
continue
|
||||||
|
|
||||||
# If in error state, we force an update and repoll data
|
# If in error state, we force an update and repoll data
|
||||||
self._available = self._nuki_lock.state not in ERROR_STATES
|
self._available = self._nuki_lock.state not in ERROR_STATES
|
||||||
if self._available:
|
if self._available:
|
||||||
break
|
break
|
||||||
|
|
||||||
self._name = self._nuki_lock.name
|
|
||||||
self._locked = self._nuki_lock.is_locked
|
|
||||||
self._battery_critical = self._nuki_lock.battery_critical
|
|
||||||
|
|
||||||
def lock(self, **kwargs):
|
def lock(self, **kwargs):
|
||||||
"""Lock the device."""
|
"""Lock the device."""
|
||||||
self._nuki_lock.lock()
|
self._nuki_lock.lock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user