Skip to content

Commit

Permalink
feat(app, api-client): usbPort type to match what robot server returns (
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader authored Jul 14, 2023
1 parent 0630f70 commit 46690d8
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 95 deletions.
25 changes: 21 additions & 4 deletions api-client/src/modules/__fixtures__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const mockModulesResponse = [
usbPort: {
port: 0,
path: '',
hub: false,
portGroup: 'unknown',
},
},
{
Expand All @@ -36,10 +38,13 @@ export const mockModulesResponse = [
currentSpeed: 0,
temperatureStatus: 'idle',
currentTemperature: 23.0,
targetSpeed: null,
},
usbPort: {
port: 0,
path: '',
hub: false,
portGroup: 'unknown',
},
},
{
Expand All @@ -58,6 +63,8 @@ export const mockModulesResponse = [
usbPort: {
port: 0,
path: '',
hub: false,
portGroup: 'unknown',
},
},
{
Expand All @@ -76,6 +83,8 @@ export const mockModulesResponse = [
usbPort: {
port: 0,
path: '',
hub: false,
portGroup: 'unknown',
},
},
]
Expand All @@ -87,8 +96,10 @@ export const v2MockModulesResponse = [
moduleModel: 'thermocyclerModuleV1',
port: '/dev/ot_module_sim_thermocycler0',
usbPort: {
hub: null,
port: 0,
hub: false,
portGroup: 'unknown',
path: '',
},
serial: 'dummySerialTC',
model: 'dummyModelTC',
Expand Down Expand Up @@ -116,7 +127,9 @@ export const v2MockModulesResponse = [
moduleModel: 'heaterShakerModuleV1',
port: '/dev/ot_module_sim_heatershaker1',
usbPort: {
hub: null,
hub: false,
portGroup: 'unknown',
path: '',
port: 0,
},
serial: 'dummySerialHS',
Expand All @@ -142,7 +155,9 @@ export const v2MockModulesResponse = [
moduleModel: 'temperatureModuleV1',
port: '/dev/ot_module_sim_tempdeck2',
usbPort: {
hub: null,
hub: false,
portGroup: 'unknown',
path: '',
port: 0,
},
serial: 'dummySerialTD',
Expand All @@ -162,8 +177,10 @@ export const v2MockModulesResponse = [
moduleModel: 'magneticModuleV1',
port: '/dev/ot_module_sim_magdeck3',
usbPort: {
hub: null,
port: 0,
hub: false,
portGroup: 'unknown',
path: '',
},
serial: 'dummySerialMD',
model: 'mag_deck_v1.1',
Expand Down
6 changes: 4 additions & 2 deletions api-client/src/modules/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { ModuleType } from '@opentrons/shared-data'

import type { ModuleModel } from '@opentrons/shared-data'

type PortGroup = 'main' | 'left' | 'right' | 'front' | 'unknown'
interface PhysicalPort {
path: string | null
port: number | null
hub: number | null
port: number
hub: boolean
portGroup: PortGroup
}

export interface ApiBaseModule {
Expand Down
2 changes: 1 addition & 1 deletion app/src/assets/localization/en/device_details.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
"to_run_protocol_go_to_protocols_page": "To run a protocol on this robot, import a protocol on the <navlink>Protocols page</navlink>",
"update_now": "Update now",
"updating_firmware": "Updating firmware...",
"usb_hub": "usb-{{port}} via hub",
"usb_port": "usb-{{port}}",
"usb_port_not_connected": "usb not connected",
"version": "Version {{version}}",
"view_pipette_setting": "Pipette Settings",
"view_run_record": "View protocol run record",
Expand Down
1 change: 0 additions & 1 deletion app/src/assets/localization/en/protocol_setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"heater_shaker_extra_attention": "Use latch controls for easy placement of labware.",
"heater_shaker_labware_list_view": "To add labware, use the toggle to control the latch",
"how_offset_data_works": "How labware offsets work",
"hub_port_connected": "USB Port {{port}} via hub",
"initial_liquids_num_plural": "{{count}} initial liquids",
"initial_liquids_num": "{{count}} initial liquid",
"initial_location": "Initial Location",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ export const HeaterShakerModuleCard = (
fontSize={TYPOGRAPHY.fontSizeCaption}
paddingBottom={SPACING.spacing4}
>
{t(module?.usbPort.port === null ? 'usb_hub' : 'usb_port', {
port: module?.usbPort.hub ?? module?.usbPort.port,
})}
{module?.usbPort !== null
? t('usb_port', {
port: module?.usbPort?.port,
})
: t('usb_port_not_connected')}
</StyledText>
<Flex paddingBottom={SPACING.spacing4}>
<Icon
Expand Down
3 changes: 1 addition & 2 deletions app/src/organisms/Devices/HeaterShakerWizard/PowerOn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export function PowerOn(props: PowerOnProps): JSX.Element {
<ModuleInfo
moduleModel={moduleDef.model}
isAttached={props.attachedModule !== null}
usbPort={props.attachedModule?.usbPort.port ?? null}
hubPort={props.attachedModule?.usbPort.hub ?? null}
physicalPort={props.attachedModule?.usbPort ?? null}
/>
</Module>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ const mockHeaterShakeShaking: HeaterShakerModule = {
errorDetails: null,
status: 'idle',
},
usbPort: { path: '/dev/ot_module_heatershaker0', port: 1, hub: null },
usbPort: {
path: '/dev/ot_module_heatershaker0',
port: 1,
hub: false,
portGroup: 'unknown',
},
}

describe('AttachAdapter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ describe('PowerOn', () => {
})

it('renders heater shaker SVG with info with module connected', () => {
if (props.attachedModule != null) {
props.attachedModule.usbPort.hub = 1
props.attachedModule.usbPort.port = null
if (props.attachedModule != null && props.attachedModule.usbPort != null) {
props.attachedModule.usbPort.port = 1
}
const { getByText } = render(props)
getByText('Connected')
getByText('Heater-Shaker Module GEN1')
getByText('USB Port 1 via hub')
getByText('USB Port 1')
})

it('renders heater shaker SVG with info with module not connected', () => {
Expand Down
15 changes: 6 additions & 9 deletions app/src/organisms/Devices/ModuleInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import {

import { StyledText } from '../../atoms/text'
import { useRunHasStarted } from './hooks'
import type { PhysicalPort } from '../../redux/modules/api-types'

export interface ModuleInfoProps {
moduleModel: ModuleModel
isAttached: boolean
usbPort: number | null
hubPort: number | null
physicalPort: PhysicalPort | null
runId?: string
}

export const ModuleInfo = (props: ModuleInfoProps): JSX.Element => {
const { moduleModel, usbPort, hubPort, isAttached, runId = null } = props
const { moduleModel, physicalPort, isAttached, runId = null } = props
const moduleDef = getModuleDef2(moduleModel)
const {
xDimension,
Expand All @@ -42,17 +42,14 @@ export const ModuleInfo = (props: ModuleInfoProps): JSX.Element => {
const { t } = useTranslation('protocol_setup')

const runHasStarted = useRunHasStarted(runId)

let connectionStatus = t('no_usb_port_yet')
if (moduleModel === MAGNETIC_BLOCK_V1) {
connectionStatus = t('no_usb_required')
}
if (usbPort === null && hubPort === null && isAttached) {
if (physicalPort === null && isAttached) {
connectionStatus = t('usb_connected_no_port_info')
} else if (hubPort === null && usbPort !== null && isAttached) {
connectionStatus = t('usb_port_connected', { port: usbPort })
} else if (hubPort !== null && isAttached) {
connectionStatus = t('hub_port_connected', { port: hubPort })
} else if (physicalPort != null && isAttached) {
connectionStatus = t('usb_port_connected', { port: physicalPort.port })
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export const SetupModulesMap = ({
<ModuleInfo
moduleModel={model}
isAttached={attachedModuleMatch != null}
usbPort={attachedModuleMatch?.usbPort.port ?? null}
hubPort={attachedModuleMatch?.usbPort.hub ?? null}
physicalPort={attachedModuleMatch?.usbPort ?? null}
runId={runId}
/>
</Module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ describe('SetupModulesMap', () => {
partialComponentPropsMatcher({
moduleModel: mockMagneticModule.model,
isAttached: false,
usbPort: null,
hubPort: null,
physicalPort: null,
runId: MOCK_RUN_ID,
})
)
Expand Down Expand Up @@ -247,8 +246,7 @@ describe('SetupModulesMap', () => {
componentPropsMatcher({
moduleModel: mockMagneticModule.model,
isAttached: true,
usbPort: mockMagneticModuleFixture.usbPort.port,
hubPort: mockMagneticModuleFixture.usbPort.hub,
physicalPort: mockMagneticModuleFixture.usbPort,
runId: MOCK_RUN_ID,
})
)
Expand All @@ -259,8 +257,7 @@ describe('SetupModulesMap', () => {
componentPropsMatcher({
moduleModel: mockTCModule.model,
isAttached: true,
usbPort: mockThermocyclerFixture.usbPort.port,
hubPort: mockThermocyclerFixture.usbPort.hub,
physicalPort: mockThermocyclerFixture.usbPort,
runId: MOCK_RUN_ID,
})
)
Expand All @@ -273,7 +270,6 @@ describe('SetupModulesMap', () => {
it('renders Moam with the correct module in the correct slot', () => {
const dupModId = `${mockMagneticModule.moduleId}duplicate`
const dupModPort = 10
const dupModHub = 2
when(mockUseModuleRenderInfoForProtocolById)
.calledWith(MOCK_ROBOT_NAME, MOCK_RUN_ID)
.mockReturnValue({
Expand Down Expand Up @@ -308,7 +304,9 @@ describe('SetupModulesMap', () => {
model: mockMagneticModule.model,
usbPort: {
port: dupModPort,
hub: dupModHub,
hub: false,
portGroup: 'unknown',
path: '',
},
} as any,
slotName: '3',
Expand All @@ -320,8 +318,7 @@ describe('SetupModulesMap', () => {
componentPropsMatcher({
moduleModel: mockMagneticModule.model,
isAttached: true,
usbPort: mockMagneticModuleFixture.usbPort.port,
hubPort: mockMagneticModuleFixture.usbPort.hub,
physicalPort: mockMagneticModuleFixture.usbPort,
runId: MOCK_RUN_ID,
})
)
Expand All @@ -332,8 +329,12 @@ describe('SetupModulesMap', () => {
componentPropsMatcher({
moduleModel: mockMagneticModule.model,
isAttached: true,
usbPort: dupModPort,
hubPort: dupModHub,
physicalPort: {
port: dupModPort,
hub: false,
portGroup: 'unknown',
path: '',
},
runId: MOCK_RUN_ID,
})
)
Expand Down
21 changes: 8 additions & 13 deletions app/src/organisms/Devices/__tests__/ModuleInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('ModuleInfo', () => {
props = {
moduleModel: mockTCModule.model,
isAttached: false,
usbPort: null,
hubPort: null,
physicalPort: null,
}
when(mockUseRunHasStarted).calledWith(MOCK_RUN_ID).mockReturnValue(false)
})
Expand All @@ -48,22 +47,19 @@ describe('ModuleInfo', () => {
getByText('Not connected')
})

it('should show module connected and hub number', () => {
props = { ...props, usbPort: 1, hubPort: 1, isAttached: true }
const { getByText } = render(props)
getByText('Connected')
getByText('USB Port 1 via hub')
})

it('should show module connected and no USB number', () => {
props = { ...props, usbPort: null, hubPort: null, isAttached: true }
props = { ...props, isAttached: true }
const { getByText } = render(props)
getByText('Connected')
getByText('USB Port Connected')
})

it('should show module connected and USB number', () => {
props = { ...props, usbPort: 1, hubPort: null, isAttached: true }
props = {
...props,
physicalPort: { port: 1, hub: false, portGroup: 'unknown', path: '' },
isAttached: true,
}
const { getByText } = render(props)
getByText('Connected')
getByText('USB Port 1')
Expand All @@ -72,8 +68,7 @@ describe('ModuleInfo', () => {
it('should not show module connected when run has started', () => {
props = {
...props,
usbPort: 1,
hubPort: null,
physicalPort: { port: 1, hub: false, portGroup: 'unknown', path: '' },
isAttached: true,
runId: MOCK_RUN_ID,
}
Expand Down
14 changes: 12 additions & 2 deletions app/src/organisms/ModuleCard/__tests__/ErrorInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ const mockErrorThermocycler = {
totalStepCount: null,
status: 'error',
},
usbPort: { path: '/dev/ot_module_thermocycler0', port: 1, hub: null },
usbPort: {
path: '/dev/ot_module_thermocycler0',
port: 1,
hub: false,
portGroup: 'unknown',
},
} as ThermocyclerModule

const mockErrorHeaterShaker = {
Expand All @@ -57,7 +62,12 @@ const mockErrorHeaterShaker = {
errorDetails: 'errorDetails',
status: 'error',
},
usbPort: { path: '/dev/ot_module_heatershaker0', hub: null, port: 1 },
usbPort: {
path: '/dev/ot_module_heatershaker0',
hub: false,
port: 1,
portGroup: 'unknown',
},
} as HeaterShakerModule

const render = (props: React.ComponentProps<typeof ErrorInfo>) => {
Expand Down
Loading

0 comments on commit 46690d8

Please sign in to comment.