diff --git a/src/LoadUIElements.ts b/src/LoadUIElements.ts index f0a44669..b7ffd07c 100644 --- a/src/LoadUIElements.ts +++ b/src/LoadUIElements.ts @@ -11,6 +11,7 @@ import "./components/buttons/HacsButtonClearNew"; import "./components/buttons/HacsButtonMainAction"; import "./components/buttons/HacsButtonOpenPlugin"; import "./components/buttons/HacsButtonOpenRepository"; +import "./components/buttons/HacsButtonRestartHomeAssistant"; import "./components/buttons/HacsButtonUninstall"; import "./components/HacsBody"; import "./components/HacsLink"; diff --git a/src/components/buttons/HacsButtonRestartHomeAssistant.ts b/src/components/buttons/HacsButtonRestartHomeAssistant.ts new file mode 100644 index 00000000..d6ef1134 --- /dev/null +++ b/src/components/buttons/HacsButtonRestartHomeAssistant.ts @@ -0,0 +1,34 @@ +import { customElement, TemplateResult, html, property } from "lit-element"; +import swal from "sweetalert"; +import { HomeAssistant } from "custom-card-helpers"; + +import { HacsRepositoryButton } from "./HacsRepositoryButton"; +import { HACS } from "../../Hacs"; +import { localize } from "../../localize/localize"; + +@customElement("hacs-button-restart-home-assistant") +export class HacsButtonRestartHomeAssistant extends HacsRepositoryButton { + @property({ type: Object }) public hacs!: HACS; + @property({ type: Object }) public hass!: HomeAssistant; + + render(): TemplateResult | void { + if (!this.repository.installed) return html``; + + return html` + + ${this.hacs.localize("repository.restart_home_assistant")} + + `; + } + + RestartHomeAssistant() { + swal(localize("confirm.restart_home_assistant"), { + buttons: [localize("confirm.no"), localize("confirm.yes")] + }).then(value => { + if (value !== null) { + this.hass.callService("homeassistant", "restart"); + swal(localize("confirm.home_assistant_is_restarting")); + } + }); + } +} diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 2a6edd1d..a2d1a260 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -32,11 +32,13 @@ "delete": "Are you sure you want to delete '{item}'?", "exist": "{item} already exists", "generic": "Are you sure?", + "home_assistant_is_restarting": "Hold on, Home Assistant is now restarting.", "no_upgrades": "No upgrades pending", "no": "No", "ok": "OK", "overwrite": "Doing this will overwrite it.", "reload_data": "This reloads the data of all repositories HACS knows about, this will take some time to finish.", + "restart_home_assistant": "Are you sure you want to restart Home Assistant?", "uninstall": "Are you sure you want to uninstall '{item}'?", "upgrade_all": "This will upgrade all of these repositories, make sure that you have read the release notes for all of them before proceeding.", "yes": "Yes" @@ -67,6 +69,7 @@ "open_plugin": "Open plugin", "reinstall": "Reinstall", "repository": "Repository", + "restart_home_assistant": "Restart Home Assistant", "show_beta": "Show beta", "uninstall": "Uninstall", "update_information": "Update information", diff --git a/src/misc/RepositoryBannerNote.ts b/src/misc/RepositoryBannerNote.ts index 89e2a434..36bcd788 100644 --- a/src/misc/RepositoryBannerNote.ts +++ b/src/misc/RepositoryBannerNote.ts @@ -8,7 +8,13 @@ import { property } from "lit-element"; import { HacsStyle } from "../style/hacs-style"; -import { RepositoryData, Configuration, Status, LovelaceConfig } from "../types"; +import { + RepositoryData, + Configuration, + Status, + LovelaceConfig +} from "../types"; +import { HACS } from "../Hacs"; import { AddedToLovelace } from "./AddedToLovelace"; import { HomeAssistant } from "custom-card-helpers"; import { localize } from "../localize/localize"; @@ -17,6 +23,12 @@ interface CustomHACard extends HTMLElement { header?: string; } +interface RestartHomeAssistant extends HTMLElement { + hacs?: HACS; + hass?: HomeAssistant; + repository?: RepositoryData; +} + interface AddedToLovelace extends HTMLElement { hass?: HomeAssistant; configuration?: Configuration; @@ -26,6 +38,7 @@ interface AddedToLovelace extends HTMLElement { @customElement("hacs-repository-banner-note") export class RepositoryBannerNote extends LitElement { + @property({ type: Object }) public hacs!: HACS; @property({ type: Object }) public configuration: Configuration; @property({ type: Object }) public hass!: HomeAssistant; @property({ type: Object }) public lovelaceconfig: LovelaceConfig; @@ -81,6 +94,21 @@ export class RepositoryBannerNote extends LitElement { addedToLovelace.lovelaceconfig = this.lovelaceconfig; actions.appendChild(addedToLovelace); wrapper.appendChild(actions); + } else if ( + this.repository.status == "pending-restart" && + this.repository.category == "integration" + ) { + const actions = document.createElement("div"); + actions.className = "card-actions"; + + const restartHomeAssistant: RestartHomeAssistant = document.createElement( + "hacs-button-restart-home-assistant" + ); + restartHomeAssistant.hacs = this.hacs; + restartHomeAssistant.hass = this.hass; + restartHomeAssistant.repository = this.repository; + actions.appendChild(restartHomeAssistant); + wrapper.appendChild(actions); } return html` diff --git a/src/panels/repository.ts b/src/panels/repository.ts index d22da39b..4f48f98f 100644 --- a/src/panels/repository.ts +++ b/src/panels/repository.ts @@ -90,6 +90,7 @@ export class HacsRepository extends LitElement {