x
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import axios, { type AxiosInstance } from 'axios'
|
||||
|
||||
import type { FullStatusResponse } from '../types/fullStatus'
|
||||
import type { CurrentPlanResponse, RunPlanResponse } from '../types/plan'
|
||||
|
||||
const client: AxiosInstance = axios.create({
|
||||
@@ -14,6 +15,25 @@ export async function getBackendHealth(): Promise<unknown> {
|
||||
return data
|
||||
}
|
||||
|
||||
export type HealthDetailedResponse = {
|
||||
db: 'ok' | 'error'
|
||||
scheduler: 'running' | 'stopped'
|
||||
telemetry_loop: 'running' | 'stopped'
|
||||
last_telemetry_age_sec: number
|
||||
last_plan_age_sec: number
|
||||
active_jobs: { id: string; next_run_time: string | null }[]
|
||||
}
|
||||
|
||||
export async function getBackendHealthDetailed(): Promise<HealthDetailedResponse> {
|
||||
const { data } = await client.get<HealthDetailedResponse>('/health/detailed')
|
||||
return data
|
||||
}
|
||||
|
||||
export async function getSiteStatusFull(siteId: number): Promise<FullStatusResponse> {
|
||||
const { data } = await client.get<FullStatusResponse>(`/sites/${siteId}/status/full`)
|
||||
return data
|
||||
}
|
||||
|
||||
export type SetSiteModePayload = {
|
||||
mode: string
|
||||
notes: string | null
|
||||
@@ -53,4 +73,86 @@ export async function postRunPlan(
|
||||
return data
|
||||
}
|
||||
|
||||
export type PricesImportResponse = {
|
||||
slots_imported: number
|
||||
date: string
|
||||
first_price_czk_kwh: number
|
||||
}
|
||||
|
||||
export async function postImportSitePrices(
|
||||
siteId: number,
|
||||
date?: string,
|
||||
): Promise<PricesImportResponse> {
|
||||
const { data } = await client.post<PricesImportResponse>(
|
||||
`/sites/${siteId}/prices/import`,
|
||||
null,
|
||||
{
|
||||
params: date ? { date } : undefined,
|
||||
timeout: 60_000,
|
||||
},
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
export type ForecastRunResponse = {
|
||||
intervals_saved: number
|
||||
pv_arrays: number
|
||||
}
|
||||
|
||||
export async function postRunForecast(siteId: number): Promise<ForecastRunResponse> {
|
||||
const { data } = await client.post<ForecastRunResponse>(
|
||||
`/sites/${siteId}/forecast/run`,
|
||||
null,
|
||||
{ timeout: 120_000 },
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
/** Aktivní EV session (GET .../ev/sessions/active) – join vozidlo + nabíječka */
|
||||
export type ActiveEvSessionRow = {
|
||||
id: number
|
||||
charger_id: number
|
||||
vehicle_id: number | null
|
||||
session_start: string
|
||||
energy_delivered_wh: number
|
||||
target_soc_pct: number | null
|
||||
target_deadline: string | null
|
||||
make: string | null
|
||||
model: string | null
|
||||
battery_capacity_kwh: number | null
|
||||
default_target_soc_pct: number | null
|
||||
default_deadline_hour: number | null
|
||||
charger_code: string
|
||||
charger_name: string | null
|
||||
}
|
||||
|
||||
export async function getActiveEvSessions(siteId: number): Promise<ActiveEvSessionRow[]> {
|
||||
const { data } = await client.get<ActiveEvSessionRow[]>(
|
||||
`/sites/${siteId}/ev/sessions/active`,
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
export type PatchEvSessionPayload = {
|
||||
target_soc_pct: number | null
|
||||
target_deadline: string | null
|
||||
}
|
||||
|
||||
export type PatchEvSessionResponse = {
|
||||
success: boolean
|
||||
session_id: number
|
||||
}
|
||||
|
||||
export async function patchEvSession(
|
||||
siteId: number,
|
||||
sessionId: number,
|
||||
payload: PatchEvSessionPayload,
|
||||
): Promise<PatchEvSessionResponse> {
|
||||
const { data } = await client.patch<PatchEvSessionResponse>(
|
||||
`/sites/${siteId}/ev/sessions/${sessionId}`,
|
||||
payload,
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
export { client as backendClient }
|
||||
|
||||
Reference in New Issue
Block a user