Skip to content

Commit

Permalink
refactor(api,robot-server): Make reset opts for cal (#6788)
Browse files Browse the repository at this point in the history
While we may change this with an actual UX-design inspired approach, for
now let's just add some options to make the user actually able to reset
the calibrations, somehow.

Co-authored-by: Brian Arthur Cooper <[email protected]>
  • Loading branch information
sfoster1 and b-cooper authored Oct 15, 2020
1 parent 4b9e582 commit ee3d122
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 27 deletions.
11 changes: 11 additions & 0 deletions api/src/opentrons/calibration_storage/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,14 @@ def _remove_json_files_in_directories(p: Path):
_remove_json_files_in_directories(offset_dir)
except FileNotFoundError:
pass


def delete_robot_deck_attitude():
"""
Delete the robot deck attitude calibration.
"""

robot_dir = config.get_opentrons_path('robot_calibration_dir')
gantry_path = robot_dir / 'deck_calibration.json'
if gantry_path.exists():
gantry_path.unlink()
71 changes: 61 additions & 10 deletions api/src/opentrons/config/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ class ResetOptionId(str, Enum):
tip_probe = 'tipProbe'
labware_calibration = 'labwareCalibration'
boot_scripts = 'bootScripts'
deck_calibration = 'deckCalibration'
pipette_offset = 'pipetteOffsetCalibrations'
tip_length_calibrations = 'tipLengthCalibrations'


_common_settings_reset_options = {
ResetOptionId.tip_probe:
CommonResetOption(
name='Pipette Calibration',
description='Clear pipette offset and tip length calibration'
),
ResetOptionId.labware_calibration:
CommonResetOption(
name='Labware Calibration',
Expand All @@ -49,9 +47,42 @@ class ResetOptionId(str, Enum):
),
}

_legacy_cal_reset_options = {
ResetOptionId.tip_probe:
CommonResetOption(
name='Pipette Calibration',
description='Clear pipette offset and tip length calibration'
),
}

_cal_overhaul_reset_options = {
ResetOptionId.deck_calibration:
CommonResetOption(
name='Deck Calibration',
description='Clear deck calibration (will also clear pipette '
'offset)'
),
ResetOptionId.pipette_offset:
CommonResetOption(
name='Pipette Offset Calibrations',
description='Clear pipette offset calibrations'
),
ResetOptionId.tip_length_calibrations:
CommonResetOption(
name='Tip Length Calibrations',
description='Clear tip length calibrations (will also clear '
'pipette offset)'
)
}


def reset_options() -> Dict[ResetOptionId, CommonResetOption]:
return _common_settings_reset_options
options = {k: v for k, v in _common_settings_reset_options.items()}
if ff.enable_calibration_overhaul():
options.update(_cal_overhaul_reset_options)
else:
options.update(_legacy_cal_reset_options)
return options


def reset(options: Set[ResetOptionId]) -> None:
Expand All @@ -70,6 +101,15 @@ def reset(options: Set[ResetOptionId]) -> None:
if ResetOptionId.boot_scripts in options:
reset_boot_scripts()

if ResetOptionId.deck_calibration in options:
reset_deck_calibration()

if ResetOptionId.pipette_offset in options:
reset_pipette_offset()

if ResetOptionId.tip_length_calibrations in options:
reset_tip_length_calibrations()


def reset_boot_scripts():
if IS_ROBOT:
Expand All @@ -79,6 +119,20 @@ def reset_boot_scripts():
log.debug(f'Not on pi, not removing {DATA_BOOT_D}')


def reset_deck_calibration():
delete.delete_robot_deck_attitude()
delete.clear_pipette_offset_calibrations()


def reset_pipette_offset():
delete.clear_pipette_offset_calibrations()


def reset_tip_length_calibrations():
delete.clear_tip_length_calibration()
delete.clear_pipette_offset_calibrations()


def reset_labware_calibration():
delete.clear_calibrations()
db.reset()
Expand All @@ -88,8 +142,5 @@ def reset_tip_probe():
config = rc.load()
config = config._replace(
instrument_offset=rc.build_fallback_instrument_offset({}))
if ff.enable_calibration_overhaul():
delete.clear_tip_length_calibration()
else:
config.tip_length.clear()
config.tip_length.clear()
rc.save_robot_settings(config)
62 changes: 60 additions & 2 deletions robot-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def set_up_index_file_temporary_directory(server_temp_directory):
labware.save_calibration(lw, Point(0, 0, 0))


@pytest.fixture
@pytest.fixture(scope="function")
def set_up_pipette_offset_temp_directory(server_temp_directory):
pip_list = ['pip_1', 'pip_2']
mount_list = [Mount.LEFT, Mount.RIGHT]
Expand All @@ -157,7 +157,7 @@ def set_up_pipette_offset_temp_directory(server_temp_directory):
tiprack_uri='uri')


