Fix use of "" on lock entity more info (use default code) (#18706)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
G Johansson 2023-12-04 14:23:11 +01:00 committed by GitHub
parent 8a93284bb3
commit 97b71c785b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import {
HassEntityAttributeBase, HassEntityAttributeBase,
HassEntityBase, HassEntityBase,
} from "home-assistant-js-websocket"; } from "home-assistant-js-websocket";
import { getExtendedEntityRegistryEntry } from "./entity_registry";
import { showEnterCodeDialogDialog } from "../dialogs/enter-code/show-enter-code-dialog"; import { showEnterCodeDialogDialog } from "../dialogs/enter-code/show-enter-code-dialog";
import { HomeAssistant } from "../types"; import { HomeAssistant } from "../types";
@ -30,15 +31,20 @@ export const callProtectedLockService = async (
service: ProtectedLockService service: ProtectedLockService
) => { ) => {
let code: string | undefined; let code: string | undefined;
const lockRegistryEntry = await getExtendedEntityRegistryEntry(
hass,
stateObj.entity_id
).catch(() => undefined);
const defaultCode = lockRegistryEntry?.options?.lock?.default_code;
if (stateObj!.attributes.code_format) { if (stateObj!.attributes.code_format && !defaultCode) {
const response = await showEnterCodeDialogDialog(element, { const response = await showEnterCodeDialogDialog(element, {
codeFormat: "text", codeFormat: "text",
codePattern: stateObj!.attributes.code_format, codePattern: stateObj!.attributes.code_format,
title: hass.localize(`ui.card.lock.${service}`), title: hass.localize(`ui.card.lock.${service}`),
submitText: hass.localize(`ui.card.lock.${service}`), submitText: hass.localize(`ui.card.lock.${service}`),
}); });
if (!response) { if (response == null) {
throw new Error("Code dialog closed"); throw new Error("Code dialog closed");
} }
code = response; code = response;

View File

@ -99,6 +99,8 @@ export class DialogEnterCode
id="code" id="code"
.label=${this.hass.localize("ui.dialogs.enter_code.input_label")} .label=${this.hass.localize("ui.dialogs.enter_code.input_label")}
type="password" type="password"
autoValidate
validateOnInitialRender
pattern=${ifDefined(this._dialogParams.codePattern)} pattern=${ifDefined(this._dialogParams.codePattern)}
inputmode="text" inputmode="text"
></ha-textfield> ></ha-textfield>