mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add UI control to reload a config entry (integration) (#6656)
* Add UI control to reload an integration * Refactor to move reload above delete and check supports_unload * Avoid index switch * Update src/panels/config/integrations/ha-integration-card.ts
This commit is contained in:
parent
9b7d17433c
commit
e10c8faa47
@ -8,6 +8,7 @@ export interface ConfigEntry {
|
|||||||
state: string;
|
state: string;
|
||||||
connection_class: string;
|
connection_class: string;
|
||||||
supports_options: boolean;
|
supports_options: boolean;
|
||||||
|
supports_unload: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfigEntryMutableParams {
|
export interface ConfigEntryMutableParams {
|
||||||
@ -37,6 +38,11 @@ export const deleteConfigEntry = (hass: HomeAssistant, configEntryId: string) =>
|
|||||||
require_restart: boolean;
|
require_restart: boolean;
|
||||||
}>("DELETE", `config/config_entries/entry/${configEntryId}`);
|
}>("DELETE", `config/config_entries/entry/${configEntryId}`);
|
||||||
|
|
||||||
|
export const reloadConfigEntry = (hass: HomeAssistant, configEntryId: string) =>
|
||||||
|
hass.callApi<{
|
||||||
|
require_restart: boolean;
|
||||||
|
}>("POST", `config/config_entries/entry/${configEntryId}/reload`);
|
||||||
|
|
||||||
export const getConfigEntrySystemOptions = (
|
export const getConfigEntrySystemOptions = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
configEntryId: string
|
configEntryId: string
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
updateConfigEntry,
|
updateConfigEntry,
|
||||||
deleteConfigEntry,
|
deleteConfigEntry,
|
||||||
|
reloadConfigEntry,
|
||||||
} from "../../../data/config_entries";
|
} from "../../../data/config_entries";
|
||||||
import { EntityRegistryEntry } from "../../../data/entity_registry";
|
import { EntityRegistryEntry } from "../../../data/entity_registry";
|
||||||
import { DeviceRegistryEntry } from "../../../data/device_registry";
|
import { DeviceRegistryEntry } from "../../../data/device_registry";
|
||||||
@ -28,7 +29,8 @@ import { haStyle } from "../../../resources/styles";
|
|||||||
import "../../../components/ha-icon-next";
|
import "../../../components/ha-icon-next";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { mdiDotsVertical, mdiOpenInNew } from "@mdi/js";
|
import { mdiDotsVertical, mdiOpenInNew } from "@mdi/js";
|
||||||
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
import type { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
|
||||||
|
import { shouldHandleRequestSelectedEvent } from "../../../common/mwc/handle-request-selected-event";
|
||||||
|
|
||||||
export interface ConfigEntryUpdatedEvent {
|
export interface ConfigEntryUpdatedEvent {
|
||||||
entry: ConfigEntry;
|
entry: ConfigEntry;
|
||||||
@ -228,7 +230,7 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
<ha-button-menu corner="BOTTOM_START" @action=${this._handleAction}>
|
<ha-button-menu corner="BOTTOM_START">
|
||||||
<mwc-icon-button
|
<mwc-icon-button
|
||||||
.title=${this.hass.localize("ui.common.menu")}
|
.title=${this.hass.localize("ui.common.menu")}
|
||||||
.label=${this.hass.localize("ui.common.overflow_menu")}
|
.label=${this.hass.localize("ui.common.overflow_menu")}
|
||||||
@ -236,7 +238,7 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon path=${mdiDotsVertical}></ha-svg-icon>
|
<ha-svg-icon path=${mdiDotsVertical}></ha-svg-icon>
|
||||||
</mwc-icon-button>
|
</mwc-icon-button>
|
||||||
<mwc-list-item>
|
<mwc-list-item @request-selected="${this._handleSystemOptions}">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.integrations.config_entry.system_options"
|
"ui.panel.config.integrations.config_entry.system_options"
|
||||||
)}
|
)}
|
||||||
@ -259,7 +261,17 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
</a>
|
</a>
|
||||||
`}
|
`}
|
||||||
<mwc-list-item class="warning">
|
${item.state === "loaded" && item.supports_unload
|
||||||
|
? html`<mwc-list-item @request-selected="${this._handleReload}">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.integrations.config_entry.reload"
|
||||||
|
)}
|
||||||
|
</mwc-list-item>`
|
||||||
|
: ""}
|
||||||
|
<mwc-list-item
|
||||||
|
class="warning"
|
||||||
|
@request-selected="${this._handleDelete}"
|
||||||
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.integrations.config_entry.delete"
|
"ui.panel.config.integrations.config_entry.delete"
|
||||||
)}
|
)}
|
||||||
@ -309,17 +321,31 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
showOptionsFlowDialog(this, ev.target.closest("ha-card").configEntry);
|
showOptionsFlowDialog(this, ev.target.closest("ha-card").configEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleAction(ev: CustomEvent<ActionDetail>) {
|
private _handleReload(ev: CustomEvent<RequestSelectedDetail>): void {
|
||||||
const configEntry = ((ev.target as HTMLElement).closest("ha-card") as any)
|
if (!shouldHandleRequestSelectedEvent(ev)) {
|
||||||
.configEntry;
|
return;
|
||||||
switch (ev.detail.index) {
|
|
||||||
case 0:
|
|
||||||
this._showSystemOptions(configEntry);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
this._removeIntegration(configEntry);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
this._reloadIntegration(
|
||||||
|
((ev.target as HTMLElement).closest("ha-card") as any).configEntry
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleDelete(ev: CustomEvent<RequestSelectedDetail>): void {
|
||||||
|
if (!shouldHandleRequestSelectedEvent(ev)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._removeIntegration(
|
||||||
|
((ev.target as HTMLElement).closest("ha-card") as any).configEntry
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _handleSystemOptions(ev: CustomEvent<RequestSelectedDetail>): void {
|
||||||
|
if (!shouldHandleRequestSelectedEvent(ev)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._showSystemOptions(
|
||||||
|
((ev.target as HTMLElement).closest("ha-card") as any).configEntry
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showSystemOptions(configEntry: ConfigEntry) {
|
private _showSystemOptions(configEntry: ConfigEntry) {
|
||||||
@ -353,6 +379,21 @@ export class HaIntegrationCard extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _reloadIntegration(configEntry: ConfigEntry) {
|
||||||
|
const entryId = configEntry.entry_id;
|
||||||
|
|
||||||
|
reloadConfigEntry(this.hass, entryId).then((result) => {
|
||||||
|
const locale_key = result.require_restart
|
||||||
|
? "reload_restart_confirm"
|
||||||
|
: "reload_confirm";
|
||||||
|
showAlertDialog(this, {
|
||||||
|
text: this.hass.localize(
|
||||||
|
`ui.panel.config.integrations.config_entry.${locale_key}`
|
||||||
|
),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async _editEntryName(ev) {
|
private async _editEntryName(ev) {
|
||||||
const configEntry = ev.target.closest("ha-card").configEntry;
|
const configEntry = ev.target.closest("ha-card").configEntry;
|
||||||
const newName = await showPromptDialog(this, {
|
const newName = await showPromptDialog(this, {
|
||||||
|
@ -1606,7 +1606,10 @@
|
|||||||
"documentation": "Documentation",
|
"documentation": "Documentation",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"delete_confirm": "Are you sure you want to delete this integration?",
|
"delete_confirm": "Are you sure you want to delete this integration?",
|
||||||
|
"reload": "Reload",
|
||||||
"restart_confirm": "Restart Home Assistant to finish removing this integration",
|
"restart_confirm": "Restart Home Assistant to finish removing this integration",
|
||||||
|
"reload_confirm": "The integration was reloaded",
|
||||||
|
"reload_restart_confirm": "Restart Home Assistant to finish reloading this integration",
|
||||||
"manuf": "by {manufacturer}",
|
"manuf": "by {manufacturer}",
|
||||||
"hub": "Connected via",
|
"hub": "Connected via",
|
||||||
"firmware": "Firmware: {version}",
|
"firmware": "Firmware: {version}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user