-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-designer): hook up wait for temp in PD (#4926)
* feat(protocol-designer): hook up wait for temp in PD Adds new command creator for await temp, adds warnings as specified in ticket fix #4732 * refactor await temperature test * add comment explaining unreachable temp * clean up imports * refactor step generation tests to use same robot factory function * plug in forAwaitTemperature state updater * adds in missing temp step error text into localization * removed comments * Use temperature instead of temp to avoid confusion * move mock object creator into existing fixture file * rename test name to be more understandable * refactor test to reuse mock factory function * import status constants into test fixture file * update test names to reflect action and outcome * remove leftover console.log
- Loading branch information
Showing
16 changed files
with
528 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
protocol-designer/src/step-generation/commandCreators/atomic/awaitTemperature.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// @flow | ||
import { | ||
TEMPDECK, | ||
TEMPERATURE_AT_TARGET, | ||
TEMPERATURE_DEACTIVATED, | ||
} from '../../../constants' | ||
import * as errorCreators from '../../errorCreators' | ||
import type { CommandCreator, AwaitTemperatureArgs } from '../../types' | ||
import { getModuleState } from '../../utils/misc' | ||
|
||
/** Set temperature target for specified module. */ | ||
export const awaitTemperature: CommandCreator<AwaitTemperatureArgs> = ( | ||
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 !== TEMPDECK) { | ||
console.error( | ||
`expected module to be ${TEMPDECK} but got ${tempModState.type}` | ||
) | ||
return { errors: [errorCreators.missingModuleError()] } | ||
} | ||
|
||
// if the temp mod is already at the target temp | ||
// AND the newly awaited temperature is different than the target temp | ||
// this means the temp mod will not change its temp, since it is already | ||
// at the target temp, so the new await temp will never be reached | ||
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 TEMPDECK: | ||
return { | ||
commands: [ | ||
{ | ||
command: 'temperatureModule/awaitTemperature', | ||
params, | ||
}, | ||
], | ||
} | ||
|
||
default: | ||
console.error( | ||
`awaitTemperature expected module ${module} to be ${TEMPDECK}, got ${moduleType}` | ||
) | ||
return { errors: [errorCreators.missingModuleError()] } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// @flow | ||
export { | ||
aspirate, | ||
awaitTemperature, | ||
blowout, | ||
consolidate, | ||
distribute, | ||
|
150 changes: 150 additions & 0 deletions
150
protocol-designer/src/step-generation/test-with-flow/awaitTemperature.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// @flow | ||
import { | ||
TEMPERATURE_AT_TARGET, | ||
TEMPERATURE_APPROACHING_TARGET, | ||
TEMPERATURE_DEACTIVATED, | ||
} from '../../constants' | ||
import { awaitTemperature } from '../commandCreators/atomic/awaitTemperature' | ||
import { | ||
getStateAndContextTempMagModules, | ||
robotWithStatusAndTemp, | ||
} from './fixtures' | ||
|
||
describe('awaitTemperature', () => { | ||
const temperatureModuleId = 'temperatureModuleId' | ||
const thermocyclerId = 'thermocyclerId' | ||
const commandCreatorFnName = 'awaitTemperature' | ||
const prevRobotTemp = 42 | ||
|
||
const missingModuleError = { | ||
errors: [{ message: expect.any(String), type: 'MISSING_MODULE' }], | ||
} | ||
const missingTemperatureStep = { | ||
errors: [{ message: expect.any(String), type: 'MISSING_TEMPERATURE_STEP' }], | ||
} | ||
|
||
let invariantContext | ||
let robotState | ||
|
||
beforeEach(() => { | ||
const stateAndContext = getStateAndContextTempMagModules({ | ||
temperatureModuleId, | ||
thermocyclerId, | ||
}) | ||
invariantContext = stateAndContext.invariantContext | ||
robotState = stateAndContext.robotState | ||
}) | ||
|
||
test('temperature module id exists and temp status is approaching temp', () => { | ||
const temperature = 20 | ||
const args = { | ||
module: temperatureModuleId, | ||
temperature, | ||
commandCreatorFnName, | ||
} | ||
const previousRobotState = robotWithStatusAndTemp( | ||
robotState, | ||
temperatureModuleId, | ||
TEMPERATURE_APPROACHING_TARGET, | ||
prevRobotTemp | ||
) | ||
|
||
const expected = { | ||
commands: [ | ||
{ | ||
command: 'temperatureModule/awaitTemperature', | ||
params: { | ||
module: temperatureModuleId, | ||
temperature: 20, | ||
}, | ||
}, | ||
], | ||
} | ||
const result = awaitTemperature(args, invariantContext, previousRobotState) | ||
expect(result).toEqual(expected) | ||
}) | ||
test('returns missing module error when module id does not exist', () => { | ||
const temperature = 42 | ||
const args = { | ||
module: 'someNonexistentModuleId', | ||
temperature, | ||
commandCreatorFnName, | ||
} | ||
|
||
const result = awaitTemperature(args, invariantContext, robotState) | ||
expect(result).toEqual(missingModuleError) | ||
}) | ||
test('returns missing module error when module id is null', () => { | ||
const temperature = 42 | ||
const args = { | ||
module: null, | ||
temperature, | ||
commandCreatorFnName, | ||
} | ||
|
||
const result = awaitTemperature(args, invariantContext, robotState) | ||
expect(result).toEqual(missingModuleError) | ||
}) | ||
test('returns awaitTemperature command creator when temperature module already at target temp and awaiting that same temp', () => { | ||
const temperature = 42 | ||
const args = { | ||
module: temperatureModuleId, | ||
temperature, | ||
commandCreatorFnName, | ||
} | ||
const previousRobotState = robotWithStatusAndTemp( | ||
robotState, | ||
temperatureModuleId, | ||
TEMPERATURE_AT_TARGET, | ||
prevRobotTemp | ||
) | ||
const expected = { | ||
commands: [ | ||
{ | ||
command: 'temperatureModule/awaitTemperature', | ||
params: { | ||
module: temperatureModuleId, | ||
temperature: 42, | ||
}, | ||
}, | ||
], | ||
} | ||
const result = awaitTemperature(args, invariantContext, previousRobotState) | ||
expect(result).toEqual(expected) | ||
}) | ||
test('returns missing temperature step error when temperature module already at target temp and awaiting different temp', () => { | ||
const temperature = 80 | ||
const args = { | ||
module: temperatureModuleId, | ||
temperature, | ||
commandCreatorFnName, | ||
} | ||
|
||
const previousRobotState = robotWithStatusAndTemp( | ||
robotState, | ||
temperatureModuleId, | ||
TEMPERATURE_AT_TARGET, | ||
prevRobotTemp | ||
) | ||
|
||
const result = awaitTemperature(args, invariantContext, previousRobotState) | ||
expect(result).toEqual(missingTemperatureStep) | ||
}) | ||
test('returns missing temperature step error when prev temp state is DEACTIVATED', () => { | ||
const temperature = 80 | ||
const args = { | ||
module: temperatureModuleId, | ||
temperature, | ||
commandCreatorFnName, | ||
} | ||
const previousRobotState = robotWithStatusAndTemp( | ||
robotState, | ||
temperatureModuleId, | ||
TEMPERATURE_DEACTIVATED, | ||
prevRobotTemp | ||
) | ||
|
||
const result = awaitTemperature(args, invariantContext, previousRobotState) | ||
expect(result).toEqual(missingTemperatureStep) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.