Skip to content

Commit 2a785a7

Browse files
authored
refactor(step-generation): trash command utils into compound commands (#17782)
This is the 1st PR in a series of PRs that refactors any utils that emit several commands in step-generation into a compound command for py interop.
1 parent b0db34f commit 2a785a7

File tree

11 files changed

+337
-214
lines changed

11 files changed

+337
-214
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { describe, it, expect } from 'vitest'
2+
import {
3+
getInitialRobotStateStandard,
4+
getSuccessResult,
5+
makeContext,
6+
} from '../fixtures'
7+
import { airGapInTrash } from '../commandCreators/compound'
8+
import type { CutoutId } from '@opentrons/shared-data'
9+
import type { InvariantContext, RobotState } from '../types'
10+
11+
const mockId = 'mockId'
12+
const mockCutout: CutoutId = 'cutoutA3'
13+
const invariantContext: InvariantContext = makeContext()
14+
const prevRobotState: RobotState = getInitialRobotStateStandard(
15+
invariantContext
16+
)
17+
18+
describe('airGapInTrash', () => {
19+
it('returns correct commands for airGapInPlace over a trash bin', () => {
20+
const result = airGapInTrash(
21+
{
22+
pipetteId: mockId,
23+
volume: 10,
24+
flowRate: 10,
25+
trashLocation: mockCutout,
26+
},
27+
invariantContext,
28+
prevRobotState
29+
)
30+
expect(getSuccessResult(result).commands).toEqual([
31+
{
32+
commandType: 'moveToAddressableArea',
33+
key: expect.any(String),
34+
params: {
35+
pipetteId: mockId,
36+
addressableAreaName: 'movableTrashA3',
37+
offset: { x: 0, y: 0, z: 0 },
38+
},
39+
},
40+
{
41+
commandType: 'prepareToAspirate',
42+
key: expect.any(String),
43+
params: {
44+
pipetteId: mockId,
45+
},
46+
},
47+
{
48+
commandType: 'airGapInPlace',
49+
key: expect.any(String),
50+
params: {
51+
pipetteId: mockId,
52+
volume: 10,
53+
flowRate: 10,
54+
},
55+
},
56+
])
57+
})
58+
})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { describe, it, expect, vi } from 'vitest'
2+
import {
3+
getInitialRobotStateStandard,
4+
getSuccessResult,
5+
makeContext,
6+
} from '../fixtures'
7+
import { blowOutInTrash } from '../commandCreators/compound'
8+
import type { CutoutId } from '@opentrons/shared-data'
9+
import type { InvariantContext, RobotState } from '../types'
10+
11+
vi.mock('../getNextRobotStateAndWarnings/dispenseUpdateLiquidState')
12+
13+
const mockId = 'mockId'
14+
const mockCutout: CutoutId = 'cutoutA3'
15+
const invariantContext: InvariantContext = makeContext()
16+
const prevRobotState: RobotState = getInitialRobotStateStandard(
17+
invariantContext
18+
)
19+
20+
describe('blowOutInTrash', () => {
21+
it('returns correct commands for blowout in a trash bin', () => {
22+
const result = blowOutInTrash(
23+
{
24+
pipetteId: mockId,
25+
flowRate: 10,
26+
trashLocation: mockCutout,
27+
},
28+
invariantContext,
29+
prevRobotState
30+
)
31+
expect(getSuccessResult(result).commands).toEqual([
32+
{
33+
commandType: 'moveToAddressableArea',
34+
key: expect.any(String),
35+
params: {
36+
pipetteId: mockId,
37+
addressableAreaName: 'movableTrashA3',
38+
offset: { x: 0, y: 0, z: 0 },
39+
},
40+
},
41+
{
42+
commandType: 'blowOutInPlace',
43+
key: expect.any(String),
44+
params: {
45+
pipetteId: mockId,
46+
flowRate: 10,
47+
},
48+
},
49+
])
50+
})
51+
})
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, it, expect, vi } from 'vitest'
2+
import {
3+
getInitialRobotStateStandard,
4+
getSuccessResult,
5+
makeContext,
6+
} from '../fixtures'
7+
import { dispenseInTrash } from '../commandCreators/compound'
8+
import type { CutoutId } from '@opentrons/shared-data'
9+
import type { InvariantContext, RobotState } from '../types'
10+
11+
vi.mock('../getNextRobotStateAndWarnings/dispenseUpdateLiquidState')
12+
13+
const mockId = 'mockId'
14+
const mockCutout: CutoutId = 'cutoutA3'
15+
const invariantContext: InvariantContext = makeContext()
16+
const prevRobotState: RobotState = getInitialRobotStateStandard(
17+
invariantContext
18+
)
19+
20+
describe('dispenseInTrash', () => {
21+
it('returns correct commands for dispenseInTrash in trash bin', () => {
22+
const result = dispenseInTrash(
23+
{
24+
pipetteId: mockId,
25+
flowRate: 10,
26+
volume: 10,
27+
trashLocation: mockCutout,
28+
},
29+
invariantContext,
30+
prevRobotState
31+
)
32+
expect(getSuccessResult(result).commands).toEqual([
33+
{
34+
commandType: 'moveToAddressableArea',
35+
key: expect.any(String),
36+
params: {
37+
pipetteId: mockId,
38+
addressableAreaName: 'movableTrashA3',
39+
offset: { x: 0, y: 0, z: 0 },
40+
},
41+
},
42+
{
43+
commandType: 'dispenseInPlace',
44+
key: expect.any(String),
45+
params: {
46+
pipetteId: mockId,
47+
volume: 10,
48+
flowRate: 10,
49+
},
50+
},
51+
])
52+
})
53+
})

