Skip to content

Commit

Permalink
Directly prompt for lock code in dashboards (#19835)
Browse files Browse the repository at this point in the history
Prompt for lock codes in more places
  • Loading branch information
chammp authored Feb 26, 2024
1 parent a39cf99 commit e8fca5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions src/panels/lovelace/entity-rows/hui-lock-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
import { createEntityNotFoundWarning } from "../components/hui-warning";
import { EntityConfig, LovelaceRow } from "./types";
import { callProtectedLockService } from "../../../data/lock";

@customElement("hui-lock-entity-row")
class HuiLockEntityRow extends LitElement implements LovelaceRow {
Expand Down Expand Up @@ -75,10 +76,11 @@ class HuiLockEntityRow extends LitElement implements LovelaceRow {
private _callService(ev): void {
ev.stopPropagation();
const stateObj = this.hass!.states[this._config!.entity];
this.hass!.callService(
"lock",
stateObj.state === "locked" ? "unlock" : "lock",
{ entity_id: stateObj.entity_id }
callProtectedLockService(
this,
this.hass!,
stateObj,
stateObj.state === "locked" ? "unlock" : "lock"
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/state-summary/state-card-lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { customElement, property } from "lit/decorators";
import { supportsFeature } from "../common/entity/supports-feature";
import "../components/entity/state-info";
import { LockEntityFeature } from "../data/lock";
import { callProtectedLockService, LockEntityFeature } from "../data/lock";
import { HomeAssistant } from "../types";
import { haStyle } from "../resources/styles";

Expand Down Expand Up @@ -56,10 +56,10 @@ class StateCardLock extends LitElement {
private async _callService(ev) {
ev.stopPropagation();
const service = ev.target.dataset.service;
const data = {
entity_id: this.stateObj.entity_id,
};
await this.hass.callService("lock", service, data);
if (!this.hass || !this.stateObj) {
return;
}
await callProtectedLockService(this, this.hass, this.stateObj, service);
}

static get styles(): CSSResultGroup {
Expand Down

0 comments on commit e8fca5d

Please sign in to comment.