Skip to content

Commit

Permalink
Merge pull request #58 from oskarpearson/master
Browse files Browse the repository at this point in the history
Pull sleep/wait changes from master to dev (and fix a typo)
  • Loading branch information
cjo20 authored Jan 28, 2017
2 parents 2b469d8 + f7ca8b2 commit 75890e7
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions mmeowlink/handlers/stick.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,10 @@ def __call__ (self, command, repetitions=None, ack_wait_seconds=None):
buf = pkt.assemble( )
log.debug('Sending repeated message %s' % (str(buf).encode('hex')))

self.link.write(buf, repetitions=repetitions)

# The radio takes a while to send all the packets, so wait for a bit before
# trying to talk to the radio, otherwise we can interrupt it.
#
# This multiplication factor is based on
# testing, which shows that it takes 8.04 seconds to send 500 packets
# (8.04/500 =~ 0.016 packets per second).
# We don't want to miss the reply, so take off a bit:
time.sleep((repetitions * 0.016) - 2.2)
self.link.write(buf, repetitions=repetitions, timeout=0.024 * repetitions)

try:
self.wait_for_ack()
self.wait_for_ack(timeout=ack_wait_seconds)
return True
except CommsException, InvalidPacketReceived:
log.error("%s - Response not received - retrying" % time.time())
Expand Down Expand Up @@ -216,14 +207,14 @@ def power_control (self, minutes=None):
# See if the pump is on and responding to messages. If it isn't, then
# we need to send a wakeup to the pump
if self.check_pump_awake():
log.info('Pump %s is already responding. Not sneding wakeup messages' % self.serial)
log.info('Pump %s is already responding. Not sending wakeup messages' % self.serial)
return True
else:
log.info('BEGIN POWER CONTROL %s' % self.serial)
self.command = commands.PowerControl(**dict(minutes=minutes, serial=self.serial))
repeater = Repeater(self.link)

status = repeater(self.command, repetitions=500, ack_wait_seconds=20)
status = repeater(self.command, repetitions=500, ack_wait_seconds=12)

if status:
return True
Expand Down

0 comments on commit 75890e7

Please sign in to comment.