mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix timer entity display (#6849)
This commit is contained in:
parent
4e676b1dba
commit
909cff2158
@ -1,7 +1,12 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import durationToSeconds from "../datetime/duration_to_seconds";
|
import durationToSeconds from "../datetime/duration_to_seconds";
|
||||||
|
|
||||||
export const timerTimeRemaining = (stateObj: HassEntity) => {
|
export const timerTimeRemaining = (
|
||||||
|
stateObj: HassEntity
|
||||||
|
): undefined | number => {
|
||||||
|
if (!stateObj.attributes.remaining) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
let timeRemaining = durationToSeconds(stateObj.attributes.remaining);
|
let timeRemaining = durationToSeconds(stateObj.attributes.remaining);
|
||||||
|
|
||||||
if (stateObj.state === "active") {
|
if (stateObj.state === "active") {
|
||||||
|
@ -26,15 +26,12 @@ class MoreInfoTimer extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-attributes
|
<ha-attributes
|
||||||
.stateObj=${this.stateObj}
|
.stateObj=${this.stateObj}
|
||||||
.extraFilters=${"remaining"}
|
extra-filters="remaining"
|
||||||
></ha-attributes>
|
></ha-attributes>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
${this.stateObj.state === "idle" || this.stateObj.state === "paused"
|
${this.stateObj.state === "idle" || this.stateObj.state === "paused"
|
||||||
? html`
|
? html`
|
||||||
<mwc-button
|
<mwc-button .action=${"start"} @click=${this._handleActionClick}>
|
||||||
.action="${"start"}"
|
|
||||||
@click="${this._handleActionClick}"
|
|
||||||
>
|
|
||||||
${this.hass!.localize("ui.card.timer.actions.start")}
|
${this.hass!.localize("ui.card.timer.actions.start")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
`
|
`
|
||||||
@ -42,7 +39,7 @@ class MoreInfoTimer extends LitElement {
|
|||||||
${this.stateObj.state === "active"
|
${this.stateObj.state === "active"
|
||||||
? html`
|
? html`
|
||||||
<mwc-button
|
<mwc-button
|
||||||
.action="${"pause"}"
|
.action=${"pause"}
|
||||||
@click="${this._handleActionClick}"
|
@click="${this._handleActionClick}"
|
||||||
>
|
>
|
||||||
${this.hass!.localize("ui.card.timer.actions.pause")}
|
${this.hass!.localize("ui.card.timer.actions.pause")}
|
||||||
@ -52,13 +49,13 @@ class MoreInfoTimer extends LitElement {
|
|||||||
${this.stateObj.state === "active" || this.stateObj.state === "paused"
|
${this.stateObj.state === "active" || this.stateObj.state === "paused"
|
||||||
? html`
|
? html`
|
||||||
<mwc-button
|
<mwc-button
|
||||||
.action="${"cancel"}"
|
.action=${"cancel"}
|
||||||
@click="${this._handleActionClick}"
|
@click="${this._handleActionClick}"
|
||||||
>
|
>
|
||||||
${this.hass!.localize("ui.card.timer.actions.cancel")}
|
${this.hass!.localize("ui.card.timer.actions.cancel")}
|
||||||
</mwc-button>
|
</mwc-button>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
.action="${"finish"}"
|
.action=${"finish"}
|
||||||
@click="${this._handleActionClick}"
|
@click="${this._handleActionClick}"
|
||||||
>
|
>
|
||||||
${this.hass!.localize("ui.card.timer.actions.finish")}
|
${this.hass!.localize("ui.card.timer.actions.finish")}
|
||||||
|
@ -2,9 +2,9 @@ import { HassEntity } from "home-assistant-js-websocket";
|
|||||||
import {
|
import {
|
||||||
customElement,
|
customElement,
|
||||||
html,
|
html,
|
||||||
|
internalProperty,
|
||||||
LitElement,
|
LitElement,
|
||||||
property,
|
property,
|
||||||
internalProperty,
|
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
@ -125,7 +125,9 @@ class HuiTimerEntityRow extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stateObj.state === "idle" || this._timeRemaining === 0) {
|
if (stateObj.state === "idle" || this._timeRemaining === 0) {
|
||||||
return this.hass!.localize("state.timer." + stateObj.state);
|
return (
|
||||||
|
this.hass!.localize(`state.timer.${stateObj.state}`) || stateObj.state
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let display = secondsToDuration(this._timeRemaining || 0);
|
let display = secondsToDuration(this._timeRemaining || 0);
|
||||||
|
@ -23,7 +23,7 @@ class StateCardTimer extends PolymerElement {
|
|||||||
|
|
||||||
<div class="horizontal justified layout">
|
<div class="horizontal justified layout">
|
||||||
${this.stateInfoTemplate}
|
${this.stateInfoTemplate}
|
||||||
<div class="state">[[_secondsToDuration(timeRemaining)]]</div>
|
<div class="state">[[_displayState(timeRemaining, stateObj)]]</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -90,8 +90,10 @@ class StateCardTimer extends PolymerElement {
|
|||||||
this.timeRemaining = timerTimeRemaining(stateObj);
|
this.timeRemaining = timerTimeRemaining(stateObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
_secondsToDuration(time) {
|
_displayState(time, stateObj) {
|
||||||
return secondsToDuration(time);
|
return time
|
||||||
|
? secondsToDuration(time)
|
||||||
|
: this.hass.localize(`state.timer.${stateObj.state}`) || stateObj.state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
customElements.define("state-card-timer", StateCardTimer);
|
customElements.define("state-card-timer", StateCardTimer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user