step-generation/src/__tests__/movableTrashCommandsUtil.test.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
getTrashBinAddressableAreaName,
3+
reduceCommandCreators,
4+
curryCommandCreator,
5+
} from '../../utils'
6+
import { ZERO_OFFSET } from '../../constants'
7+
import {
8+
airGapInPlace,
9+
moveToAddressableArea,
10+
prepareToAspirate,
11+
} from '../atomic'
12+
import type { CurriedCommandCreator, CommandCreator } from '../../types'
13+
import type { CutoutId } from '@opentrons/shared-data'
14+
15+
interface AirGapInTrashParams {
16+
pipetteId: string
17+
flowRate: number
18+
volume: number
19+
trashLocation: CutoutId
20+
}
21+
export const airGapInTrash: CommandCreator<AirGapInTrashParams> = (
22+
args,
23+
invariantContext,
24+
prevRobotState
25+
) => {
26+
const { pipetteId, trashLocation, flowRate, volume } = args
27+
const addressableAreaName = getTrashBinAddressableAreaName(trashLocation)
28+
const commandCreators: CurriedCommandCreator[] = [
29+
curryCommandCreator(moveToAddressableArea, {
30+
pipetteId,
31+
addressableAreaName,
32+
offset: ZERO_OFFSET,
33+
}),
34+
curryCommandCreator(prepareToAspirate, {
35+
pipetteId,
36+
}),
37+
curryCommandCreator(airGapInPlace, {
38+
pipetteId,
39+
volume,
40+
flowRate,
41+
}),
42+
]
43+
44+
return reduceCommandCreators(
45+
commandCreators,
46+
invariantContext,
47+
prevRobotState
48+
)
49+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
getTrashBinAddressableAreaName,
3+
reduceCommandCreators,
4+
curryCommandCreator,
5+
} from '../../utils'
6+
import { ZERO_OFFSET } from '../../constants'
7+
import { blowOutInPlace, moveToAddressableArea } from '../atomic'
8+
import type { CurriedCommandCreator, CommandCreator } from '../../types'
9+
import type { CutoutId } from '@opentrons/shared-data'
10+
11+
interface BlowOutInTrashParams {
12+
pipetteId: string
13+
flowRate: number
14+
trashLocation: CutoutId
15+
}
16+
export const blowOutInTrash: CommandCreator<BlowOutInTrashParams> = (
17+
args,
18+
invariantContext,
19+
prevRobotState
20+
) => {
21+
const { pipetteId, trashLocation, flowRate } = args
22+
const addressableAreaName = getTrashBinAddressableAreaName(trashLocation)
23+
const commandCreators: CurriedCommandCreator[] = [
24+
curryCommandCreator(moveToAddressableArea, {
25+
pipetteId,
26+
addressableAreaName,
27+
offset: ZERO_OFFSET,
28+
}),
29+
curryCommandCreator(blowOutInPlace, {
30+
pipetteId,
31+
flowRate,
32+
}),
33+
]
34+
35+
return reduceCommandCreators(
36+
commandCreators,
37+
invariantContext,
38+
prevRobotState
39+
)
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
getTrashBinAddressableAreaName,
3+
reduceCommandCreators,
4+
curryCommandCreator,
5+
} from '../../utils'
6+
import { ZERO_OFFSET } from '../../constants'
7+
import { dispenseInPlace, moveToAddressableArea } from '../atomic'
8+
import type { CurriedCommandCreator, CommandCreator } from '../../types'
9+
import type { CutoutId } from '@opentrons/shared-data'
10+
11+
interface DispenseInTrashParams {
12+
pipetteId: string
13+
flowRate: number
14+
volume: number
15+
trashLocation: CutoutId
16+
}
17+
export const dispenseInTrash: CommandCreator<DispenseInTrashParams> = (
18+
args,
19+
invariantContext,
20+
prevRobotState
21+
) => {
22+
const { pipetteId, trashLocation, flowRate, volume } = args
23+
const addressableAreaName = getTrashBinAddressableAreaName(trashLocation)
24+
const commandCreators: CurriedCommandCreator[] = [
25+
curryCommandCreator(moveToAddressableArea, {
26+
pipetteId,
27+
addressableAreaName,
28+
offset: ZERO_OFFSET,
29+
}),
30+
curryCommandCreator(dispenseInPlace, {
31+
pipetteId,
32+
volume,
33+
flowRate,
34+
}),
35+
]
36+
37+
return reduceCommandCreators(
38+
commandCreators,
39+
invariantContext,
40+
prevRobotState
41+
)
42+
}

step-generation/src/commandCreators/compound/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export { absorbanceReaderCloseInitialize } from './absorbanceReaderCloseInitialize'
22
export { absorbanceReaderCloseRead } from './absorbanceReaderCloseRead'
3+
export { airGapInTrash } from './airGapInTrash'
4+
export { blowOutInTrash } from './blowOutInTrash'
35
export { consolidate } from './consolidate'
6+
export { dispenseInTrash } from './dispenseInTrash'
47
export { distribute } from './distribute'
58
export { dropTipInTrash } from './dropTipInTrash'
69
export { dropTipInWasteChute } from './dropTipInWasteChute'

step-generation/src/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export * from './commandCreatorArgsGetters'
2323
export * from './heaterShakerCollision'
2424
export * from './createTimelineFromRunCommands'
2525
export * from './misc'
26-
export * from './movableTrashCommandsUtil'
2726
export * from './safePipetteMovements'
2827
export * from './wasteChuteCommandsUtil'
2928
export * from './createTimelineFromRunCommands'

0 commit comments

Comments
 (0)