import { TEMPERATURE_MODULE_TYPE } from '@opentrons/shared-data' ; import { TEMPERATURE_AT_TARGET , TEMPERATURE_DEACTIVATED } from '../../constants' ; import * as errorCreators from '../../errorCreators' ; import type { CommandCreator , AwaitTemperatureArgs } from '../../types' ; import { getModuleState } from '../../robotStateSelectors' ; /** Set temperature target for specified module. */ export const awaitTemperature = ( args , invariantContext , prevRobotState ) => { const { module , temperature } = args ; const tempModState = module ? getModuleState ( prevRobotState , module ) : null ; if ( module === null || ! tempModState ) { return { errors : [ errorCreators . missingModuleError ( ) ] , } ; } if ( tempModState . type !== TEMPERATURE_MODULE_TYPE ) { console . error ( `expected module to be ${ TEMPERATURE_MODULE_TYPE } but got ${ tempModState . type }` ) ; return { errors : [ errorCreators . missingModuleError ( ) ] , } ; } const unreachableTemp = tempModState . status === TEMPERATURE_AT_TARGET && tempModState . targetTemperature !== temperature ; if ( unreachableTemp || tempModState . status === TEMPERATURE_DEACTIVATED ) { return { errors : [ errorCreators . missingTemperatureStep ( ) ] , } ; } const moduleType = invariantContext . moduleEntities [ module ] ?. type ; const params = { module , temperature , } ; switch ( moduleType ) { case TEMPERATURE_MODULE_TYPE : return { commands : [ { command : 'temperatureModule/awaitTemperature' , params , } , ] , } ; default : console . error ( `awaitTemperature expected module ${ module } to be ${ TEMPERATURE_MODULE_TYPE }, got ${ moduleType }` ) ; return { errors : [ errorCreators . missingModuleError ( ) ] , } ; } } ;