feat(csms): add system settings management for OCPP 1.6J heartbeat interval
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { useDrizzle } from '@/lib/db.js'
|
||||
import dayjs from 'dayjs'
|
||||
import { chargePoint } from '@/db/schema.js'
|
||||
import { getOcpp16jSettings } from '@/lib/system-settings.js'
|
||||
import type {
|
||||
BootNotificationRequest,
|
||||
BootNotificationResponse,
|
||||
OcppConnectionContext,
|
||||
} from '../types.ts'
|
||||
|
||||
const DEFAULT_HEARTBEAT_INTERVAL = 60
|
||||
|
||||
export async function handleBootNotification(
|
||||
payload: BootNotificationRequest,
|
||||
ctx: OcppConnectionContext,
|
||||
): Promise<BootNotificationResponse> {
|
||||
const db = useDrizzle()
|
||||
const { heartbeatInterval } = await getOcpp16jSettings()
|
||||
|
||||
const [cp] = await db
|
||||
.insert(chargePoint)
|
||||
@@ -30,7 +30,7 @@ export async function handleBootNotification(
|
||||
meterSerialNumber: payload.meterSerialNumber ?? null,
|
||||
// New, unknown devices start as Pending — admin must manually accept them
|
||||
registrationStatus: 'Pending',
|
||||
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
|
||||
heartbeatInterval,
|
||||
lastBootNotificationAt: dayjs().toDate(),
|
||||
})
|
||||
.onConflictDoUpdate({
|
||||
@@ -45,7 +45,7 @@ export async function handleBootNotification(
|
||||
meterType: payload.meterType ?? null,
|
||||
meterSerialNumber: payload.meterSerialNumber ?? null,
|
||||
// Do NOT override registrationStatus — preserve whatever the admin set
|
||||
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
|
||||
heartbeatInterval,
|
||||
lastBootNotificationAt: dayjs().toDate(),
|
||||
updatedAt: dayjs().toDate(),
|
||||
},
|
||||
@@ -59,7 +59,7 @@ export async function handleBootNotification(
|
||||
|
||||
return {
|
||||
currentTime: dayjs().toISOString(),
|
||||
interval: DEFAULT_HEARTBEAT_INTERVAL,
|
||||
interval: heartbeatInterval,
|
||||
status,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user