<commit_before>import asyncio
import logging
import os
import threading
from queue import Queue
try:
    import select
except ModuleNotFoundError:
    select = None  # type: ignore
from time import sleep
from typing import Optional, Mapping
from serial.serialutil import SerialException  # type: ignore
from opentrons.drivers import serial_communication, utils
from opentrons.drivers.serial_communication import SerialNoResponse


log = logging.getLogger(__name__)

GCODES = {
    'OPEN_LID': 'M126',
    'CLOSE_LID': 'M127',
    'GET_LID_STATUS': 'M119',
    'SET_LID_TEMP': 'M140',
    'GET_LID_TEMP': 'M141',
    'DEACTIVATE_LID_HEATING': 'M108',
    'EDIT_PID_PARAMS': 'M301',
    'SET_PLATE_TEMP': 'M104',
    'GET_PLATE_TEMP': 'M105',
    'SET_RAMP_RATE': 'M566',
    'DEACTIVATE': 'M18',
    'DEVICE_INFO': 'M115'
}
LID_TARGET_DEFAULT = 105    # Degree celsius
LID_TARGET_MIN = 20
LID_TARGET_MAX = 105
TEMP_UPDATE_RETRIES = 15


def _build_temp_code(temp, hold_time=None):
    if temp < 0:
        temp = 0
    if temp > 99:
        temp = 99
    cmd = '{} S{}'.format(GCODES['SET_PLATE_TEMP'], temp)
    if hold_time:
        cmd += ' H{}'.format(hold_time)
    return cmd, temp


TC_BAUDRATE = 115200
# TODO (Laura 20190327) increased the thermocycler command timeout
# temporarily until we can change the firmware to asynchronously handle
# the lid being open and closed
SERIAL_ACK = '\r\n'
TC_COMMAND_TERMINATOR = SERIAL_ACK
TC_ACK = 'ok' + SERIAL_ACK + 'ok' + SERIAL_ACK
ERROR_KEYWORD = 'error'
DEFAULT_TC_TIMEOUT = 40<commit_msg>refactor(api): clamp tc lid temp to 37 thru 110 (#4073)<commit_after>import asyncio
import logging
import os
import threading
from queue import Queue
try:
    import select
except ModuleNotFoundError:
    select = None  # type: ignore
from time import sleep
from typing import Optional, Mapping
from serial.serialutil import SerialException  # type: ignore
from opentrons.drivers import serial_communication, utils
from opentrons.drivers.serial_communication import SerialNoResponse


log = logging.getLogger(__name__)

GCODES = {
    'OPEN_LID': 'M126',
    'CLOSE_LID': 'M127',
    'GET_LID_STATUS': 'M119',
    'SET_LID_TEMP': 'M140',
    'GET_LID_TEMP': 'M141',
    'DEACTIVATE_LID_HEATING': 'M108',
    'EDIT_PID_PARAMS': 'M301',
    'SET_PLATE_TEMP': 'M104',
    'GET_PLATE_TEMP': 'M105',
    'SET_RAMP_RATE': 'M566',
    'DEACTIVATE': 'M18',
    'DEVICE_INFO': 'M115'
}
LID_TARGET_DEFAULT = 105    # Degree celsius
LID_TARGET_MIN = 37
LID_TARGET_MAX = 110
TEMP_UPDATE_RETRIES = 15


def _build_temp_code(temp, hold_time=None):
    if temp < 0:
        temp = 0
    if temp > 99:
        temp = 99
    cmd = '{} S{}'.format(GCODES['SET_PLATE_TEMP'], temp)
    if hold_time:
        cmd += ' H{}'.format(hold_time)
    return cmd, temp


TC_BAUDRATE = 115200
# TODO (Laura 20190327) increased the thermocycler command timeout
# temporarily until we can change the firmware to asynchronously handle
# the lid being open and closed
SERIAL_ACK = '\r\n'
TC_COMMAND_TERMINATOR = SERIAL_ACK
TC_ACK = 'ok' + SERIAL_ACK + 'ok' + SERIAL_ACK
ERROR_KEYWORD = 'error'
DEFAULT_TC_TIMEOUT = 40
{'fraction_non_alphanumeric': 0.10428662827895073, 'fraction_numerical': 0.045745361484325016, 'mean_word_length': 4.194352159468439, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5621366', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1110, 'n_words': 296}