mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Consistently use isComponentLoaded() helper (#7995)
This commit is contained in:
parent
0d281f8437
commit
d02a2e8c2e
@ -12,6 +12,7 @@ import {
|
|||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
|
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
||||||
import {
|
import {
|
||||||
CameraEntity,
|
CameraEntity,
|
||||||
CAMERA_SUPPORT_STREAM,
|
CAMERA_SUPPORT_STREAM,
|
||||||
@ -86,7 +87,7 @@ class HaCameraStream extends LitElement {
|
|||||||
private get _shouldRenderMJPEG() {
|
private get _shouldRenderMJPEG() {
|
||||||
return (
|
return (
|
||||||
this._forceMJPEG === this.stateObj!.entity_id ||
|
this._forceMJPEG === this.stateObj!.entity_id ||
|
||||||
!this.hass!.config.components.includes("stream") ||
|
!isComponentLoaded(this.hass!, "stream") ||
|
||||||
!supportsFeature(this.stateObj!, CAMERA_SUPPORT_STREAM)
|
!supportsFeature(this.stateObj!, CAMERA_SUPPORT_STREAM)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { supportsFeature } from "../../../common/entity/supports-feature";
|
import { supportsFeature } from "../../../common/entity/supports-feature";
|
||||||
|
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||||
import "../../../components/ha-camera-stream";
|
import "../../../components/ha-camera-stream";
|
||||||
import {
|
import {
|
||||||
CameraPreferences,
|
CameraPreferences,
|
||||||
@ -81,7 +82,7 @@ class MoreInfoCamera extends LitElement {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
curEntityId &&
|
curEntityId &&
|
||||||
this.hass!.config.components.includes("stream") &&
|
isComponentLoaded(this.hass!, "stream") &&
|
||||||
supportsFeature(this.stateObj!, CAMERA_SUPPORT_STREAM)
|
supportsFeature(this.stateObj!, CAMERA_SUPPORT_STREAM)
|
||||||
) {
|
) {
|
||||||
// Fetch in background while we set up the video.
|
// Fetch in background while we set up the video.
|
||||||
|
@ -14,6 +14,7 @@ import "../../../../components/ha-card";
|
|||||||
import "../../../../components/ha-circular-progress";
|
import "../../../../components/ha-circular-progress";
|
||||||
import "../../../../components/ha-settings-row";
|
import "../../../../components/ha-settings-row";
|
||||||
import "../../../../components/ha-switch";
|
import "../../../../components/ha-switch";
|
||||||
|
import { isComponentLoaded } from "../../../../common/config/is_component_loaded";
|
||||||
import {
|
import {
|
||||||
CloudStatusLoggedIn,
|
CloudStatusLoggedIn,
|
||||||
CloudWebhook,
|
CloudWebhook,
|
||||||
@ -202,7 +203,7 @@ export class CloudWebhooks extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchData() {
|
private async _fetchData() {
|
||||||
this._localHooks = this.hass!.config.components.includes("webhook")
|
this._localHooks = isComponentLoaded(this.hass!, "webhook")
|
||||||
? await fetchWebhooks(this.hass!)
|
? await fetchWebhooks(this.hass!)
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { formatDateTime } from "../../../common/datetime/format_date_time";
|
import { formatDateTime } from "../../../common/datetime/format_date_time";
|
||||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||||
|
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||||
import "../../../components/ha-button-menu";
|
import "../../../components/ha-button-menu";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
@ -179,7 +180,7 @@ class SystemHealthCard extends LitElement {
|
|||||||
|
|
||||||
this.hass!.loadBackendTranslation("system_health");
|
this.hass!.loadBackendTranslation("system_health");
|
||||||
|
|
||||||
if (!this.hass!.config.components.includes("system_health")) {
|
if (!isComponentLoaded(this.hass!, "system_health")) {
|
||||||
this._info = {
|
this._info = {
|
||||||
system_health: {
|
system_health: {
|
||||||
info: {
|
info: {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
HassConfig,
|
|
||||||
HassEntities,
|
HassEntities,
|
||||||
HassEntity,
|
HassEntity,
|
||||||
STATE_NOT_RUNNING,
|
STATE_NOT_RUNNING,
|
||||||
@ -14,6 +13,7 @@ import { splitByGroups } from "../../../common/entity/split_by_groups";
|
|||||||
import { compare } from "../../../common/string/compare";
|
import { compare } from "../../../common/string/compare";
|
||||||
import { LocalizeFunc } from "../../../common/translations/localize";
|
import { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
import { subscribeOne } from "../../../common/util/subscribe-one";
|
import { subscribeOne } from "../../../common/util/subscribe-one";
|
||||||
|
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||||
import {
|
import {
|
||||||
AreaRegistryEntry,
|
AreaRegistryEntry,
|
||||||
subscribeAreaRegistry,
|
subscribeAreaRegistry,
|
||||||
@ -382,16 +382,16 @@ export const generateDefaultViewConfig = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const generateLovelaceConfigFromData = async (
|
export const generateLovelaceConfigFromData = async (
|
||||||
config: HassConfig,
|
hass: HomeAssistant,
|
||||||
areaEntries: AreaRegistryEntry[],
|
areaEntries: AreaRegistryEntry[],
|
||||||
deviceEntries: DeviceRegistryEntry[],
|
deviceEntries: DeviceRegistryEntry[],
|
||||||
entityEntries: EntityRegistryEntry[],
|
entityEntries: EntityRegistryEntry[],
|
||||||
entities: HassEntities,
|
entities: HassEntities,
|
||||||
localize: LocalizeFunc
|
localize: LocalizeFunc
|
||||||
): Promise<LovelaceConfig> => {
|
): Promise<LovelaceConfig> => {
|
||||||
if (config.safe_mode) {
|
if (hass.config.safe_mode) {
|
||||||
return {
|
return {
|
||||||
title: config.location_name,
|
title: hass.config.location_name,
|
||||||
views: [
|
views: [
|
||||||
{
|
{
|
||||||
cards: [{ type: "safe-mode" }],
|
cards: [{ type: "safe-mode" }],
|
||||||
@ -421,7 +421,7 @@ export const generateLovelaceConfigFromData = async (
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
let title = config.location_name;
|
let title = hass.config.location_name;
|
||||||
|
|
||||||
// User can override default view. If they didn't, we will add one
|
// User can override default view. If they didn't, we will add one
|
||||||
// that contains all entities.
|
// that contains all entities.
|
||||||
@ -440,7 +440,7 @@ export const generateLovelaceConfigFromData = async (
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Add map of geo locations to default view if loaded
|
// Add map of geo locations to default view if loaded
|
||||||
if (config.components.includes("geo_location")) {
|
if (isComponentLoaded(hass, "geo_location")) {
|
||||||
if (views[0] && views[0].cards) {
|
if (views[0] && views[0].cards) {
|
||||||
views[0].cards.push({
|
views[0].cards.push({
|
||||||
type: "map",
|
type: "map",
|
||||||
@ -510,7 +510,7 @@ export const generateLovelaceConfigFromHass = async (
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return generateLovelaceConfigFromData(
|
return generateLovelaceConfigFromData(
|
||||||
hass.config,
|
hass,
|
||||||
areaEntries,
|
areaEntries,
|
||||||
deviceEntries,
|
deviceEntries,
|
||||||
entityEntries,
|
entityEntries,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user