3
3
from __future__ import annotations
4
4
5
5
from abc import ABC , abstractmethod
6
+ import asyncio
6
7
import functools
7
8
from typing import TYPE_CHECKING , Any , Literal
8
9
@@ -127,27 +128,29 @@ async def async_unlock(self) -> None:
127
128
self ._state = STATE_UNLOCKED
128
129
self .maybe_emit_state_changed_event ()
129
130
130
- async def async_set_lock_user_code (self , code_slot : int , user_code : str ) -> None :
131
+ async def async_set_lock_user_code (
132
+ self , code_slot : int , user_code : str , ** kwargs
133
+ ) -> None :
131
134
"""Set the user_code to index X on the lock."""
132
135
if self ._doorlock_cluster_handler :
133
136
await self ._doorlock_cluster_handler .async_set_user_code (
134
137
code_slot , user_code
135
138
)
136
139
self .debug ("User code at slot %s set" , code_slot )
137
140
138
- async def async_enable_lock_user_code (self , code_slot : int ) -> None :
141
+ async def async_enable_lock_user_code (self , code_slot : int , ** kwargs ) -> None :
139
142
"""Enable user_code at index X on the lock."""
140
143
if self ._doorlock_cluster_handler :
141
144
await self ._doorlock_cluster_handler .async_enable_user_code (code_slot )
142
145
self .debug ("User code at slot %s enabled" , code_slot )
143
146
144
- async def async_disable_lock_user_code (self , code_slot : int ) -> None :
147
+ async def async_disable_lock_user_code (self , code_slot : int , ** kwargs ) -> None :
145
148
"""Disable user_code at index X on the lock."""
146
149
if self ._doorlock_cluster_handler :
147
150
await self ._doorlock_cluster_handler .async_disable_user_code (code_slot )
148
151
self .debug ("User code at slot %s disabled" , code_slot )
149
152
150
- async def async_clear_lock_user_code (self , code_slot : int ) -> None :
153
+ async def async_clear_lock_user_code (self , code_slot : int , ** kwargs ) -> None :
151
154
"""Clear the user_code at index X on the lock."""
152
155
if self ._doorlock_cluster_handler :
153
156
await self ._doorlock_cluster_handler .async_clear_user_code (code_slot )
@@ -163,12 +166,11 @@ def handle_cluster_handler_attribute_updated(
163
166
self .maybe_emit_state_changed_event ()
164
167
165
168
def restore_external_state_attributes (
166
- self ,
167
- * ,
168
- state : Literal ["locked" , "unlocked" ] | None ,
169
+ self , * , state : Literal ["locked" , "unlocked" ] | None , ** kwargs
169
170
) -> None :
170
171
"""Restore extra state attributes that are stored outside of the ZCL cache."""
171
172
self ._state = state
173
+ self .maybe_emit_state_changed_event ()
172
174
173
175
174
176
class WebSocketClientLockEntity (
@@ -183,6 +185,7 @@ def __init__(
183
185
) -> None :
184
186
"""Initialize the ZHA lock entity."""
185
187
super ().__init__ (entity_info , device )
188
+ self ._tasks : list [asyncio .Task ] = []
186
189
187
190
@property
188
191
def is_locked (self ) -> bool :
@@ -191,25 +194,47 @@ def is_locked(self) -> bool:
191
194
192
195
async def async_lock (self ) -> None :
193
196
"""Lock the lock."""
197
+ await self ._device .gateway .locks .lock (self .info_object )
194
198
195
199
async def async_unlock (self ) -> None :
196
200
"""Unlock the lock."""
201
+ await self ._device .gateway .locks .unlock (self .info_object )
197
202
198
203
async def async_set_lock_user_code (self , code_slot : int , user_code : str ) -> None :
199
204
"""Set the user_code to index X on the lock."""
205
+ await self ._device .gateway .locks .set_user_lock_code (
206
+ self .info_object , code_slot , user_code
207
+ )
200
208
201
209
async def async_enable_lock_user_code (self , code_slot : int ) -> None :
202
210
"""Enable user_code at index X on the lock."""
211
+ await self ._device .gateway .locks .enable_user_lock_code (
212
+ self .info_object , code_slot
213
+ )
203
214
204
215
async def async_disable_lock_user_code (self , code_slot : int ) -> None :
205
216
"""Disable user_code at index X on the lock."""
217
+ await self ._device .gateway .locks .disable_user_lock_code (
218
+ self .info_object , code_slot
219
+ )
206
220
207
221
async def async_clear_lock_user_code (self , code_slot : int ) -> None :
208
222
"""Clear the user_code at index X on the lock."""
223
+ await self ._device .gateway .locks .clear_user_lock_code (
224
+ self .info_object , code_slot
225
+ )
209
226
210
227
def restore_external_state_attributes (
211
228
self ,
212
229
* ,
213
230
state : Literal ["locked" , "unlocked" ] | None ,
214
231
) -> None :
215
232
"""Restore extra state attributes that are stored outside of the ZCL cache."""
233
+ task = asyncio .create_task (
234
+ self ._device .gateway .locks .restore_external_state_attributes (
235
+ self .info_object ,
236
+ state = state ,
237
+ )
238
+ )
239
+ self ._tasks .append (task )
240
+ task .add_done_callback (self ._tasks .remove )
0 commit comments