mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Create more-for timer with action buttons (#3621)
* Create more-for timer with action buttons Closes https://github.com/home-assistant/home-assistant-polymer/issues/3594 * center actions * Address review comments * address review comments
This commit is contained in:
parent
2ff4d0fa4b
commit
cbd01f2d68
@ -45,6 +45,7 @@ export const DOMAINS_WITH_MORE_INFO = [
|
|||||||
"media_player",
|
"media_player",
|
||||||
"script",
|
"script",
|
||||||
"sun",
|
"sun",
|
||||||
|
"timer",
|
||||||
"updater",
|
"updater",
|
||||||
"vacuum",
|
"vacuum",
|
||||||
"water_heater",
|
"water_heater",
|
||||||
|
11
src/data/timer.ts
Normal file
11
src/data/timer.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import {
|
||||||
|
HassEntityBase,
|
||||||
|
HassEntityAttributeBase,
|
||||||
|
} from "home-assistant-js-websocket";
|
||||||
|
|
||||||
|
export type TimerEntity = HassEntityBase & {
|
||||||
|
attributes: HassEntityAttributeBase & {
|
||||||
|
duration: string;
|
||||||
|
remaining: string;
|
||||||
|
};
|
||||||
|
};
|
@ -21,6 +21,7 @@ import "./more-info-lock";
|
|||||||
import "./more-info-media_player";
|
import "./more-info-media_player";
|
||||||
import "./more-info-script";
|
import "./more-info-script";
|
||||||
import "./more-info-sun";
|
import "./more-info-sun";
|
||||||
|
import "./more-info-timer";
|
||||||
import "./more-info-updater";
|
import "./more-info-updater";
|
||||||
import "./more-info-vacuum";
|
import "./more-info-vacuum";
|
||||||
import "./more-info-water_heater";
|
import "./more-info-water_heater";
|
||||||
|
104
src/dialogs/more-info/controls/more-info-timer.ts
Normal file
104
src/dialogs/more-info/controls/more-info-timer.ts
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import {
|
||||||
|
LitElement,
|
||||||
|
html,
|
||||||
|
TemplateResult,
|
||||||
|
CSSResult,
|
||||||
|
css,
|
||||||
|
property,
|
||||||
|
PropertyValues,
|
||||||
|
customElement,
|
||||||
|
} from "lit-element";
|
||||||
|
import "@material/mwc-button";
|
||||||
|
|
||||||
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import { TimerEntity } from "../../../data/timer";
|
||||||
|
|
||||||
|
@customElement("more-info-timer")
|
||||||
|
class MoreInfoTimer extends LitElement {
|
||||||
|
@property() public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public stateObj?: TimerEntity;
|
||||||
|
|
||||||
|
protected render(): TemplateResult | void {
|
||||||
|
if (!this.hass || !this.stateObj) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-attributes
|
||||||
|
.stateObj=${this.stateObj}
|
||||||
|
.extraFilters=${"remaining"}
|
||||||
|
></ha-attributes>
|
||||||
|
<div class="actions">
|
||||||
|
${this.stateObj.state === "idle" || this.stateObj.state === "paused"
|
||||||
|
? html`
|
||||||
|
<mwc-button
|
||||||
|
.action="${"start"}"
|
||||||
|
@click="${this._handleActionClick}"
|
||||||
|
>
|
||||||
|
${this.hass!.localize("ui.card.timer.actions.start")}
|
||||||
|
</mwc-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
${this.stateObj.state === "active"
|
||||||
|
? html`
|
||||||
|
<mwc-button
|
||||||
|
.action="${"pause"}"
|
||||||
|
@click="${this._handleActionClick}"
|
||||||
|
>
|
||||||
|
${this.hass!.localize("ui.card.timer.actions.pause")}
|
||||||
|
</mwc-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
${this.stateObj.state === "active" || this.stateObj.state === "paused"
|
||||||
|
? html`
|
||||||
|
<mwc-button
|
||||||
|
.action="${"cancel"}"
|
||||||
|
@click="${this._handleActionClick}"
|
||||||
|
>
|
||||||
|
${this.hass!.localize("ui.card.timer.actions.cancel")}
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button
|
||||||
|
.action="${"finish"}"
|
||||||
|
@click="${this._handleActionClick}"
|
||||||
|
>
|
||||||
|
${this.hass!.localize("ui.card.timer.actions.finish")}
|
||||||
|
</mwc-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected updated(changedProps: PropertyValues) {
|
||||||
|
super.updated(changedProps);
|
||||||
|
if (!changedProps.has("stateObj") || !this.stateObj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleActionClick(e: MouseEvent): void {
|
||||||
|
const action = (e.currentTarget as any).action;
|
||||||
|
this.hass.callService("timer", action, {
|
||||||
|
entity_id: this.stateObj!.entity_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResult {
|
||||||
|
return css`
|
||||||
|
.actions {
|
||||||
|
margin: 0 8px;
|
||||||
|
padding-top: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"more-info-timer": MoreInfoTimer;
|
||||||
|
}
|
||||||
|
}
|
@ -446,6 +446,14 @@
|
|||||||
"script": {
|
"script": {
|
||||||
"execute": "Execute"
|
"execute": "Execute"
|
||||||
},
|
},
|
||||||
|
"timer": {
|
||||||
|
"actions": {
|
||||||
|
"start": "start",
|
||||||
|
"pause": "pause",
|
||||||
|
"cancel": "cancel",
|
||||||
|
"finish": "finish"
|
||||||
|
}
|
||||||
|
},
|
||||||
"vacuum": {
|
"vacuum": {
|
||||||
"actions": {
|
"actions": {
|
||||||
"resume_cleaning": "Resume cleaning",
|
"resume_cleaning": "Resume cleaning",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user