Ensure we pickup all the reloadable domains (#6861)

This commit is contained in:
J. Nick Koston 2020-09-08 13:56:45 -05:00 committed by GitHub
parent 4d0d1ed2a1
commit 869b7c85ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 28 deletions

View File

@ -0,0 +1,9 @@
import { HomeAssistant } from "../../types";
/** Return an array of domains with the service. */
export const componentsWithService = (
hass: HomeAssistant,
service: string
): Array<string> =>
hass &&
Object.keys(hass.services).filter((key) => service in hass.services[key]);

View File

@ -12,7 +12,7 @@ import {
property,
TemplateResult,
} from "lit-element";
import { isServiceLoaded } from "../../../common/config/is_service_loaded";
import { componentsWithService } from "../../../common/config/components_with_service";
import "../../../components/buttons/ha-call-service-button";
import "../../../components/ha-card";
import { checkCoreConfig } from "../../../data/core";
@ -23,8 +23,6 @@ import { HomeAssistant, Route } from "../../../types";
import "../ha-config-section";
import { configSections } from "../ha-panel-config";
const platformsWithReload = ["template"];
@customElement("ha-config-server-control")
export class HaConfigServerControl extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@ -51,13 +49,10 @@ export class HaConfigServerControl extends LitElement {
changedProperties.has("hass") &&
(!oldHass || oldHass.config.components !== this.hass.config.components)
) {
this._reloadableDomains = this.hass.config.components
.concat(platformsWithReload)
.filter(
(component) =>
!component.includes(".") &&
isServiceLoaded(this.hass, component, "reload")
);
this._reloadableDomains = componentsWithService(
this.hass,
"reload"
).sort();
}
}
@ -207,24 +202,23 @@ export class HaConfigServerControl extends LitElement {
)}
</ha-call-service-button>
</div>
${this._reloadableDomains.map((domain) =>
isServiceLoaded(this.hass, domain, "reload")
? html`<div class="card-actions">
<ha-call-service-button
.hass=${this.hass}
.domain=${domain}
service="reload"
>${this.hass.localize(
`ui.panel.config.server_control.section.reloading.${domain}`
) ||
this.hass.localize(
"ui.panel.config.server_control.section.reloading.reload",
"domain",
domainToName(this.hass.localize, domain)
)}
</ha-call-service-button>
</div>`
: ""
${this._reloadableDomains.map(
(domain) =>
html`<div class="card-actions">
<ha-call-service-button
.hass=${this.hass}
.domain=${domain}
service="reload"
>${this.hass.localize(
`ui.panel.config.server_control.section.reloading.${domain}`
) ||
this.hass.localize(
"ui.panel.config.server_control.section.reloading.reload",
"domain",
domainToName(this.hass.localize, domain)
)}
</ha-call-service-button>
</div>`
)}
</ha-card>
`