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