second version
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import axios, { type AxiosInstance } from 'axios'
|
||||
|
||||
import type { FullStatusResponse } from '../types/fullStatus'
|
||||
import type { Notification } from '../types/dashboard'
|
||||
import type { CurrentPlanResponse, RunPlanResponse } from '../types/plan'
|
||||
|
||||
const client: AxiosInstance = axios.create({
|
||||
@@ -34,6 +35,19 @@ export async function getSiteStatusFull(siteId: number): Promise<FullStatusRespo
|
||||
return data
|
||||
}
|
||||
|
||||
export type SiteNotificationsResponse = {
|
||||
notifications: Notification[]
|
||||
}
|
||||
|
||||
export async function getSiteNotifications(siteId: number): Promise<SiteNotificationsResponse> {
|
||||
const { data } = await client.get<SiteNotificationsResponse>(`/sites/${siteId}/notifications`, {
|
||||
timeout: 30_000,
|
||||
})
|
||||
return {
|
||||
notifications: Array.isArray(data?.notifications) ? data.notifications : [],
|
||||
}
|
||||
}
|
||||
|
||||
export type SetSiteModePayload = {
|
||||
mode: string
|
||||
notes: string | null
|
||||
@@ -61,6 +75,72 @@ export async function getCurrentPlan(siteId: number): Promise<CurrentPlanRespons
|
||||
return data
|
||||
}
|
||||
|
||||
/** GET /api/v1/sites/{id}/prices?date=YYYY-MM-DD */
|
||||
export type SiteEffectivePriceRowDto = {
|
||||
site_id: number
|
||||
interval_start: string
|
||||
interval_end?: string
|
||||
effective_buy_price_czk_kwh?: number | string | null
|
||||
effective_sell_price_czk_kwh?: number | string | null
|
||||
}
|
||||
|
||||
export async function getSitePrices(siteId: number, date: string): Promise<SiteEffectivePriceRowDto[]> {
|
||||
const { data } = await client.get<SiteEffectivePriceRowDto[]>(`/sites/${siteId}/prices`, {
|
||||
params: { date },
|
||||
timeout: 60_000,
|
||||
})
|
||||
return Array.isArray(data) ? data : []
|
||||
}
|
||||
|
||||
export type ForecastPvIntervalRow = {
|
||||
interval_start: string
|
||||
power_w?: number | string | null
|
||||
pv_array_id?: number
|
||||
}
|
||||
|
||||
export type ForecastPvDayResponse = {
|
||||
pv_a: ForecastPvIntervalRow[]
|
||||
pv_b: ForecastPvIntervalRow[]
|
||||
}
|
||||
|
||||
export async function getSiteForecastPv(siteId: number, date: string): Promise<ForecastPvDayResponse> {
|
||||
const { data } = await client.get<ForecastPvDayResponse>(`/sites/${siteId}/forecast/pv`, {
|
||||
params: { date },
|
||||
timeout: 60_000,
|
||||
})
|
||||
return {
|
||||
pv_a: Array.isArray(data?.pv_a) ? data.pv_a : [],
|
||||
pv_b: Array.isArray(data?.pv_b) ? data.pv_b : [],
|
||||
}
|
||||
}
|
||||
|
||||
export type NegPricePredictionDto = {
|
||||
predicted_date: string
|
||||
window_start_hour: number
|
||||
window_end_hour: number
|
||||
probability_pct: number
|
||||
expected_min_price: number | null
|
||||
reason: string
|
||||
}
|
||||
|
||||
export type NegativePredictionsResponseDto = {
|
||||
predictions: NegPricePredictionDto[]
|
||||
insufficient_history: boolean
|
||||
}
|
||||
|
||||
export async function getNegativePricePredictions(
|
||||
siteId: number,
|
||||
): Promise<NegativePredictionsResponseDto> {
|
||||
const { data } = await client.get<NegativePredictionsResponseDto>(
|
||||
`/sites/${siteId}/prices/negative-predictions`,
|
||||
{ timeout: 30_000 },
|
||||
)
|
||||
return {
|
||||
predictions: Array.isArray(data?.predictions) ? data.predictions : [],
|
||||
insufficient_history: Boolean(data?.insufficient_history),
|
||||
}
|
||||
}
|
||||
|
||||
export async function postRunPlan(
|
||||
siteId: number,
|
||||
planType: 'daily' | 'rolling',
|
||||
@@ -155,4 +235,52 @@ export async function patchEvSession(
|
||||
return data
|
||||
}
|
||||
|
||||
/** Živé hodnoty registrů Deye (GET …/control/registers). */
|
||||
export type DeyeRegistersLive = {
|
||||
reg108_charge_a: number
|
||||
reg109_discharge_a: number
|
||||
reg141_energy_mode: number
|
||||
reg142_limit_control: number
|
||||
reg143_export_limit_w: number
|
||||
reg178_peak_shaving_switch: number
|
||||
reg191_peak_shaving_w: number
|
||||
read_at: string
|
||||
}
|
||||
|
||||
export async function getDeyeRegisters(siteId: number): Promise<DeyeRegistersLive> {
|
||||
const { data } = await client.get<DeyeRegistersLive>(`/sites/${siteId}/control/registers`, {
|
||||
timeout: 15_000,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export type ModbusJournalCommandDto = {
|
||||
id: number
|
||||
register: number
|
||||
register_name: string | null
|
||||
value_to_write: number
|
||||
value_written: number | null
|
||||
value_verified: number | null
|
||||
status: string
|
||||
attempt_count: number
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export type ModbusJournalResponse = {
|
||||
commands: ModbusJournalCommandDto[]
|
||||
}
|
||||
|
||||
export async function getCommandJournal(
|
||||
siteId: number,
|
||||
limit = 50,
|
||||
): Promise<ModbusJournalResponse> {
|
||||
const { data } = await client.get<ModbusJournalResponse>(
|
||||
`/sites/${siteId}/control/journal`,
|
||||
{ params: { limit }, timeout: 15_000 },
|
||||
)
|
||||
return {
|
||||
commands: Array.isArray(data?.commands) ? data.commands : [],
|
||||
}
|
||||
}
|
||||
|
||||
export { client as backendClient }
|
||||
|
||||
Reference in New Issue
Block a user