@@ -18,8 +18,8 @@ import {
1818 DEFAULT_CREDENTIAL_MAX_LENGTH ,
1919 DEFAULT_CREDENTIAL_MIN_LENGTH ,
2020 ENTERABLE_ZWAVE_CREDENTIAL_TYPES ,
21+ addZwaveUser ,
2122 deleteZwaveCredential ,
22- deleteZwaveUser ,
2323 enterableCredentialTypes ,
2424 getCredentialError ,
2525 compatibleUserTypes ,
@@ -508,27 +508,19 @@ class DialogZwaveCredentialUserEdit extends LitElement {
508508 credentialType : ZwaveCredentialType
509509 ) : Promise < void > {
510510 const params = this . _params ! ;
511- const { user_id } = await setZwaveUser ( this . hass , params . entity_id , {
512- user_name : this . _supportsUserNames ? this . _userName . trim ( ) : undefined ,
513- user_type : this . _userType ,
514- active : true ,
515- } ) ;
516-
511+ // Create the user and write the credential in a single call. This is the
512+ // only way to add a user on User Code CC locks, where the user and code
513+ // share a slot. If the credential write fails, the service rolls the user
514+ // back so the lock is never left with a credential-less user.
517515 try {
518- await setZwaveCredential ( this . hass , params . entity_id , {
519- user_id,
516+ await addZwaveUser ( this . hass , params . entity_id , {
517+ user_name : this . _supportsUserNames ? this . _userName . trim ( ) : undefined ,
518+ user_type : this . _userType ,
519+ active : true ,
520520 credential_type : credentialType ,
521521 credential_data : this . _credentialData ,
522522 } ) ;
523523 } catch ( err : unknown ) {
524- // Roll back the user so the lock returns to its prior state. We
525- // ignore rollback errors — the credential error is the actionable
526- // one to surface; a stranded user will reappear on next refresh.
527- try {
528- await deleteZwaveUser ( this . hass , params . entity_id , user_id ) ;
529- } catch {
530- // Ignore.
531- }
532524 this . _error = this . hass . localize (
533525 "ui.panel.config.zwave_js.credentials.errors.add_user_failed" ,
534526 {
0 commit comments