Skip to content

Commit

Permalink
Adds restart homeassistant button after integration installation/upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 28, 2019
1 parent fc1a5a2 commit 596c53d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/LoadUIElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
34 changes: 34 additions & 0 deletions src/components/buttons/HacsButtonRestartHomeAssistant.ts
Original file line number Diff line number Diff line change
@@ -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`
<mwc-button @click=${this.RestartHomeAssistant}>
${this.hacs.localize("repository.restart_home_assistant")}
</mwc-button>
`;
}

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"));
}
});
}
}
3 changes: 3 additions & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 29 additions & 1 deletion src/misc/RepositoryBannerNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions src/panels/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class HacsRepository extends LitElement {
</div>
<hacs-repository-banner-note
.hacs=${this.hacs}
.hass=${this.hass}
.status=${this.status}
.repository=${this.repo}
Expand Down

0 comments on commit 596c53d

Please sign in to comment.