diff --git a/src/components/ha-control-button.ts b/src/components/ha-control-button.ts index 58ea4f4400b2..6da398498461 100644 --- a/src/components/ha-control-button.ts +++ b/src/components/ha-control-button.ts @@ -84,6 +84,7 @@ export class HaControlButton extends LitElement { --control-button-background-color: var(--disabled-color); --control-button-background-opacity: 0.2; --control-button-border-radius: 10px; + --control-button-padding: 8px; --mdc-icon-size: 20px; color: var(--primary-text-color); width: 40px; @@ -95,16 +96,20 @@ export class HaControlButton extends LitElement { position: relative; cursor: pointer; display: flex; + flex-direction: column; align-items: center; justify-content: center; + text-align: center; width: 100%; height: 100%; border-radius: var(--control-button-border-radius); border: none; margin: 0; - padding: 0; + padding: var(--control-button-padding); box-sizing: border-box; - line-height: 0; + line-height: inherit; + font-family: Roboto; + font-weight: 500; outline: none; overflow: hidden; background: none; @@ -126,6 +131,8 @@ export class HaControlButton extends LitElement { background-color 180ms ease-in-out, opacity 180ms ease-in-out; opacity: var(--control-button-background-opacity); + pointer-events: none; + white-space: normal; } .button { transition: color 180ms ease-in-out; @@ -133,6 +140,7 @@ export class HaControlButton extends LitElement { } .button ::slotted(*) { pointer-events: none; + opacity: 0.95; } .button:disabled { cursor: not-allowed; diff --git a/src/dialogs/more-info/controls/more-info-lock.ts b/src/dialogs/more-info/controls/more-info-lock.ts index 9af77fd128bf..fccc841c9014 100644 --- a/src/dialogs/more-info/controls/more-info-lock.ts +++ b/src/dialogs/more-info/controls/more-info-lock.ts @@ -1,10 +1,12 @@ -import { mdiDoorOpen, mdiLock, mdiLockOff } from "@mdi/js"; +import { mdiCheck } from "@mdi/js"; import { CSSResultGroup, LitElement, css, html, nothing } from "lit"; -import { customElement, property } from "lit/decorators"; +import { customElement, property, state } from "lit/decorators"; import { styleMap } from "lit/directives/style-map"; import { stateColorCss } from "../../../common/entity/state_color"; import { supportsFeature } from "../../../common/entity/supports-feature"; import "../../../components/ha-attributes"; +import "../../../components/ha-control-button"; +import "../../../components/ha-control-button-group"; import "../../../components/ha-outlined-icon-button"; import "../../../components/ha-state-icon"; import { UNAVAILABLE } from "../../../data/entity"; @@ -18,14 +20,49 @@ import type { HomeAssistant } from "../../../types"; import "../components/ha-more-info-state-header"; import { moreInfoControlStyle } from "../components/more-info-control-style"; +const CONFIRM_TIMEOUT_SECOND = 5; +const OPENED_TIMEOUT_SECOND = 3; + +type ButtonState = "normal" | "confirm" | "success"; + @customElement("more-info-lock") class MoreInfoLock extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public stateObj?: LockEntity; + @state() public _buttonState: ButtonState = "normal"; + + private _buttonTimeout?: number; + + private _setButtonState(buttonState: ButtonState, timeoutSecond?: number) { + clearTimeout(this._buttonTimeout); + this._buttonState = buttonState; + if (timeoutSecond) { + this._buttonTimeout = window.setTimeout(() => { + this._buttonState = "normal"; + }, timeoutSecond * 1000); + } + } + private async _open() { + if (this._buttonState !== "confirm") { + this._setButtonState("confirm", CONFIRM_TIMEOUT_SECOND); + return; + } + callProtectedLockService(this, this.hass, this.stateObj!, "open"); + + this._setButtonState("success", OPENED_TIMEOUT_SECOND); + } + + private _resetButtonState() { + this._setButtonState("normal"); + } + + disconnectedCallback(): void { + super.disconnectedCallback(); + this._resetButtonState(); } private async _lock() { @@ -45,7 +82,7 @@ class MoreInfoLock extends LitElement { const color = stateColorCss(this.stateObj); const style = { - "--icon-color": color, + "--state-color": color, }; const isJammed = this.stateObj.state === "jammed"; @@ -56,74 +93,70 @@ class MoreInfoLock extends LitElement { .stateObj=${this.stateObj} >