diff --git a/src/dialogs/more-info/ha-more-info-dialog.ts b/src/dialogs/more-info/ha-more-info-dialog.ts index da8a41b210..b31bd472af 100644 --- a/src/dialogs/more-info/ha-more-info-dialog.ts +++ b/src/dialogs/more-info/ha-more-info-dialog.ts @@ -1,4 +1,5 @@ import { + mdiBackupRestore, mdiChartBoxOutline, mdiClose, mdiCodeBraces, @@ -49,7 +50,10 @@ import type { EntityRegistryEntry, ExtEntityRegistryEntry, } from "../../data/entity/entity_registry"; -import { getExtendedEntityRegistryEntry } from "../../data/entity/entity_registry"; +import { + getExtendedEntityRegistryEntry, + updateEntityRegistryEntry, +} from "../../data/entity/entity_registry"; import { lightSupportsFavoriteColors } from "../../data/light"; import type { ItemType } from "../../data/search"; import { SearchableDomains } from "../../data/search"; @@ -75,6 +79,7 @@ import "./ha-more-info-history-and-logbook"; import "./ha-more-info-info"; import "./ha-more-info-settings"; import "./more-info-content"; +import { showConfirmationDialog } from "../generic/show-dialog-box"; export interface MoreInfoDialogParams { entityId: string | null; @@ -358,6 +363,9 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) { case "toggle_edit": this._toggleInfoEditMode(); break; + case "reset_favorites": + this._resetFavorites(); + break; case "related": this._goToRelated(); break; @@ -373,6 +381,36 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) { } } + private async _resetFavorites() { + if ( + !(await showConfirmationDialog(this, { + title: this.hass!.localize( + "ui.dialogs.more_info_control.light.reset_favorites" + ), + text: this.hass!.localize( + "ui.dialogs.more_info_control.light.reset_favorites_text" + ), + dismissText: this.hass!.localize("ui.common.cancel"), + confirmText: this.hass!.localize("ui.common.reset"), + destructive: true, + })) + ) { + return; + } + + const result = await updateEntityRegistryEntry( + this.hass, + this._entry!.entity_id, + { + options_domain: "light", + options: { + favorite_colors: undefined, + }, + } + ); + this._entry = result.entity_entry; + } + private _showDetails(): void { import("./ha-more-info-details"); this._childView = { @@ -592,6 +630,19 @@ export class MoreInfoDialog extends ScrollableFadeMixin(LitElement) { `ui.dialogs.more_info_control.${domain}.edit_mode` )} + + + ${this.hass.localize( + `ui.dialogs.more_info_control.light.reset_favorites` + )} + ` : nothing} diff --git a/src/translations/en.json b/src/translations/en.json index 2e09ca283f..d93a5791cc 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1612,6 +1612,8 @@ }, "light": { "edit_mode": "Edit favorite colors", + "reset_favorites": "Reset favorite colors", + "reset_favorites_text": "Do you want to reset all favorite colors for this light back to default?", "toggle": "Toggle", "color": "Color", "color_temp": "Temperature",