Move restored entity warning up and use ha-alert (#13477)

This commit is contained in:
Paulus Schoutsen 2022-08-25 07:09:31 -04:00 committed by GitHub
parent 700af72303
commit 80e7993923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 43 deletions

View File

@ -3,6 +3,13 @@ title: Alerts
subtitle: An alert displays a short, important message in a way that attracts the user's attention without interrupting the user's task. subtitle: An alert displays a short, important message in a way that attracts the user's attention without interrupting the user's task.
--- ---
<style>
ha-alert {
display: block;
margin: 4px 0;
}
</style>
# Alert `<ha-alert>` # Alert `<ha-alert>`
The alert offers four severity levels that set a distinctive icon and color. The alert offers four severity levels that set a distinctive icon and color.

View File

@ -83,7 +83,6 @@ class HaAlert extends LitElement {
position: relative; position: relative;
padding: 8px; padding: 8px;
display: flex; display: flex;
margin: 4px 0;
} }
.issue-type.rtl { .issue-type.rtl {
flex-direction: row-reverse; flex-direction: row-reverse;

View File

@ -152,6 +152,7 @@ export class MoreInfoDialog extends LitElement {
` `
: ""} : ""}
</div> </div>
<div class="content" tabindex="-1" dialogInitialFocus> <div class="content" tabindex="-1" dialogInitialFocus>
${cache( ${cache(
this._currTab === "info" this._currTab === "info"

View File

@ -1,9 +1,12 @@
import { LitElement, html, css } from "lit"; import { LitElement, html, css } from "lit";
import { customElement, property } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeDomain } from "../../common/entity/compute_domain"; import { computeDomain } from "../../common/entity/compute_domain";
import { removeEntityRegistryEntry } from "../../data/entity_registry"; import { subscribeOne } from "../../common/util/subscribe-one";
import {
EntityRegistryEntry,
subscribeEntityRegistry,
} from "../../data/entity_registry";
import type { HomeAssistant } from "../../types"; import type { HomeAssistant } from "../../types";
import { showConfirmationDialog } from "../generic/show-dialog-box";
import { import {
computeShowHistoryComponent, computeShowHistoryComponent,
computeShowLogBookComponent, computeShowLogBookComponent,
@ -19,12 +22,24 @@ export class MoreInfoInfo extends LitElement {
@property() public entityId!: string; @property() public entityId!: string;
@state() private _entityEntry?: EntityRegistryEntry;
protected render() { protected render() {
const entityId = this.entityId; const entityId = this.entityId;
const stateObj = this.hass.states[entityId]; const stateObj = this.hass.states[entityId];
const domain = computeDomain(entityId); const domain = computeDomain(entityId);
return html` return html`
${stateObj.attributes.restored && this._entityEntry
? html`<ha-alert alert-type="warning">
${this.hass.localize(
"ui.dialogs.more_info_control.restored.no_longer_provided",
{
integration: this._entityEntry.platform,
}
)}
</ha-alert>`
: ""}
${DOMAINS_NO_INFO.includes(domain) ${DOMAINS_NO_INFO.includes(domain)
? "" ? ""
: html` : html`
@ -52,43 +67,18 @@ export class MoreInfoInfo extends LitElement {
.stateObj=${stateObj} .stateObj=${stateObj}
.hass=${this.hass} .hass=${this.hass}
></more-info-content> ></more-info-content>
${stateObj.attributes.restored
? html`
<p>
${this.hass.localize(
"ui.dialogs.more_info_control.restored.not_provided"
)}
</p>
<p>
${this.hass.localize(
"ui.dialogs.more_info_control.restored.remove_intro"
)}
</p>
<mwc-button class="warning" @click=${this._removeEntity}>
${this.hass.localize(
"ui.dialogs.more_info_control.restored.remove_action"
)}
</mwc-button>
`
: ""}
`; `;
} }
private _removeEntity() { protected firstUpdated(changedProps) {
const entityId = this.entityId!; super.firstUpdated(changedProps);
showConfirmationDialog(this, { subscribeOne(this.hass.connection, subscribeEntityRegistry).then(
title: this.hass.localize( (entries) => {
"ui.dialogs.more_info_control.restored.confirm_remove_title" this._entityEntry = entries.find(
), (entry) => entry.entity_id === this.entityId
text: this.hass.localize( );
"ui.dialogs.more_info_control.restored.confirm_remove_text" }
), );
confirmText: this.hass.localize("ui.common.remove"),
dismissText: this.hass.localize("ui.common.cancel"),
confirm: () => {
removeEntityRegistryEntry(this.hass, entityId);
},
});
} }
static get styles() { static get styles() {
@ -99,6 +89,13 @@ export class MoreInfoInfo extends LitElement {
display: block; display: block;
margin-bottom: 16px; margin-bottom: 16px;
} }
ha-alert {
display: block;
margin: calc(-1 * var(--dialog-content-padding, 24px))
calc(-1 * var(--dialog-content-padding, 24px)) 16px
calc(-1 * var(--dialog-content-padding, 24px));
}
`; `;
} }
} }

View File

@ -776,11 +776,7 @@
"activity": "Current activity" "activity": "Current activity"
}, },
"restored": { "restored": {
"not_provided": "This entity is currently unavailable and is an orphan to a removed, changed or dysfunctional integration or device.", "no_longer_provided": "This entity is no longer being provided by the {integration} integration. If the entity is no longer in use, delete it in settings."
"remove_intro": "If the entity is no longer in use, you can clean it up by removing it.",
"remove_action": "Remove entity",
"confirm_remove_title": "Remove entity?",
"confirm_remove_text": "Are you sure you want to remove this entity?"
}, },
"vacuum": { "vacuum": {
"status": "Status", "status": "Status",