import last from 'lodash/last' ; import { THERMOCYCLER_MODULE_TYPE } from '@opentrons/shared-data' ; import { getModuleState } from '../robotStateSelectors' ; import type { ModuleOnlyParams , TCProfileParams , TemperatureParams , ThermocyclerSetTargetBlockTemperatureArgs , } from '@opentrons/shared-data/protocol/types/schemaV4' ; import type { InvariantContext , RobotStateAndWarnings , RobotState , ThermocyclerModuleState , } from '../types' ; const _getThermocyclerModuleState = ( robotState , module ) : ThermocyclerModuleState => { const moduleState = getModuleState ( robotState , module ) ; if ( moduleState . type === THERMOCYCLER_MODULE_TYPE ) { return moduleState ; } else { console . error ( `Thermocycler state updater expected ${ module } moduleState to be thermocycler, but it was ${ moduleState . type }` ) ; const fallback = { } ; return fallback ; } } ; export const forThermocyclerSetTargetBlockTemperature = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module , temperature } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; moduleState . blockTargetTemp = temperature ; } ; export const forThermocyclerSetTargetLidTemperature = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module , temperature } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; moduleState . lidTargetTemp = temperature ; } ; export const forThermocyclerAwaitBlockTemperature = ( params , invariantContext , robotStateAndWarnings ) : void => { } ; export const forThermocyclerAwaitLidTemperature = ( params , invariantContext , robotStateAndWarnings ) : void => { } ; export const forThermocyclerAwaitProfileComplete = ( params , invariantContext , robotStateAndWarnings ) : void => { } ; export const forThermocyclerDeactivateBlock = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; moduleState . blockTargetTemp = null ; } ; export const forThermocyclerDeactivateLid = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; moduleState . lidTargetTemp = null ; } ; export const forThermocyclerCloseLid = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; moduleState . lidOpen = false ; } ; export const forThermocyclerOpenLid = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; moduleState . lidOpen = true ; } ; export const forThermocyclerRunProfile = ( params , invariantContext , robotStateAndWarnings ) : void => { const { module , profile } = params ; const { robotState } = robotStateAndWarnings ; const moduleState = _getThermocyclerModuleState ( robotState , module ) ; if ( profile . length > 0 ) { moduleState . blockTargetTemp = last ( profile ) . temperature ; } } ;