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