Add support for new timer properties (#11940)

This commit is contained in:
Raman Gupta 2022-03-30 03:00:36 -04:00 committed by GitHub
parent e263b57296
commit ac670614b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View File

@ -12,6 +12,7 @@ export type TimerEntity = HassEntityBase & {
attributes: HassEntityAttributeBase & { attributes: HassEntityAttributeBase & {
duration: string; duration: string;
remaining: string; remaining: string;
restore: boolean;
}; };
}; };
@ -26,12 +27,14 @@ export interface Timer {
name: string; name: string;
icon?: string; icon?: string;
duration?: string | number | DurationDict; duration?: string | number | DurationDict;
restore?: boolean;
} }
export interface TimerMutableParams { export interface TimerMutableParams {
name: string; name: string;
icon: string; icon: string;
duration: string | number | DurationDict; duration: string | number | DurationDict;
restore: boolean;
} }
export const fetchTimer = (hass: HomeAssistant) => export const fetchTimer = (hass: HomeAssistant) =>

View File

@ -46,7 +46,7 @@ class MoreInfoTimer extends LitElement {
<ha-attributes <ha-attributes
.hass=${this.hass} .hass=${this.hass}
.stateObj=${this.stateObj} .stateObj=${this.stateObj}
extra-filters="remaining" extra-filters="remaining,restore"
></ha-attributes> ></ha-attributes>
`; `;
} }

View File

@ -21,16 +21,20 @@ class HaTimerForm extends LitElement {
@state() private _duration!: string | number | DurationDict; @state() private _duration!: string | number | DurationDict;
@state() private _restore!: boolean;
set item(item: Timer) { set item(item: Timer) {
this._item = item; this._item = item;
if (item) { if (item) {
this._name = item.name || ""; this._name = item.name || "";
this._icon = item.icon || ""; this._icon = item.icon || "";
this._duration = item.duration || "00:00:00"; this._duration = item.duration || "00:00:00";
this._restore = item.restore || false;
} else { } else {
this._name = ""; this._name = "";
this._icon = ""; this._icon = "";
this._duration = "00:00:00"; this._duration = "00:00:00";
this._restore = false;
} }
} }
@ -79,6 +83,18 @@ class HaTimerForm extends LitElement {
"ui.dialogs.helper_settings.timer.duration" "ui.dialogs.helper_settings.timer.duration"
)} )}
></ha-textfield> ></ha-textfield>
<ha-formfield
.label=${this.hass.localize(
"ui.dialogs.helper_settings.timer.restore"
)}
>
<ha-checkbox
.configValue=${"restore"}
.checked=${this._restore}
@click=${this._toggleRestore}
>
</ha-checkbox>
</ha-formfield>
</div> </div>
`; `;
} }
@ -104,6 +120,13 @@ class HaTimerForm extends LitElement {
}); });
} }
private _toggleRestore() {
this._restore = !this._restore;
fireEvent(this, "value-changed", {
value: { ...this._item, restore: this._restore },
});
}
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return [ return [
haStyle, haStyle,

View File

@ -900,7 +900,8 @@
"step": "Step size" "step": "Step size"
}, },
"timer": { "timer": {
"duration": "Duration" "duration": "Duration",
"restore": "Restore?"
} }
}, },
"options_flow": { "options_flow": {