@pytest.fixture
@pytest.fixture(scope="function")
def set_up_tip_length_temp_directory(server_temp_directory):
pip_list = ['pip_1', 'pip_2']
tiprack_hash = 'fakehash'
Expand Down Expand Up @@ -200,3 +200,61 @@ def _get_labware_fixture(fixture_name):
return json.loads(f.read().decode('utf-8'))

return _get_labware_fixture


@pytest.fixture
def tavern_enable_calibration_overhaul(run_server):
"""For integration tests that need to set then clear the
enableTiplengthCalibration feature flag"""
url = "http://localhost:31950/settings"
data = {
"id": "enableTipLengthCalibration",
"value": True
}
requests.post(url, json=data)
yield None
data['value'] = None
requests.post(url, json=data)


@pytest.fixture
def tavern_disable_calibration_overhaul(run_server):
"""For integration tests that need to set then clear the
enableTiplengthCalibration feature flag"""
url = "http://localhost:31950/settings"
data = {
"id": "enableTipLengthCalibration",
"value": False
}
requests.post(url, json=data)
yield None
data['value'] = None
requests.post(url, json=data)


@pytest.fixture
def apiclient_enable_calibration_overhaul(api_client):
"""For integration tests that need to set then clear the
enableTiplengthCalibration feature flag"""
data = {
"id": "enableTipLengthCalibration",
"value": True
}
api_client.post(url='/settings', json=data)
yield None
data['value'] = None
api_client.post('/settings', json=data)


@pytest.fixture
def apiclient_disable_calibration_overhaul(api_client):
"""For integration tests that need to set then clear the
enableTiplengthCalibration feature flag"""
data = {
"id": "enableTipLengthCalibration",
"value": False
}
api_client.post('/settings', json=data)
yield None
data['value'] = None
api_client.post('/settings', json=data)
115 changes: 113 additions & 2 deletions robot-server/tests/integration/test_settings_reset_options.tavern.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
test_name: GET Settings Reset Options
test_name: GET Settings Reset Options legacy
marks:
- usefixtures:
- run_server
- tavern_disable_calibration_overhaul
stages:
- name: Reset Options GET request returns correct option
request:
Expand All @@ -12,20 +13,52 @@ stages:
status_code: 200
json:
options:
- id: labwareCalibration
name: Labware Calibration
description: !re_search "Clear labware calibration and Protocol API v1 custom labware"
- id: bootScripts
name: Boot Scripts
description: Clear custom boot scripts
- id: tipProbe
name: Pipette Calibration
description: Clear pipette offset and tip length calibration

