Skip to content

Commit

Permalink
fix(api): Allows floating-point temperatures to be set/read to/from t…
Browse files Browse the repository at this point in the history
…emp-deck (#1798)
  • Loading branch information
andySigler authored Jul 2, 2018
1 parent f9b1dee commit 856134a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions api/opentrons/drivers/temp_deck/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
TEMP_DECK_COMMAND_TERMINATOR = '\r\n\r\n'
TEMP_DECK_ACK = 'ok\r\nok\r\n'

# Number of digits after the decimal point for temperatures being sent
# to/from Temp-Deck
GCODE_ROUNDING_PRECISION = 3


class TempDeckError(Exception):
pass
Expand All @@ -64,7 +68,7 @@ def _parse_string_value_from_substring(substring) -> str:
substring))


def _parse_number_from_substring(substring) -> int:
def _parse_number_from_substring(substring) -> float:
'''
Returns the number in the expected string "N:12.3", where "N" is the
key, and "12.3" is a floating point value
Expand All @@ -76,7 +80,7 @@ def _parse_number_from_substring(substring) -> int:
value = substring.split(':')[1]
if value.strip().lower() == 'none':
return None
return int(value)
return round(float(value), GCODE_ROUNDING_PRECISION)
except (ValueError, IndexError, TypeError, AttributeError):
log.exception('Unexpected argument to _parse_number_from_substring:')
raise ParseError(
Expand Down Expand Up @@ -202,8 +206,9 @@ def disengage(self) -> str:
def set_temperature(self, celsius) -> str:
self.run_flag.wait()
try:
celsius = round(float(celsius), GCODE_ROUNDING_PRECISION)
self._send_command(
'{0} S{1}'.format(GCODES['SET_TEMP'], int(celsius)))
'{0} S{1}'.format(GCODES['SET_TEMP'], celsius))
except (TempDeckError, SerialException, SerialNoResponse) as e:
return str(e)
return ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def _mock_send_command(self, command, timeout=None):
temp_deck._send_command = types.MethodType(_mock_send_command, temp_deck)

temp_deck.set_temperature(99)
assert command_log[-1] == 'M104 S99'
assert command_log[-1] == 'M104 S99.0'

temp_deck.set_temperature(-9)
assert command_log[-1] == 'M104 S-9'
assert command_log[-1] == 'M104 S-9.0'


def test_fail_set_temp_deck_temperature(monkeypatch):
Expand Down

0 comments on commit 856134a

Please sign in to comment.