mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
parent
5edee41c5b
commit
e8ad975212
@ -1,7 +1,7 @@
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import { DataEntryFlowStep, DataEntryFlowProgress } from "./data_entry_flow";
|
import { DataEntryFlowStep, DataEntryFlowProgress } from "./data_entry_flow";
|
||||||
import { debounce } from "../common/util/debounce";
|
import { debounce } from "../common/util/debounce";
|
||||||
import { createCollection } from "home-assistant-js-websocket";
|
import { getCollection, Connection } from "home-assistant-js-websocket";
|
||||||
import { LocalizeFunc } from "../common/translations/localize";
|
import { LocalizeFunc } from "../common/translations/localize";
|
||||||
|
|
||||||
export const createConfigFlow = (hass: HomeAssistant, handler: string) =>
|
export const createConfigFlow = (hass: HomeAssistant, handler: string) =>
|
||||||
@ -29,9 +29,6 @@ export const handleConfigFlowStep = (
|
|||||||
export const deleteConfigFlow = (hass: HomeAssistant, flowId: string) =>
|
export const deleteConfigFlow = (hass: HomeAssistant, flowId: string) =>
|
||||||
hass.callApi("DELETE", `config/config_entries/flow/${flowId}`);
|
hass.callApi("DELETE", `config/config_entries/flow/${flowId}`);
|
||||||
|
|
||||||
export const getConfigFlowsInProgress = (hass: HomeAssistant) =>
|
|
||||||
hass.callApi<DataEntryFlowProgress[]>("GET", "config/config_entries/flow");
|
|
||||||
|
|
||||||
export const getConfigFlowHandlers = (hass: HomeAssistant) =>
|
export const getConfigFlowHandlers = (hass: HomeAssistant) =>
|
||||||
hass.callApi<string[]>("GET", "config/config_entries/flow_handlers");
|
hass.callApi<string[]>("GET", "config/config_entries/flow_handlers");
|
||||||
|
|
||||||
@ -53,17 +50,18 @@ const subscribeConfigFlowInProgressUpdates = (conn, store) =>
|
|||||||
"config_entry_discovered"
|
"config_entry_discovered"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const getConfigFlowInProgressCollection = (conn: Connection) =>
|
||||||
|
getCollection<DataEntryFlowProgress[]>(
|
||||||
|
conn,
|
||||||
|
"_configFlowProgress",
|
||||||
|
fetchConfigFlowInProgress,
|
||||||
|
subscribeConfigFlowInProgressUpdates
|
||||||
|
);
|
||||||
|
|
||||||
export const subscribeConfigFlowInProgress = (
|
export const subscribeConfigFlowInProgress = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
onChange: (flows: DataEntryFlowProgress[]) => void
|
onChange: (flows: DataEntryFlowProgress[]) => void
|
||||||
) =>
|
) => getConfigFlowInProgressCollection(hass.connection).subscribe(onChange);
|
||||||
createCollection<DataEntryFlowProgress[]>(
|
|
||||||
"_configFlowProgress",
|
|
||||||
fetchConfigFlowInProgress,
|
|
||||||
subscribeConfigFlowInProgressUpdates,
|
|
||||||
hass.connection,
|
|
||||||
onChange
|
|
||||||
);
|
|
||||||
|
|
||||||
export const localizeConfigFlowTitle = (
|
export const localizeConfigFlowTitle = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
|
@ -18,14 +18,14 @@ import { getConfigEntries, ConfigEntry } from "../data/config_entries";
|
|||||||
import { compare } from "../common/string/compare";
|
import { compare } from "../common/string/compare";
|
||||||
import "./integration-badge";
|
import "./integration-badge";
|
||||||
import { LocalizeFunc } from "../common/translations/localize";
|
import { LocalizeFunc } from "../common/translations/localize";
|
||||||
import { debounce } from "../common/util/debounce";
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { onboardIntegrationStep } from "../data/onboarding";
|
import { onboardIntegrationStep } from "../data/onboarding";
|
||||||
import { genClientId } from "home-assistant-js-websocket";
|
import { genClientId } from "home-assistant-js-websocket";
|
||||||
import { DataEntryFlowProgress } from "../data/data_entry_flow";
|
import { DataEntryFlowProgress } from "../data/data_entry_flow";
|
||||||
import {
|
import {
|
||||||
localizeConfigFlowTitle,
|
localizeConfigFlowTitle,
|
||||||
getConfigFlowsInProgress,
|
subscribeConfigFlowInProgress,
|
||||||
|
getConfigFlowInProgressCollection,
|
||||||
} from "../data/config_flow";
|
} from "../data/config_flow";
|
||||||
|
|
||||||
@customElement("onboarding-integrations")
|
@customElement("onboarding-integrations")
|
||||||
@ -38,20 +38,16 @@ class OnboardingIntegrations extends LitElement {
|
|||||||
|
|
||||||
public connectedCallback() {
|
public connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
this.hass.connection
|
this._unsubEvents = subscribeConfigFlowInProgress(this.hass, (flows) => {
|
||||||
.subscribeEvents(
|
this._discovered = flows;
|
||||||
debounce(() => this._loadData(), 500),
|
});
|
||||||
"config_entry_discovered"
|
|
||||||
)
|
|
||||||
.then((unsub) => {
|
|
||||||
this._unsubEvents = unsub;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback() {
|
public disconnectedCallback() {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
if (this._unsubEvents) {
|
if (this._unsubEvents) {
|
||||||
this._unsubEvents();
|
this._unsubEvents();
|
||||||
|
this._unsubEvents = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,30 +122,32 @@ class OnboardingIntegrations extends LitElement {
|
|||||||
protected firstUpdated(changedProps: PropertyValues) {
|
protected firstUpdated(changedProps: PropertyValues) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
loadConfigFlowDialog();
|
loadConfigFlowDialog();
|
||||||
this._loadData();
|
this._loadConfigEntries();
|
||||||
/* polyfill for paper-dropdown */
|
/* polyfill for paper-dropdown */
|
||||||
import(/* webpackChunkName: "polyfill-web-animations-next" */ "web-animations-js/web-animations-next-lite.min");
|
import(/* webpackChunkName: "polyfill-web-animations-next" */ "web-animations-js/web-animations-next-lite.min");
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createFlow() {
|
private _createFlow() {
|
||||||
showConfigFlowDialog(this, {
|
showConfigFlowDialog(this, {
|
||||||
dialogClosedCallback: () => this._loadData(),
|
dialogClosedCallback: () => {
|
||||||
|
this._loadConfigEntries();
|
||||||
|
getConfigFlowInProgressCollection(this.hass!.connection).refresh();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _continueFlow(ev) {
|
private _continueFlow(ev) {
|
||||||
showConfigFlowDialog(this, {
|
showConfigFlowDialog(this, {
|
||||||
continueFlowId: ev.currentTarget.flowId,
|
continueFlowId: ev.currentTarget.flowId,
|
||||||
dialogClosedCallback: () => this._loadData(),
|
dialogClosedCallback: () => {
|
||||||
|
this._loadConfigEntries();
|
||||||
|
getConfigFlowInProgressCollection(this.hass!.connection).refresh();
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _loadData() {
|
private async _loadConfigEntries() {
|
||||||
const [discovered, entries] = await Promise.all([
|
const entries = await getConfigEntries(this.hass!);
|
||||||
getConfigFlowsInProgress(this.hass!),
|
|
||||||
getConfigEntries(this.hass!),
|
|
||||||
]);
|
|
||||||
this._discovered = discovered;
|
|
||||||
// We filter out the config entry for the local weather.
|
// We filter out the config entry for the local weather.
|
||||||
// It is one that we create automatically and it will confuse the user
|
// It is one that we create automatically and it will confuse the user
|
||||||
// if it starts showing up during onboarding.
|
// if it starts showing up during onboarding.
|
||||||
|
@ -24,7 +24,10 @@ import {
|
|||||||
} from "../../../data/device_registry";
|
} from "../../../data/device_registry";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import { DataEntryFlowProgress } from "../../../data/data_entry_flow";
|
import { DataEntryFlowProgress } from "../../../data/data_entry_flow";
|
||||||
import { subscribeConfigFlowInProgress } from "../../../data/config_flow";
|
import {
|
||||||
|
subscribeConfigFlowInProgress,
|
||||||
|
getConfigFlowInProgressCollection,
|
||||||
|
} from "../../../data/config_flow";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
@ -79,7 +82,10 @@ class HaConfigIntegrations extends HassRouterPage {
|
|||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
super.firstUpdated(changedProps);
|
super.firstUpdated(changedProps);
|
||||||
this.addEventListener("hass-reload-entries", () => this._loadData());
|
this.addEventListener("hass-reload-entries", () => {
|
||||||
|
this._loadData();
|
||||||
|
getConfigFlowInProgressCollection(this.hass.connection).refresh();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user