async def test_override(attached_pipettes): # This test will check that setting modified pipette configs # works as expected changes = {'pickUpCurrent': 1} test_id = attached_pipettes['left']['id'] # Check data has not been changed yet c, _ = pipette_config.load_config_dict(test_id) assert c['pickUpCurrent'] == \ pipette_config.list_mutable_configs( pipette_id=test_id)['pickUpCurrent'] # Check that data is changed and matches the changes specified pipette_config.override(pipette_id=test_id, fields=changes) c, _ = pipette_config.load_config_dict(test_id) assert c['pickUpCurrent']['value'] == changes['pickUpCurrent'] # Check that None reverts a setting to default changes2 = {'pickUpCurrent': None} # Check that data is changed and matches the changes specified pipette_config.override(pipette_id=test_id, fields=changes2) c, _ = pipette_config.load_config_dict(test_id) assert c['pickUpCurrent']['value'] == \ pipette_config.list_mutable_configs( pipette_id=test_id)['pickUpCurrent']['default']
async def modify_pipette_settings(request: web.Request) -> web.Response: """ Expects a dictionary with mutable configs wrapped in a `fields` key such as: { 'fields': { 'pickUpCurrent': {'value': some_value}, 'dropTipSpeed': {'value': some_value} } } If a value needs to be reset, simply type in the body formatted as above: 'configKey': null } """ pipette_id = request.match_info['id'] whole_config = pc.load_config_dict(pipette_id) config_match = pc.list_mutable_configs(pipette_id) data = await request.json() if not data.get('fields'): return web.json_response(config_match, status=200) for key, value in data['fields'].items(): if value and not isinstance(value['value'], bool): config = value['value'] default = config_match[key] if config < default['min'] or config > default['max']: return web.json_response( {'message': '{} out of range with {}'.format(key, config)}, status=412) pc.save_overrides(pipette_id, data['fields'], whole_config.get('model')) updated_configs = {'fields': pc.list_mutable_configs(pipette_id)} return web.json_response(updated_configs, status=200)
def _make_pipette_response_body(pipette_id): whole_config = pc.load_config_dict(pipette_id) res = { 'info': { 'name': whole_config.get('name'), 'model': whole_config.get('model') }, 'fields': pc.list_mutable_configs(pipette_id) } return res
async def pipette_settings(request: web.Request) -> web.Response: res = {} for id in pc.known_pipettes(): whole_config = pc.load_config_dict(id) res[id] = { 'info': { 'name': whole_config.get('name'), 'model': whole_config.get('model') }, 'fields': pc.list_mutable_configs(pipette_id=id) } return web.json_response(res, status=200)
async def pipette_settings_id(request: web.Request) -> web.Response: pipette_id = request.match_info['id'] if pipette_id not in pc.known_pipettes(): return web.json_response( {'message': '{} is not a valid pipette id'.format(pipette_id)}, status=404) whole_config = pc.load_config_dict(pipette_id) res = { 'info': { 'name': whole_config.get('name'), 'model': whole_config.get('model') }, 'fields': pc.list_mutable_configs(pipette_id) } return web.json_response(res, status=200)