Little cleanup (#11461)

This commit is contained in:
Bram Kragten 2022-01-27 18:56:50 +01:00 committed by GitHub
parent f04b844223
commit ba75c2e7af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ import { isComponentLoaded } from "../../../common/config/is_component_loaded";
import { subscribeOne } from "../../../common/util/subscribe-one";
import { subscribeAreaRegistry } from "../../../data/area_registry";
import { subscribeDeviceRegistry } from "../../../data/device_registry";
import { EnergyPreferences, getEnergyPreferences } from "../../../data/energy";
import { getEnergyPreferences } from "../../../data/energy";
import { subscribeEntityRegistry } from "../../../data/entity_registry";
import { generateDefaultViewConfig } from "../common/generate-lovelace-config";
import {
@ -39,30 +39,18 @@ export class OriginalStatesStrategy {
subscribeEntityRegistry(hass.connection, () => undefined);
}
let energyPromise: Promise<EnergyPreferences> | undefined;
if (isComponentLoaded(hass, "energy")) {
energyPromise = getEnergyPreferences(hass);
}
const [areaEntries, deviceEntries, entityEntries, localize] =
const [areaEntries, deviceEntries, entityEntries, localize, energyPrefs] =
await Promise.all([
subscribeOne(hass.connection, subscribeAreaRegistry),
subscribeOne(hass.connection, subscribeDeviceRegistry),
subscribeOne(hass.connection, subscribeEntityRegistry),
hass.loadBackendTranslation("title"),
isComponentLoaded(hass, "energy")
? // It raises if not configured, just swallow that.
getEnergyPreferences(hass).catch(() => undefined)
: undefined,
]);
let energyPrefs: EnergyPreferences | undefined;
if (energyPromise) {
try {
energyPrefs = await energyPromise;
} catch (_) {
// Nothing to do here
}
}
// User can override default view. If they didn't, we will add one
// that contains all entities.
const view = generateDefaultViewConfig(