mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Update UI when service schema change (#9120)
This commit is contained in:
parent
a9c7a39a47
commit
9be4a00169
@ -1,5 +1,9 @@
|
||||
import { mdiHelpCircle } from "@mdi/js";
|
||||
import { HassService, HassServiceTarget } from "home-assistant-js-websocket";
|
||||
import {
|
||||
HassService,
|
||||
HassServices,
|
||||
HassServiceTarget,
|
||||
} from "home-assistant-js-websocket";
|
||||
import {
|
||||
css,
|
||||
CSSResult,
|
||||
@ -73,7 +77,10 @@ export class HaServiceControl extends LitElement {
|
||||
this._checkedKeys = new Set();
|
||||
}
|
||||
|
||||
const serviceData = this._getServiceInfo(this.value?.service);
|
||||
const serviceData = this._getServiceInfo(
|
||||
this.value?.service,
|
||||
this.hass.services
|
||||
);
|
||||
|
||||
if (
|
||||
serviceData &&
|
||||
@ -122,40 +129,45 @@ export class HaServiceControl extends LitElement {
|
||||
return ENTITY_COMPONENT_DOMAINS.includes(domain) ? [domain] : null;
|
||||
});
|
||||
|
||||
private _getServiceInfo = memoizeOne((service?: string):
|
||||
| ExtHassService
|
||||
| undefined => {
|
||||
if (!service) {
|
||||
return undefined;
|
||||
}
|
||||
const domain = computeDomain(service);
|
||||
const serviceName = computeObjectId(service);
|
||||
const serviceDomains = this.hass.services;
|
||||
if (!(domain in serviceDomains)) {
|
||||
return undefined;
|
||||
}
|
||||
if (!(serviceName in serviceDomains[domain])) {
|
||||
return undefined;
|
||||
}
|
||||
private _getServiceInfo = memoizeOne(
|
||||
(
|
||||
service?: string,
|
||||
serviceDomains?: HassServices
|
||||
): ExtHassService | undefined => {
|
||||
if (!service || !serviceDomains) {
|
||||
return undefined;
|
||||
}
|
||||
const domain = computeDomain(service);
|
||||
const serviceName = computeObjectId(service);
|
||||
if (!(domain in serviceDomains)) {
|
||||
return undefined;
|
||||
}
|
||||
if (!(serviceName in serviceDomains[domain])) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const fields = Object.entries(
|
||||
serviceDomains[domain][serviceName].fields
|
||||
).map(([key, value]) => ({
|
||||
key,
|
||||
...value,
|
||||
selector: value.selector as Selector | undefined,
|
||||
}));
|
||||
return {
|
||||
...serviceDomains[domain][serviceName],
|
||||
fields,
|
||||
hasSelector: fields.length
|
||||
? fields.filter((field) => field.selector).map((field) => field.key)
|
||||
: [],
|
||||
};
|
||||
});
|
||||
const fields = Object.entries(
|
||||
serviceDomains[domain][serviceName].fields
|
||||
).map(([key, value]) => ({
|
||||
key,
|
||||
...value,
|
||||
selector: value.selector as Selector | undefined,
|
||||
}));
|
||||
return {
|
||||
...serviceDomains[domain][serviceName],
|
||||
fields,
|
||||
hasSelector: fields.length
|
||||
? fields.filter((field) => field.selector).map((field) => field.key)
|
||||
: [],
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
protected render() {
|
||||
const serviceData = this._getServiceInfo(this._value?.service);
|
||||
const serviceData = this._getServiceInfo(
|
||||
this._value?.service,
|
||||
this.hass.services
|
||||
);
|
||||
|
||||
const shouldRenderServiceDataYaml =
|
||||
(serviceData?.fields.length && !serviceData.hasSelector.length) ||
|
||||
|
Loading…
x
Reference in New Issue
Block a user