Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/dialogs/more-info/more-info-controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@polymer/app-layout/app-toolbar/app-toolbar";
import "@polymer/paper-dialog-scrollable/paper-dialog-scrollable";
import "@polymer/paper-icon-button/paper-icon-button";
import "@material/mwc-button";
import { html } from "@polymer/polymer/lib/utils/html-tag";
import { PolymerElement } from "@polymer/polymer/polymer-element";

Expand All @@ -18,6 +19,8 @@ import { DOMAINS_MORE_INFO_NO_HISTORY } from "../../common/const";
import { EventsMixin } from "../../mixins/events-mixin";
import LocalizeMixin from "../../mixins/localize-mixin";
import { computeRTL } from "../../common/util/compute_rtl";
import { removeEntityRegistryEntry } from "../../data/entity_registry";
import { showConfirmationDialog } from "../confirmation/show-dialog-confirmation";

const DOMAINS_NO_INFO = ["camera", "configurator", "history_graph"];
/*
Expand Down Expand Up @@ -117,6 +120,15 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
state-obj="[[stateObj]]"
hass="[[hass]]"
></more-info-content>
<template
is="dom-if"
if="[[_computeShowRestored(stateObj)]]"
restamp=""
>
[[localize('ui.dialogs.more_info_control.restored.not_provided')]] <br />
[[localize('ui.dialogs.more_info_control.restored.remove_intro')]] <br />
<mwc-button on-click="_removeEntity">[[localize('ui.dialogs.more_info_control.restored.remove_action')]]</mwc-buttom>
</template>
</paper-dialog-scrollable>
`;
}
Expand Down Expand Up @@ -172,6 +184,10 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
return !stateObj || !DOMAINS_NO_INFO.includes(computeStateDomain(stateObj));
}

_computeShowRestored(stateObj) {
return !stateObj || stateObj.attributes.restored;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This screen won't show without State obj

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but it is undefined at first render...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but then guard it, because now you're implying it's restored entity if state object is not available.

Suggested change
return !stateObj || stateObj.attributes.restored;
return stateObj && stateObj.attributes.restored;

}

_computeShowHistoryComponent(hass, stateObj) {
return (
hass &&
Expand Down Expand Up @@ -202,6 +218,21 @@ class MoreInfoControls extends LocalizeMixin(EventsMixin(PolymerElement)) {
}
}

_removeEntity() {
showConfirmationDialog(this, {
title: this.localize(
"ui.dialogs.more_info_control.restored.confirm_remove_title"
),
text: this.localize(
"ui.dialogs.more_info_control.restored.confirm_remove_text"
),
confirmBtnText: this.localize("ui.common.yes"),
cancelBtnText: this.localize("ui.common.no"),
confirm: () =>
removeEntityRegistryEntry(this.hass, this.stateObj.entity_id),
});
}

_gotoSettings() {
this.fire("more-info-page", { page: "settings" });
}
Expand Down
7 changes: 7 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@
},
"updater": {
"title": "Update Instructions"
},
"restored": {
"not_provided": "This entity was previously made available via an integration. It is not currently being provided.",
"remove_intro": "If it is no longer used, you can remove it from the entity registry by clicking the button below.",
"remove_action": "Remove entity",
"confirm_remove_title": "Remove entity?",
"confirm_remove_text": "Are you sure you want to remove this entity?"
}
},
"more_info_settings": {
Expand Down
1 change: 1 addition & 0 deletions src/util/hass-attributes-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ hassAttributeUtil.LOGIC_STATE_ATTRIBUTES = hassAttributeUtil.LOGIC_STATE_ATTRIBU
homebridge_name: { type: "string" },
supported_features: undefined,
attribution: undefined,
restored: undefined,
custom_ui_more_info: { type: "string" },
custom_ui_state_card: { type: "string" },
device_class: {
Expand Down