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 & {
duration: string;
remaining: string;
restore: boolean;
};
};
@ -26,12 +27,14 @@ export interface Timer {
name: string;
icon?: string;
duration?: string | number | DurationDict;
restore?: boolean;
}
export interface TimerMutableParams {
name: string;
icon: string;
duration: string | number | DurationDict;
restore: boolean;
}
export const fetchTimer = (hass: HomeAssistant) =>

View File

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

View File

@ -21,16 +21,20 @@ class HaTimerForm extends LitElement {
@state() private _duration!: string | number | DurationDict;
@state() private _restore!: boolean;
set item(item: Timer) {
this._item = item;
if (item) {
this._name = item.name || "";
this._icon = item.icon || "";
this._duration = item.duration || "00:00:00";
this._restore = item.restore || false;
} else {
this._name = "";
this._icon = "";
this._duration = "00:00:00";
this._restore = false;
}
}
@ -79,6 +83,18 @@ class HaTimerForm extends LitElement {
"ui.dialogs.helper_settings.timer.duration"
)}
></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>
`;
}
@ -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 {
return [
haStyle,

View File

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