Skip to content

Commit

Permalink
feat(app): Add support for modules to RPC API client (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Jul 17, 2018
1 parent f80ad18 commit 331305f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
17 changes: 13 additions & 4 deletions app/src/robot/api-client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,17 @@ export default function client (dispatch) {

if (apiSession.instruments) {
update.pipettesByMount = {}
apiSession.instruments.forEach(apiInstrumentToInstrument)
apiSession.instruments.forEach(addApiInstrumentToPipettes)
}

if (apiSession.containers) {
update.labwareBySlot = {}
apiSession.containers.forEach(apiContainerToContainer)
apiSession.containers.forEach(addApiContainerToLabware)
}

if (apiSession.modules) {
update.modulesBySlot = {}
apiSession.modules.forEach(addApiModuleToModules)
}

if (apiSession.protocol_text) {
Expand Down Expand Up @@ -371,7 +376,7 @@ export default function client (dispatch) {
}
}

function apiInstrumentToInstrument (apiInstrument) {
function addApiInstrumentToPipettes (apiInstrument) {
const {_id, mount, name, channels} = apiInstrument
// TODO(mc, 2018-01-17): pull this somehow from tiprack the instrument
// interacts with
Expand All @@ -380,7 +385,7 @@ export default function client (dispatch) {
update.pipettesByMount[mount] = {_id, mount, name, channels, volume}
}

function apiContainerToContainer (apiContainer) {
function addApiContainerToLabware (apiContainer) {
const {_id, name, type, slot} = apiContainer
const isTiprack = RE_TIPRACK.test(type)
const labware = {_id, name, slot, type, isTiprack}
Expand All @@ -391,6 +396,10 @@ export default function client (dispatch) {

update.labwareBySlot[slot] = labware
}

function addApiModuleToModules (apiModule) {
update.modulesBySlot[apiModule.slot] = apiModule
}
}

function handleRobotNotification (message) {
Expand Down
11 changes: 8 additions & 3 deletions app/src/robot/reducer/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Command,
StatePipette,
StateLabware,
StateModule,
Mount,
Slot,
SessionStatus
Expand Down Expand Up @@ -31,13 +32,16 @@ export type State = {
// TODO(mc, 2018-01-11): command IDs should be strings
protocolCommands: number[],
protocolCommandsById: {
[number]: Command
[number]: Command,
},
pipettesByMount: {
[Mount]: StatePipette
[Mount]: StatePipette,
},
labwareBySlot: {
[Slot]: StateLabware
[Slot]: StateLabware,
},
modulesBySlot: {
[Slot]: StateModule,
},
runRequest: Request,
pauseRequest: Request,
Expand Down Expand Up @@ -75,6 +79,7 @@ const INITIAL_STATE: State = {
// deck setup from protocol
pipettesByMount: {},
labwareBySlot: {},
modulesBySlot: {},

// running a protocol
runRequest: {inProgress: false, error: null},
Expand Down
3 changes: 3 additions & 0 deletions app/src/robot/test/__mocks__/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export default function MockSession () {
instruments: [],
containers: [],

// TODO(mc, 2018-07-16): THIS IS A MOCK
modules: [],

run: jest.fn(),
pause: jest.fn(),
resume: jest.fn(),
Expand Down
36 changes: 35 additions & 1 deletion app/src/robot/test/api-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ describe('api client', () => {
protocolCommands: [],
protocolCommandsById: {},
pipettesByMount: {},
labwareBySlot: {}
labwareBySlot: {},
modulesBySlot: {}
})
})

Expand Down Expand Up @@ -394,6 +395,39 @@ describe('api client', () => {
.then(() => expect(dispatch).toHaveBeenCalledWith(expected))
})

test('maps api modules to modules by slot', () => {
const expected = actions.sessionResponse(null, expect.objectContaining({
modulesBySlot: {
1: {
_id: 1,
slot: '1',
name: 'tempdeck'
},
9: {
_id: 9,
slot: '9',
name: 'magdeck'
}
}
}))

session.modules = [
{
_id: 1,
slot: '1',
name: 'tempdeck'
},
{
_id: 9,
slot: '9',
name: 'magdeck'
}
]

return sendConnect()
.then(() => expect(dispatch).toHaveBeenCalledWith(expected))
})

test('sends error if received malformed session from API', () => {
const expected = actions.sessionResponse(expect.anything())

Expand Down
1 change: 1 addition & 0 deletions app/src/robot/test/session-reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('robot reducer - session', () => {
// deck setup from protocol
pipettesByMount: {},
labwareBySlot: {},
modulesBySlot: {},

// running a protocol
runRequest: {inProgress: false, error: null},
Expand Down
9 changes: 9 additions & 0 deletions app/src/robot/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ export type Labware = StateLabware & {

export type LabwareType = 'tiprack' | 'labware'

export type StateModule = {
// resource ID
_id: number,
// slot module is installed in
slot: Slot,
// name identifier of the module
type: 'magdeck' | 'tempdeck',
}

export type SessionStatus =
| ''
| 'loaded'
Expand Down

0 comments on commit 331305f

Please sign in to comment.