Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions ts/lock-codes-card.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,21 @@ describe('LockCodesCard integration', () => {
expect((card as any)._editingSlot).toBe(1);
expect((card as any)._editValue).toBe('1234');
});

it('a failed write does not follow you to the next row', async () => {
// The banner renders above the whole slot list, so a failure left
// over from slot 1 reads as if it belongs to whatever row you
// moved on to.
(card as any)._editingSlot = 1;
(card as any)._editValue = '1234';
sendMessagePromiseMock.mockRejectedValueOnce(new Error('Code already in use'));
await (card as any)._saveCode(1);
expect((card as any)._writeError).toBe('Code already in use');

(card as any)._startEditing({ stopPropagation: () => {} }, { code: 'empty', slot: 2 });

expect((card as any)._writeError).toBeUndefined();
});
/* eslint-enable @typescript-eslint/no-explicit-any */
});

Expand Down
6 changes: 4 additions & 2 deletions ts/lock-codes-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class LockCodesCard extends LockCodesCardBase {
_data?: LockCoordinatorData;
_error?: string;

/** Whether codes were revealed before editing started */

set hass(hass: HomeAssistant) {
this._hass = hass;
void this._subscribe();
Expand Down Expand Up @@ -194,6 +192,10 @@ class LockCodesCard extends LockCodesCardBase {
// Editing methods for unmanaged slots
private _startEditing(e: Event, slot: LockCoordinatorSlotData): void {
e.stopPropagation();
// Belongs to the row it happened on. Moving to another row without
// cancelling first would otherwise leave the previous row's failure
// on screen above the one now being typed into.
this._writeError = undefined;
// Deliberately does NOT reveal. `_revealed` is card-global and
// `_formatCode` reads it for every row, so revealing to edit one
// unmanaged slot put every managed user's PIN on screen in cleartext
Expand Down
Loading