Skip to content

Commit

Permalink
Issue #4 brought to light some serious stupid in maths.
Browse files Browse the repository at this point in the history
Fix the iteration code for button pushes, now we actually iterate properly.
Fix the maths on the pump status, somewhere along the line I screwed this up.
Add a test in __main__ to play with the pump.
  • Loading branch information
garbled1 committed May 30, 2020
1 parent 541df73 commit 687171b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
33 changes: 33 additions & 0 deletions pybalboa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,39 @@ async def mini_engine(spahost):
await asyncio.sleep(2)
print("Current temp should be set back to {0} is: {1}".format(save_my_temp, spa.get_settemp()))

print("Letting the spa settle....")
await asyncio.sleep(2)

print("Trying to operate pump 0 (first pump)")
print("Current state = {0}".format(spa.get_pump(0, text=True)))
print("Set to low")
await spa.change_pump(0, 1)
await asyncio.sleep(2)
print("Current state = {0}".format(spa.get_pump(0, text=True)))
print("Pump Status: {0}".format(str(spa.pump_status)))

print(" ok, next")
print("Set to off")
await spa.change_pump(0, 0)
await asyncio.sleep(2)
print("Current state = {0}".format(spa.get_pump(0, text=True)))
print("Pump Status: {0}".format(str(spa.pump_status)))

print(" ok, next")
print("Set to high")
await spa.change_pump(0, 2)
await asyncio.sleep(2)
print("Current state = {0}".format(spa.get_pump(0, text=True)))
print("Pump Status: {0}".format(str(spa.pump_status)))
print(" ok, next")

print("Set to off")
await spa.change_pump(0, 0)
await asyncio.sleep(2)
print("Current state = {0}".format(spa.get_pump(0, text=True)))
print("Pump Status: {0}".format(str(spa.pump_status)))
print("Done")

await spa.disconnect()
return

Expand Down
12 changes: 6 additions & 6 deletions pybalboa/balboa.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,20 +344,20 @@ async def change_pump(self, pump, newstate):

# calculate how many times to push the button
if self.pump_array[pump] == 2:
for iter in range(0, 2):
for iter in range(1, 2+1):
if newstate == ((self.pump_status[pump] + iter) % 3):
break
else:
iter = 1

# now push the button until we hit desired state
for pushes in range(0, iter):
for pushes in range(1, iter+1):
# 4 is 0, 5 is 2, presume 6 is 3?
data[5] = C_PUMP1 + pump
data[7] = self.balboa_calc_cs(data[1:], 6)
self.writer.write(data)
await self.writer.drain()
await asyncio.sleep(0.5)
await asyncio.sleep(1.0)

async def change_heatmode(self, newmode):
""" Change the spa's heatmode to newmode. """
Expand Down Expand Up @@ -702,9 +702,9 @@ async def parse_status_update(self, data):
continue
# 1-4 are in one byte, 5/6 are in another
if i < 4:
self.pump_status[i] = (data[16] >> i) & 0x03
self.pump_status[i] = (data[16] >> i*2) & 0x03
else:
self.pump_status[i] = (data[17] >> (i - 4)) & 0x03
self.pump_status[i] = (data[17] >> ((i - 4)*2)) & 0x03

if self.circ_pump:
if data[18] == 0x02:
Expand Down Expand Up @@ -778,7 +778,7 @@ async def read_one_message(self):
self.log.error('Message had bad CRC, discarding')
return None

# self.log.debug(full_data.hex())
# self.log.error('got update: {}'.format(full_data.hex()))
return full_data

async def check_connection_status(self):
Expand Down

0 comments on commit 687171b

Please sign in to comment.