- tests/device.spec.ts: fix 6× organizeParameters() calls passing wrapped
response object instead of flat ParameterInfoStruct[] (runtime break)
- tests/device.spec.ts: fix setTmpParamValues([{x:1}]) with valid shape
- immediate_command_state_machine.ts: type handleResponse message param as
CWMPTaskResultData (was any, gap in typing contract)
- configuration_evaluation_state.ts: replace fragile ../../../app/ dynamic
import paths with proper static imports from ../../protocol/tr069_types.js
- main_state_machine.ts: replace all inline dynamic import() type casts with
static imports (GetParameterNamesResponse, GetParameterValuesResponse,
ParameterValueStruct, SetParameterAttribute, DownloadParameter, etc.)
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { Device } from '../../domain/device/device.js'
|
|
import { CWMPTaskQueue } from './task_queue.js'
|
|
import { DeviceActionExecutor } from './device_action_executor.js'
|
|
import { ExecutingCommandsState, DeviceContext, DeviceStateResult } from './main_state_machine.js'
|
|
import type { CWMPTaskResultData } from '../../protocol/tr069_types.js'
|
|
import logger from '@adonisjs/core/services/logger'
|
|
|
|
/**
|
|
* State machine for "6 CONNECTION REQUEST" events.
|
|
* Only executes pending Immediate (I) commands - does NOT include NI commands.
|
|
*/
|
|
export class ImmediateCommandStateMachine {
|
|
private currentState: ExecutingCommandsState
|
|
private context: DeviceContext
|
|
|
|
constructor(device: Device, session: string, taskQueue: CWMPTaskQueue) {
|
|
// includeNI = false: only execute Immediate commands
|
|
this.currentState = new ExecutingCommandsState(false)
|
|
this.context = {
|
|
device,
|
|
session,
|
|
taskQueue,
|
|
services: {
|
|
deviceAction: new DeviceActionExecutor(taskQueue),
|
|
},
|
|
}
|
|
}
|
|
|
|
async start(): Promise<string> {
|
|
logger.info(`Starting immediate-command state machine for device ${this.context.device.deviceId?.serialNumber}`)
|
|
return this.execute()
|
|
}
|
|
|
|
async handleResponse(success: boolean, message: CWMPTaskResultData): Promise<string> {
|
|
this.context.message = { success, data: message }
|
|
return this.execute()
|
|
}
|
|
|
|
getCurrentStateName(): string {
|
|
return this.currentState.name
|
|
}
|
|
|
|
isCompleted(): boolean {
|
|
return this.currentState.name === 'completed' || this.currentState.name === 'operational' || this.currentState.name === 'partial_operational'
|
|
}
|
|
|
|
private async execute(): Promise<string> {
|
|
try {
|
|
const result: DeviceStateResult = await this.currentState.handle(this.context)
|
|
|
|
if (result.isComplete) {
|
|
return ''
|
|
}
|
|
|
|
if (result.response && result.response !== '') {
|
|
return result.response
|
|
}
|
|
|
|
return ''
|
|
} catch (error) {
|
|
logger.error(`Immediate-command state machine error: ${error}`)
|
|
return ''
|
|
}
|
|
}
|
|
}
|