This commit is contained in:
Kevin L'Hereec committed 2026-06-08 16:35:33 +02:00
1 parent 08c620ee68
commit dae82eeff2
5 files changed
+114 -11

No files matched your search

@@ -131,7 +131,20 @@ export class ConfigurationEvaluationState {
const response = await context.services.deviceAction.getParameterValues(
context.device,
leaves,
() => Promise.resolve('')
async (result) => {
if (result.status === 'success' && result.data) {
const list = result.data?.ParameterList?.ParameterValueStruct
if (Array.isArray(list) && list.length > 0) {
const normalized = list.map((pv: any) => ({
...pv,
Name: typeof pv?.Name === 'string' ? pv.Name : pv?.Name?._ || pv?.Name,
}))
context.device.updateFromValues(normalized)
logger.debug({ identifier: context.device.identifier, count: normalized.length }, '[ConfigEval] Inventory GPV values saved to device')
}
}
return ''
}
)
return { response }
}
+12 -1
View File
@@ -343,8 +343,13 @@ export class StateMachineManager extends EventEmitter {
return ''
}
// If state machine produced a response, send it
// If state machine produced a response, send it.
// Also track the task ID that was just created (by addTask inside a state handler)
// so that handleCWMPResponse can execute its callback when the CPE replies.
if (response && response !== '') {
if (!machineInstance.lastTaskId) {
machineInstance.lastTaskId = this.taskQueue.getLastCreatedTaskId(machineInstance.deviceId)
}
return response
}
@@ -409,6 +414,12 @@ export class StateMachineManager extends EventEmitter {
return ''
}
// If the state machine produced a new request (e.g. next inventory GPN, next SPV),
// track the task ID so the next handleCWMPResponse can fire its callback.
if (response && response !== '' && !machineInstance.lastTaskId) {
machineInstance.lastTaskId = this.taskQueue.getLastCreatedTaskId(machineInstance.deviceId)
}
return response
} catch (error) {
logger.error(`Error handling CWMP response: ${error}`)
+20 -7
View File
@@ -86,6 +86,8 @@ export class CWMPTaskQueue extends EventEmitter {
private tasks: Map<string, CWMPTask> = new Map()
private deviceQueues: Map<string, string[]> = new Map()
private taskCallbacks: Map<string, (result: TaskResult) => Promise<string>> = new Map()
/** Tracks the most recently created task per device (set by addTask) */
private lastCreatedTaskIdByDevice: Map<string, string> = new Map()
/**
* Adds a task with callback (legacy-compatible API used by DeviceActionExecutor)
@@ -108,6 +110,9 @@ export class CWMPTaskQueue extends EventEmitter {
cwmpTask.status = TaskStatus.SENT
}
// Track the most recent task created for this device so callers can retrieve its ID
this.lastCreatedTaskIdByDevice.set(JSON.stringify(deviceId), cwmpTask.id)
// Generate CWMP envelope
const builder = CWMPTaskQueue.task_map[taskType]
if (typeof builder !== 'function') {
@@ -217,20 +222,28 @@ export class CWMPTaskQueue extends EventEmitter {
return ''
}
/**
* Returns the ID of the most recently created task for a device (via addTask).
* Used by the state machine manager to correlate responses with in-flight tasks
* that were created directly by state handlers (not served from the external queue).
*/
getLastCreatedTaskId(deviceId: DeviceId): string | undefined {
return this.lastCreatedTaskIdByDevice.get(JSON.stringify(deviceId))
}
clearPendingTasksForDevice(deviceId: DeviceId): void {
const deviceKey = JSON.stringify(deviceId)
const queue = this.deviceQueues.get(deviceKey) || []
const keep: string[] = []
// Clear ALL tasks (PENDING and SENT) — after session completion, no task
// from the previous session should bleed into the next one. Tasks that were
// already SENT (created by state-machine states via addTask()) are ghost
// entries that would otherwise be served to the next session.
for (const taskId of queue) {
const t = this.tasks.get(taskId)
if (t && t.status === TaskStatus.SENT) {
keep.push(taskId)
continue
}
this.tasks.delete(taskId)
this.taskCallbacks.delete(taskId)
}
this.deviceQueues.set(deviceKey, keep)
this.deviceQueues.set(deviceKey, [])
this.lastCreatedTaskIdByDevice.delete(deviceKey)
}
private generateTaskId(deviceId: DeviceId, type: string): string {