Files
adam-acs/app/services/cwmp/immediate_command_state_machine.ts
T
Kevin L'Hereec 9cceb139b7 fix: eslint consistent-type-imports and eqeqeq violations
- Convert value imports used only as types to 'import type' across
  all modified files (cwmp_message_builder, task_queue, device_action_executor,
  main_state_machine, immediate_command_state_machine, configuration_evaluation_state,
  cwmp_controller, cwmp_middleware, device.ts, soap.ts, soap_envelope.ts, tr069_types.ts)
- Replace != null with !== null && !== undefined in main_state_machine and cwmp_controller
2026-07-20 17:14:12 +02:00

76 lines
2.1 KiB
TypeScript

import { type Device } from '../../domain/device/device.js'
import { type CWMPTaskQueue } from './task_queue.js'
import { DeviceActionExecutor } from './device_action_executor.js'
import {
ExecutingCommandsState,
type DeviceContext,
type 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 ''
}
}
}