Skip to content

Commit 235f84b

Browse files
authored
refactor(step-generation): wasteChute command utils into compound com… (#17784)
…mands This is the 2nd 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 24e5aca commit 235f84b

12 files changed

+366
-230
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { describe, it, expect } from 'vitest'
2+
import {
3+
getInitialRobotStateStandard,
4+
getSuccessResult,
5+
makeContext,
6+
} from '../fixtures'
7+
import { airGapInWasteChute } from '../commandCreators/compound'
8+
import type { InvariantContext, PipetteEntities, RobotState } from '../types'
9+
10+
const mockId = 'mockId'
11+
const mockPipEntities: PipetteEntities = {
12+
[mockId]: {
13+
name: 'p50_single_flex',
14+
id: mockId,
15+
spec: { channels: 1 },
16+
},
17+
} as any
18+
19+
const invariantContext: InvariantContext = {
20+
...makeContext(),
21+
pipetteEntities: mockPipEntities,
22+
}
23+
const prevRobotState: RobotState = getInitialRobotStateStandard(
24+
invariantContext
25+
)
26+
27+
describe('airGapInWasteChute', () => {
28+
it('returns correct commands for air gap in waste chute', () => {
29+
const result = airGapInWasteChute(
30+
{
31+
pipetteId: mockId,
32+
volume: 10,
33+
flowRate: 10,
34+
},
35+
invariantContext,
36+
prevRobotState
37+
)
38+
expect(getSuccessResult(result).commands).toEqual([
39+
{
40+
commandType: 'moveToAddressableArea',
41+
key: expect.any(String),
42+
params: {
43+
pipetteId: mockId,
44+
addressableAreaName: '1ChannelWasteChute',
45+
offset: { x: 0, y: 0, z: 0 },
46+
},
47+
},
48+
{
49+
commandType: 'prepareToAspirate',
50+
key: expect.any(String),
51+
params: {
52+
pipetteId: mockId,
53+
},
54+
},
55+
{
56+
commandType: 'airGapInPlace',
57+
key: expect.any(String),
58+
params: {
59+
pipetteId: mockId,
60+
flowRate: 10,
61+
volume: 10,
62+
},
63+
},
64+
])
65+
})
66+
})
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { describe, it, expect, vi } from 'vitest'
2+
import {
3+
getInitialRobotStateStandard,
4+
getSuccessResult,
5+
makeContext,
6+
} from '../fixtures'
7+
import { blowOutInWasteChute } from '../commandCreators/compound'
8+
import type { InvariantContext, PipetteEntities, RobotState } from '../types'
9+
10+
vi.mock('../getNextRobotStateAndWarnings/dispenseUpdateLiquidState')
11+
12+
const mockId = 'mockId'
13+
const mockPipEntities: PipetteEntities = {
14+
[mockId]: {
15+
name: 'p50_single_flex',
16+
id: mockId,
17+
spec: { channels: 1 },
18+
},
19+
} as any
20+
21+
const invariantContext: InvariantContext = {
22+
...makeContext(),
23+
pipetteEntities: mockPipEntities,
24+
}
25+
const prevRobotState: RobotState = getInitialRobotStateStandard(
26+
invariantContext
27+
)
28+
29+
describe('blowOutInWasteChute', () => {
30+
it('returns correct commands for blowing out in waste chute', () => {
31+
const result = blowOutInWasteChute(
32+
{
33+
pipetteId: mockId,
34+
flowRate: 10,
35+
},
36+
invariantContext,
37+
prevRobotState
38+
)
39+
expect(getSuccessResult(result).commands).toEqual([
40+
{
41+
commandType: 'moveToAddressableArea',
42+
key: expect.any(String),
43+
params: {
44+
pipetteId: mockId,
45+
addressableAreaName: '1ChannelWasteChute',
46+
offset: { x: 0, y: 0, z: 0 },
47+
},
48+
},
49+
{
50+
commandType: 'blowOutInPlace',
51+
key: expect.any(String),
52+
params: {
53+
pipetteId: mockId,
54+
flowRate: 10,
55+
},
56+
},
57+
])
58+
})
59+
})

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { beforeEach, describe, it, expect, vi } from 'vitest'
2-
import { ONE_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA } from '@opentrons/shared-data'
32
import {
43
blowoutUtil,
54
SOURCE_WELL_BLOWOUT_DESTINATION,
65
DEST_WELL_BLOWOUT_DESTINATION,
76
} from '../utils'
8-
import {
9-
blowOutInPlace,
10-
moveToAddressableArea,
11-
blowout,
12-
} from '../commandCreators/atomic'
7+
import { blowout } from '../commandCreators/atomic'
8+
import { blowOutInWasteChute } from '../commandCreators/compound'
139
import { curryCommandCreator } from '../utils/curryCommandCreator'
1410
import {
1511
DEFAULT_PIPETTE,
@@ -23,6 +19,7 @@ import {
2319
} from '../fixtures'
2420
import type { RobotState, InvariantContext } from '../types'
2521
import type { BlowoutParams } from '@opentrons/shared-data'
22+
2623
vi.mock('../utils/curryCommandCreator')
2724

2825
let blowoutArgs: {
@@ -94,14 +91,9 @@ describe('blowoutUtil', () => {
9491
destWell: null,
9592
blowoutLocation: wasteChuteId,
9693
})
97-
expect(curryCommandCreator).toHaveBeenCalledWith(moveToAddressableArea, {
98-
addressableAreaName: ONE_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA,
94+
expect(curryCommandCreator).toHaveBeenCalledWith(blowOutInWasteChute, {
9995
pipetteId: blowoutArgs.pipette,
100-
offset: { x: 0, y: 0, z: 0 },
101-
})
102-
expect(curryCommandCreator).toHaveBeenCalledWith(blowOutInPlace, {
10396
flowRate: 2.3,
104-
pipetteId: blowoutArgs.pipette,
10597
})
10698
})
10799
it('blowoutUtil curries blowout with dest plate params', () => {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { describe, it, expect, vi } from 'vitest'
2+
import {
3+
getInitialRobotStateStandard,
4+
getSuccessResult,
5+
makeContext,
6+
} from '../fixtures'
7+
import { dispenseInWasteChute } from '../commandCreators/compound'
8+
import type { InvariantContext, PipetteEntities, RobotState } from '../types'
9+
10+
vi.mock('../getNextRobotStateAndWarnings/dispenseUpdateLiquidState')
11+
12+
const mockId = 'mockId'
13+
const mockPipEntities: PipetteEntities = {
14+
[mockId]: {
15+
name: 'p50_single_flex',
16+
id: mockId,
17+
spec: { channels: 1 },
18+
},
19+
} as any
20+
21+
const invariantContext: InvariantContext = {
22+
...makeContext(),
23+
pipetteEntities: mockPipEntities,
24+
}
25+
const prevRobotState: RobotState = getInitialRobotStateStandard(
26+
invariantContext
27+
)
28+
29+
describe('dispenseInWasteChute', () => {
30+
it('returns correct commands for dispensing in waste chute', () => {
31+
const result = dispenseInWasteChute(
32+
{
33+
pipetteId: mockId,
34+
volume: 10,
35+
flowRate: 10,
36+
},
37+
invariantContext,
38+
prevRobotState
39+
)
40+
expect(getSuccessResult(result).commands).toEqual([
41+
{
42+
commandType: 'moveToAddressableArea',
43+
key: expect.any(String),
44+
params: {
45+
pipetteId: mockId,
46+
addressableAreaName: '1ChannelWasteChute',
47+
offset: { x: 0, y: 0, z: 0 },
48+
},
49+
},
50+
{
51+
commandType: 'dispenseInPlace',
52+
key: expect.any(String),
53+
params: {
54+
pipetteId: mockId,
55+
flowRate: 10,
56+
volume: 10,
57+
},
58+
},
59+
])
60+
})
61+
})

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

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

0 commit comments

Comments
 (0)