---
test_name: GET Settings Reset Options cal overhaul
marks:
- usefixtures:
- run_server
- tavern_enable_calibration_overhaul
stages:
- name: Reset Options GET request returns correct option
request:
url: "{host:s}:{port:d}/settings/reset/options"
method: GET
response:
status_code: 200
json:
options:
- id: labwareCalibration
name: Labware Calibration
description: !re_search "Clear labware calibration and Protocol API v1 custom labware"
- id: bootScripts
name: Boot Scripts
description: Clear custom boot scripts
- id: deckCalibration
name: Deck Calibration
description: !re_search "Clear deck calibration"
- id: pipetteOffsetCalibrations
name: Pipette Offset Calibrations
description: !re_search "Clear pipette offset calibrations"
- id: tipLengthCalibrations
name: Tip Length Calibrations
description: !re_search "Clear tip length calibrations"
---
test_name: POST Reset tipProbe option
marks:
- usefixtures:
- run_server
- tavern_disable_calibration_overhaul
stages:
- name: POST Reset tipProbe true
request:
Expand Down Expand Up @@ -100,12 +133,90 @@ stages:
json:
message: "Nothing to do"
---
test_name: POST Reset deck calibration option
marks:
- usefixtures:
- run_server
stages:
- name: POST Reset deckCalibration true
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
json:
deckCalibration: true
response:
status_code: 200
json:
message: "Options 'deck_calibration' were reset"
- name: POST Reset deckCalibration false
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
json:
deckCalibration: false
response:
status_code: 200
json:
message: "Nothing to do"
---
test_name: POST Reset pipette offset calibrations option
marks:
- usefixtures:
- run_server
stages:
- name: POST Reset pipetteOffsetCalibrations true
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
json:
pipetteOffsetCalibrations: true
response:
status_code: 200
json:
message: "Options 'pipette_offset' were reset"
- name: POST Reset pipetteOffsetCalibrations false
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
json:
pipetteOffsetCalibrations: false
response:
status_code: 200
json:
message: "Nothing to do"
---
test_name: POST Reset tip length calibrations option
marks:
- usefixtures:
- run_server
stages:
- name: POST Reset tipLengthCalibrations true
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
json:
tipLengthCalibrations: true
response:
status_code: 200
json:
message: "Options 'tip_length_calibrations' were reset"
- name: POST Reset tipLengthCalibrations false
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
json:
tipLengthCalibrations: false
response:
status_code: 200
json:
message: "Nothing to do"
---
test_name: POST Reset all options
marks:
- usefixtures:
- run_server
stages:
- name: POST Reset all options
- name: POST Reset all options (legacy)
request:
url: "{host:s}:{port:d}/settings/reset"
method: POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from unittest.mock import MagicMock, call, patch
from typing import List, Tuple, Dict, Any
from opentrons.calibration_storage import modify, helpers, types as CSTypes
from opentrons.calibration_storage import helpers, types as CSTypes
from opentrons.types import Mount, Point
from opentrons.hardware_control import pipette
from opentrons.config.pipette_config import load
Expand Down Expand Up @@ -304,14 +304,15 @@ def test_no_pipette(hardware, mount):
assert error.value.error.detail == f"No pipette present on {mount} mount"


async def test_save_pipette_calibration(mock_user_flow):
uf = mock_user_flow
@pytest.fixture
def mock_save_pipette():
with patch('opentrons.calibration_storage.modify.save_pipette_calibration',
autospec=True) as mock_save:
yield mock_save

def mock_save_pipette_offset(*args, **kwargs):
pass

modify.save_pipette_calibration = \
MagicMock(side_effect=mock_save_pipette_offset)
async def test_save_pipette_calibration(mock_user_flow, mock_save_pipette):
uf = mock_user_flow

uf._current_state = 'savingPointOne'
await uf._hardware.move_to(
Expand All @@ -325,7 +326,7 @@ def mock_save_pipette_offset(*args, **kwargs):
uf._tip_rack._implementation.get_definition()
)
offset = uf._cal_ref_point - Point(x=10, y=10, z=40)
modify.save_pipette_calibration.assert_called_with(
mock_save_pipette.assert_called_with(
offset=offset,
mount=uf._mount,
pip_id=uf._hw_pipette.pipette_id,
Expand Down
Loading

0 comments on commit ee3d122

Please sign in to comment.