Skip to content

Commit

Permalink
Removed open_packet to account for 150 temp in comm.
Browse files Browse the repository at this point in the history
  • Loading branch information
betterengineering committed Nov 13, 2015
1 parent 968fa7e commit e8e78c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
20 changes: 7 additions & 13 deletions freshroastsr700/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ def comm(self):

if len(r) == 14:
temp = int.from_bytes(bytes(r[10:-2]), byteorder='big')
if(temp > 550 or temp < 150):

if(temp == 65280):
self.current_temp = 150
elif(temp > 550 or temp < 150):
print("here")
self._initialize()
continue
else:
self.current_temp = temp

self.open_packet(r)
if(self.update_data_func is not None):
self.update_data_func(self)

Expand Down Expand Up @@ -211,17 +216,6 @@ def generate_packet(self):

return packet

def open_packet(self, packet):
"""Opens a packet received from the roaster and sets the temperature
accordingly. Since the roaster sends 65280 if the temperature is not
above 150, this method will set 65280 at 150."""
if(bytes(packet[10:-2]) == (b'\xff\x00')):
self.current_temp = 150
return

self.current_temp = int.from_bytes(
bytes(packet[10:-2]), byteorder='big')

def idle(self):
"""Sets the current state of the roaster to idle."""
self._current_state = b'\x02\x01'
Expand Down
10 changes: 0 additions & 10 deletions tests/test_freshroastsr700.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@ def test_generate_packet(self):
self.assertEqual(
packet, b'\xaa\xaaatc\x02\x01\x01\x00\x00\x00\x00\xaa\xfa')

def test_open_packet_not_150(self):
self.roaster.open_packet(
b'\xaa\xaaatc\x02\x01\x01\x00\x00\x01\x60\xaa\xfa')
self.assertEqual(self.roaster.current_temp, 352)

def test_open_packet_before_over_150(self):
self.roaster.open_packet(
b'\xaa\xaaatc\x02\x01\x01\x00\x00\xff\x00\xaa\xfa')
self.assertEqual(self.roaster.current_temp, 150)

def test_idle(self):
self.roaster.idle()
self.assertEqual(self.roaster._current_state, b'\x02\x01')
Expand Down

0 comments on commit e8e78c0

Please sign in to comment.