mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 02:49:51 +00:00
* Update ts-eslint * Remove comments * Remove unused ts-ignore * Add undefined generic type instead of unknown * Remove unused undefined type * Fix type issues * Use undefined instead of void for subscribed return type
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import type { LocalizeFunc } from "../../../src/common/translations/localize";
|
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
|
import {
|
|
selectedDemoConfig,
|
|
selectedDemoConfigIndex,
|
|
setDemoConfig,
|
|
} from "../configs/demo-configs";
|
|
import "../custom-cards/cast-demo-row";
|
|
import "../custom-cards/ha-demo-card";
|
|
import { mapEntities } from "./entities";
|
|
|
|
export const mockLovelace = (
|
|
hass: MockHomeAssistant,
|
|
localizePromise: Promise<LocalizeFunc>
|
|
) => {
|
|
hass.mockWS("lovelace/config", ({ url_path }) => {
|
|
if (url_path === "map") {
|
|
hass.addEntities(mapEntities());
|
|
return {
|
|
strategy: {
|
|
type: "map",
|
|
},
|
|
};
|
|
}
|
|
return Promise.all([selectedDemoConfig, localizePromise]).then(
|
|
([config, localize]) => config.lovelace(localize)
|
|
);
|
|
});
|
|
|
|
hass.mockWS("lovelace/config/save", () => Promise.resolve());
|
|
hass.mockWS("lovelace/resources", () => Promise.resolve([]));
|
|
};
|
|
|
|
customElements.whenDefined("hui-root").then(() => {
|
|
// eslint-disable-next-line
|
|
const HUIRoot = customElements.get("hui-root")!;
|
|
|
|
const oldFirstUpdated = HUIRoot.prototype.firstUpdated;
|
|
|
|
HUIRoot.prototype.firstUpdated = function (changedProperties) {
|
|
oldFirstUpdated.call(this, changedProperties);
|
|
this.addEventListener("set-demo-config", async (ev) => {
|
|
const index = (ev as CustomEvent).detail.index;
|
|
try {
|
|
await setDemoConfig(this.hass, this.lovelace!, index);
|
|
} catch (_err: any) {
|
|
setDemoConfig(this.hass, this.lovelace!, selectedDemoConfigIndex);
|
|
alert("Failed to switch config :-(");
|
|
}
|
|
});
|
|
};
|
|
});
|