Skip to content

SmartlockInstance

Return the full last known API data for this smartlock.

Return the smartlock name from config if available.

Return the full state dictionary if available.

Return the remaining battery percentage, if known.

True if the smartlock state indicates it is locked.

Fetch the latest data for this smartlock.

Returns:

Name Type Description
dict Dict[str, Any]

The latest smartlock state object from the API.

Source code in nukiwebapi/smartlock_instance.py
52
53
54
55
56
57
58
59
60
def refresh(self) -> Dict[str, Any]:
    """
    Fetch the latest data for this smartlock.

    Returns:
        dict: The latest smartlock state object from the API.
    """
    self._data = self.client._request("GET", f"/smartlock/{self.id}")
    return self._data

Send an action command to the smartlock.

Parameters:

Name Type Description Default
action int

Action code (1=unlock, 2=lock, 3=unlatch, 4=lock’n’go, 5=lock’n’go+unlatch).

required
option int

Option mask (2=force, 4=full lock).

None

Returns:

Name Type Description
dict Dict[str, Any]

API response.

Source code in nukiwebapi/smartlock_instance.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
def _action(self, action: int, option: Optional[int] = None) -> Dict[str, Any]:
    """
    Send an action command to the smartlock.

    Args:
        action (int): Action code (1=unlock, 2=lock, 3=unlatch, 4=lock’n’go, 5=lock’n’go+unlatch).
        option (int, optional): Option mask (2=force, 4=full lock).

    Returns:
        dict: API response.
    """
    payload: Dict[str, Any] = {"action": action}
    if option is not None:
        payload["option"] = option

    response = self.client._request(
        "POST", f"/smartlock/{self.id}/action", json=payload
    )
    self.refresh()
    return response

Lock the smartlock.

Parameters:

Name Type Description Default
force bool

If True, use force option (option=2).

False
full bool

If True, request a full lock (option=4).

False

Returns:

Name Type Description
dict Dict[str, Any]

API response.

Source code in nukiwebapi/smartlock_instance.py
87
88
89
90
91
92
93
94
95
96
97
98
99
def lock(self, force: bool = False, full: bool = False) -> Dict[str, Any]:
    """
    Lock the smartlock.

    Args:
        force (bool): If True, use force option (option=2).
        full (bool): If True, request a full lock (option=4).

    Returns:
        dict: API response.
    """
    option = 2 if force else 4 if full else None
    return self._action(2, option=option)

Unlock the smartlock.

Parameters:

Name Type Description Default
force bool

If True, use force option (option=2).

False

Returns:

Name Type Description
dict Dict[str, Any]

API response.

Source code in nukiwebapi/smartlock_instance.py
101
102
103
104
105
106
107
108
109
110
111
112
def unlock(self, force: bool = False) -> Dict[str, Any]:
    """
    Unlock the smartlock.

    Args:
        force (bool): If True, use force option (option=2).

    Returns:
        dict: API response.
    """
    option = 2 if force else None
    return self._action(1, option=option)

Unlatch the smartlock.

Returns:

Name Type Description
dict Dict[str, Any]

API response.

Source code in nukiwebapi/smartlock_instance.py
114
115
116
117
118
119
120
121
def unlatch(self) -> Dict[str, Any]:
    """
    Unlatch the smartlock.

    Returns:
        dict: API response.
    """
    return self._action(3)

Perform lock ’n’ go.

Parameters:

Name Type Description Default
unlatch bool

If True, perform lock ’n’ go with unlatch (action=5).

False

Returns:

Name Type Description
dict Dict[str, Any]

API response.

Source code in nukiwebapi/smartlock_instance.py
123
124
125
126
127
128
129
130
131
132
133
def lock_and_go(self, unlatch: bool = False) -> Dict[str, Any]:
    """
    Perform lock ’n’ go.

    Args:
        unlatch (bool): If True, perform lock ’n’ go with unlatch (action=5).

    Returns:
        dict: API response.
    """
    return self._action(5 if unlatch else 4)