async def set_advanced_setting(request: web.Request) -> web.Response: """ Handles a POST request with a json body that has keys "id" and "value", where the value of "id" must correspond to an id field of a setting in `opentrons.config.advanced_settings.settings`. Saves the value of "value" for the setting that matches the supplied id. """ data = await request.json() key = data.get('id') value = data.get('value') log.info(f'set_advanced_setting: {key} -> {value}') if key and key in advs.settings_by_id.keys(): advs.set_adv_setting(key, value) res = _get_adv_settings() status = 200 if key == 'disableLogAggregation'\ and ARCHITECTURE == SystemArchitecture.BUILDROOT: code, stdout, stderr = await log_control.set_syslog_level( 'emerg' if value else 'info') if code != 0: log.error(f"Could not set log control: {code}: stdout={stdout}" f" stderr={stderr}") res = {'message': 'Failed to set log upstreaming: {code}'} status = 500 log.error(res) else: res = {'message': 'ID {} not found in settings list'.format(key)} status = 400 log.info(f'set_advanced_setting: bad request: {key} invalid') return web.json_response(res, status=status)
def test_new_deck_points(): # Checks that the correct deck calibration points are being used # if feature_flag is set (or not) advs.set_adv_setting('deckCalibrationDots', True) calibration_points = get_calibration_points() expected_points1 = expected_points() # Check that old calibration points are used in cli assert calibration_points[1] == (12.13, 6.0) assert calibration_points[2] == (380.87, 6.0) assert calibration_points[3] == (12.13, 351.5) # Check that endpoints are now using slot 7 for dots assert expected_points1['1'] == (12.13, 6.0) assert expected_points1['2'] == (380.87, 6.0) assert expected_points1['3'] == (12.13, 261.0) advs.set_adv_setting('deckCalibrationDots', False) calibration_points2 = get_calibration_points() expected_points2 = expected_points() # Check that new calibration points are used assert calibration_points2[1] == (12.13, 9.0) assert calibration_points2[2] == (380.87, 9.0) assert calibration_points2[3] == (12.13, 348.5) # Check that endpoints are now using slot 7 for crosses assert expected_points2['1'] == (12.13, 9.0) assert expected_points2['2'] == (380.87, 9.0) assert expected_points2['3'] == (12.13, 258.0)
async def set_advanced_setting(request: web.Request) -> web.Response: """ Set a specific advanced setting. The "id" field must correspond to an id field of a setting in `opentrons.config.advanced_settings.settings`. Saves the value of "value" for the setting that matches the supplied id. The response body includes the new settings in the same format as GET /settings, and a "links" object that may contain a "restart" key. If the "restart" key is present, the client should restart the robot, and the value is a URI that will do so. POST /settings {"id": short-id, "value": tristate new-value} -> 400 Bad Request {"error": error-shortname, "message": str} -> 500 Internal Server Error {"error": "error-shortname", "message": str} -> 200 OK {"settings": (as GET /settings), "links": {"restart": uri if restart required}} """ global _SETTINGS_RESTART_REQUIRED data = await request.json() key = data.get('id') value = data.get('value') log.info(f'set_advanced_setting: {key} -> {value}') setting = advs.settings_by_id.get(key) if not setting: log.warning(f'set_advanced_setting: bad request: {key} invalid') return web.json_response( { 'error': 'no-such-advanced-setting', 'message': f'ID {key} not found in settings list', 'links': {} }, status=400) old_val = advs.get_adv_setting(key) advs.set_adv_setting(key, value) if key == 'disableLogAggregation'\ and ARCHITECTURE == SystemArchitecture.BUILDROOT: code, stdout, stderr = await log_control.set_syslog_level( 'emerg' if value else 'info') if code != 0: log.error(f"Could not set log control: {code}: stdout={stdout}" f" stderr={stderr}") return web.json_response( { 'error': 'log-config-failure', 'message': 'Failed to set log upstreaming: {code}' }, status=500) _SETTINGS_RESTART_REQUIRED = _SETTINGS_RESTART_REQUIRED or ( setting.restart_required and old_val != value) return web.json_response( _get_adv_settings_response(), status=200, )
async def set_advanced_setting(request: web.Request) -> web.Response: """ Handles a POST request with a json body that has keys "id" and "value", where the value of "id" must correspond to an id field of a setting in `opentrons.config.advanced_settings.settings`. Saves the value of "value" for the setting that matches the supplied id. """ data = await request.json() key = data.get('id') value = data.get('value') if key and key in advs.settings_by_id.keys(): advs.set_adv_setting(key, value) res = _get_adv_settings() status = 200 else: res = {'message': 'ID {} not found in settings list'.format(key)} status = 400 return web.json_response(res, status=status)