diff --git a/src/data/config_flow.ts b/src/data/config_flow.ts index 0752659abc..d322f16ec9 100644 --- a/src/data/config_flow.ts +++ b/src/data/config_flow.ts @@ -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("POST", "config/config_entries/flow", { - handler, - show_advanced_options: Boolean(hass.userData?.showAdvanced), - }); + hass.callApi( + "POST", + "config/config_entries/flow", + { + handler, + show_advanced_options: Boolean(hass.userData?.showAdvanced), + }, + HEADERS + ); export const fetchConfigFlow = (hass: HomeAssistant, flowId: string) => hass.callApi( "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( "POST", `config/config_entries/flow/${flowId}`, - data + data, + HEADERS ); export const ignoreConfigFlow = (hass: HomeAssistant, flowId: string) => diff --git a/src/state/connection-mixin.ts b/src/state/connection-mixin.ts index 9862ed3bb3..895b6427db 100644 --- a/src/state/connection-mixin.ts +++ b/src/state/connection-mixin.ts @@ -85,8 +85,8 @@ export const connectionMixin = >( 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[2] diff --git a/src/types.ts b/src/types.ts index a16a66f31e..b375183b85 100644 --- a/src/types.ts +++ b/src/types.ts @@ -248,7 +248,8 @@ export interface HomeAssistant { callApi( method: "GET" | "POST" | "PUT" | "DELETE", path: string, - parameters?: Record + parameters?: Record, + headers?: Record ): Promise; fetchWithAuth(path: string, init?: Record): Promise; sendWS(msg: MessageBase): void; diff --git a/src/util/hass-call-api.ts b/src/util/hass-call-api.ts index cc85783cc7..adf8d9eff3 100644 --- a/src/util/hass-call-api.ts +++ b/src/util/hass-call-api.ts @@ -52,13 +52,14 @@ export default async function hassCallApi( auth: Auth, method: string, path: string, - parameters?: Record + parameters?: Record, + headers?: Record ) { const url = `${auth.data.hassUrl}/api/${path}`; const init: RequestInit = { method, - headers: {}, + headers: headers || {}, }; if (parameters) {