Skip to content

Commit

Permalink
fix(app): update useIsRobot busy hook to check for firmware update
Browse files Browse the repository at this point in the history
Query subsystem updates in useIsRobotBusy hook to check for in-progress firmware updates as
discovered in erroniously enabled robot overflow menu during firmwre update.
  • Loading branch information
ncdiehl11 committed Feb 8, 2024
1 parent 17963c0 commit 77e5e9c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
44 changes: 42 additions & 2 deletions app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { UseQueryResult } from 'react-query'

import { useAllSessionsQuery, useEstopQuery } from '@opentrons/react-api-client'
import {
useAllSessionsQuery,
useEstopQuery,
useCurrentAllSubsystemUpdatesQuery,
} from '@opentrons/react-api-client'

import {
DISENGAGED,
Expand All @@ -12,7 +16,12 @@ import { useIsFlex } from '../useIsFlex'
import { useNotifyCurrentMaintenanceRun } from '../../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun'
import { useNotifyAllRunsQuery } from '../../../../resources/runs/useNotifyAllRunsQuery'

import type { Sessions, Runs } from '@opentrons/api-client'
import type {
Sessions,
Runs,
Subsystem,

Check failure on line 22 in app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts

View workflow job for this annotation

GitHub Actions / js checks

'Subsystem' is defined but never used

Check failure on line 22 in app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts

View workflow job for this annotation

GitHub Actions / js checks

'Subsystem' is defined but never used
CurrentSubsystemUpdates,

Check failure on line 23 in app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts

View workflow job for this annotation

GitHub Actions / js checks

'CurrentSubsystemUpdates' is defined but never used

Check failure on line 23 in app/src/organisms/Devices/hooks/__tests__/useIsRobotBusy.test.ts

View workflow job for this annotation

GitHub Actions / js checks

'CurrentSubsystemUpdates' is defined but never used
} from '@opentrons/api-client'
import type { AxiosError } from 'axios'

jest.mock('@opentrons/react-api-client')
Expand Down Expand Up @@ -43,6 +52,9 @@ const mockUseNotifyCurrentMaintenanceRun = useNotifyCurrentMaintenanceRun as jes
const mockUseEstopQuery = useEstopQuery as jest.MockedFunction<
typeof useEstopQuery
>
const mockUseCurrentAllSubsystemUpdatesQuery = useCurrentAllSubsystemUpdatesQuery as jest.MockedFunction<
typeof useCurrentAllSubsystemUpdatesQuery
>
const mockUseIsFlex = useIsFlex as jest.MockedFunction<typeof useIsFlex>

describe('useIsRobotBusy', () => {
Expand All @@ -61,6 +73,18 @@ describe('useIsRobotBusy', () => {
data: {},
} as any)
mockUseEstopQuery.mockReturnValue({ data: mockEstopStatus } as any)
mockUseCurrentAllSubsystemUpdatesQuery.mockReturnValue({
data: {
data: [
{
id: '123',
createdAt: 'today',
subsystem: 'pipette_right',
updateStatus: 'done',
},
],
},
} as any)
mockUseIsFlex.mockReturnValue(false)
})

Expand Down Expand Up @@ -200,4 +224,20 @@ describe('useIsRobotBusy', () => {
const result = useIsRobotBusy()
expect(result).toBe(true)
})
it('returns true when a subsystem update is in progress', () => {
mockUseCurrentAllSubsystemUpdatesQuery.mockReturnValue({
data: {
data: [
{
id: '123',
createdAt: 'today',
subsystem: 'pipette_right',
updateStatus: 'updating',
},
],
},
} as any)
const result = useIsRobotBusy()
expect(result).toBe(true)
})
})
14 changes: 13 additions & 1 deletion app/src/organisms/Devices/hooks/useIsRobotBusy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
useAllSessionsQuery,
useEstopQuery,
useHost,
useCurrentAllSubsystemUpdatesQuery,
} from '@opentrons/react-api-client'

import { useNotifyCurrentMaintenanceRun } from '../../../resources/maintenance_runs/useNotifyCurrentMaintenanceRun'
Expand Down Expand Up @@ -33,12 +34,23 @@ export function useIsRobotBusy(
...queryOptions,
enabled: isFlex,
})
const {
data: currentSubsystemsUpdatesData,
} = useCurrentAllSubsystemUpdatesQuery({
refetchInterval: ROBOT_STATUS_POLL_MS,
})
const isSubsystemUpdating =
currentSubsystemsUpdatesData?.data.some(
update =>
update.updateStatus === 'queued' || update.updateStatus === 'updating'
) ?? false

return (
robotHasCurrentRun ||
isMaintenanceRunExisting ||
(allSessionsQueryResponse?.data?.data != null &&
allSessionsQueryResponse?.data?.data?.length !== 0) ||
(isFlex && estopStatus?.data.status !== DISENGAGED && estopError == null)
(isFlex && estopStatus?.data.status !== DISENGAGED && estopError == null) ||
isSubsystemUpdating
)
}

0 comments on commit 77e5e9c

Please sign in to comment.