mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
Add frontend url (#7797)
This commit is contained in:
parent
7403405d12
commit
51332bc7e7
@ -16,16 +16,27 @@ export const DISCOVERY_SOURCES = [
|
||||
|
||||
export const ATTENTION_SOURCES = ["reauth"];
|
||||
|
||||
const HEADERS = {
|
||||
"HA-Frontend-Base": `${location.protocol}//${location.host}`,
|
||||
};
|
||||
|
||||
export const createConfigFlow = (hass: HomeAssistant, handler: string) =>
|
||||
hass.callApi<DataEntryFlowStep>("POST", "config/config_entries/flow", {
|
||||
hass.callApi<DataEntryFlowStep>(
|
||||
"POST",
|
||||
"config/config_entries/flow",
|
||||
{
|
||||
handler,
|
||||
show_advanced_options: Boolean(hass.userData?.showAdvanced),
|
||||
});
|
||||
},
|
||||
HEADERS
|
||||
);
|
||||
|
||||
export const fetchConfigFlow = (hass: HomeAssistant, flowId: string) =>
|
||||
hass.callApi<DataEntryFlowStep>(
|
||||
"GET",
|
||||
`config/config_entries/flow/${flowId}`
|
||||
`config/config_entries/flow/${flowId}`,
|
||||
undefined,
|
||||
HEADERS
|
||||
);
|
||||
|
||||
export const handleConfigFlowStep = (
|
||||
@ -36,7 +47,8 @@ export const handleConfigFlowStep = (
|
||||
hass.callApi<DataEntryFlowStep>(
|
||||
"POST",
|
||||
`config/config_entries/flow/${flowId}`,
|
||||
data
|
||||
data,
|
||||
HEADERS
|
||||
);
|
||||
|
||||
export const ignoreConfigFlow = (hass: HomeAssistant, flowId: string) =>
|
||||
|
@ -85,8 +85,8 @@ export const connectionMixin = <T extends Constructor<HassBaseEl>>(
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
callApi: async (method, path, parameters) =>
|
||||
hassCallApi(auth, method, path, parameters),
|
||||
callApi: async (method, path, parameters, headers) =>
|
||||
hassCallApi(auth, method, path, parameters, headers),
|
||||
fetchWithAuth: (
|
||||
path: string,
|
||||
init: Parameters<typeof fetchWithAuth>[2]
|
||||
|
@ -248,7 +248,8 @@ export interface HomeAssistant {
|
||||
callApi<T>(
|
||||
method: "GET" | "POST" | "PUT" | "DELETE",
|
||||
path: string,
|
||||
parameters?: Record<string, any>
|
||||
parameters?: Record<string, any>,
|
||||
headers?: Record<string, string>
|
||||
): Promise<T>;
|
||||
fetchWithAuth(path: string, init?: Record<string, any>): Promise<Response>;
|
||||
sendWS(msg: MessageBase): void;
|
||||
|
@ -52,13 +52,14 @@ export default async function hassCallApi<T>(
|
||||
auth: Auth,
|
||||
method: string,
|
||||
path: string,
|
||||
parameters?: Record<string, unknown>
|
||||
parameters?: Record<string, unknown>,
|
||||
headers?: Record<string, string>
|
||||
) {
|
||||
const url = `${auth.data.hassUrl}/api/${path}`;
|
||||
|
||||
const init: RequestInit = {
|
||||
method,
|
||||
headers: {},
|
||||
headers: headers || {},
|
||||
};
|
||||
|
||||
if (parameters) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user