Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions lib/abstract_miband.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import struct
import json
import re
Expand Down Expand Up @@ -217,7 +217,7 @@ def monitorHeartRateSleep(self, enable):
self.waitForNotifications(self.timeout)

def setMonitorHeartRateInterval(self, interval):
print "Setting heart rate measurement interval to %s minutes" % interval
print("Setting heart rate measurement interval to %s minutes" % interval)
self.char_hrm_ctrl.write(b'\x14' + struct.pack('B', interval), True)

def req_battery(self):
Expand Down Expand Up @@ -254,13 +254,13 @@ def setDisplayTimeFormat(self, format):
# Changes time display to 12h or 24h format
def setDisplayTimeHours(self, format):
if format == 12:
print "Enabling 12 hours Format..."
print("Enabling 12 hours Format...")
self.char_config.write(b'\x06\x02\x00\x00')
elif format == 24:
print "Enabling 24 hours Format..."
print("Enabling 24 hours Format...")
self.char_config.write(b'\x06\x02\x00\x01')
else:
print "Only 12 and 24 formats supported"
print("Only 12 and 24 formats supported")

def getLastSyncDate(self):
return self.lastSyncDate
Expand All @@ -282,9 +282,9 @@ def fetch_activity_data(self):

# If finished, we're good, if not, abort
if self.fetch_state == "FINISHED":
print "Finished Successfully!"
print("Finished Successfully!")
else:
print "Finished but something went wrong, not storing data"
print("Finished but something went wrong, not storing data")

# Return to FETCH state for the next time we fetch
self.fetch_state = "FETCH"
Expand Down Expand Up @@ -323,47 +323,47 @@ def send_alert(self, code):
self.char_alert.write(code)

def event_listen(self):
print ("Listening for any event")
print("Listening for any event")
while True:
self.waitForNotifications(self.timeout)

# Some simple events we have identified
def onEvent(self, data):
if data == 1:
print "Fell Asleep"
print("Fell Asleep")
elif data == 2:
print "Woke Up"
print("Woke Up")
elif data == 4:
print "Button Pressed"
print("Button Pressed")

# Alarms work as a queue, we can't read them, so they have to be stored locally
# Watch out for inconsistencies when using multiple clients (Shell/API)
def queueAlarm(self, hour, minute, repetitionMask=128, enableAlarm=True):
if len(self.alarms) >= 5:
print "Can't store more than 5 alarms at a time."
print("Can't store more than 5 alarms at a time.")
return -1
else:
alarm = MiBandAlarm(hour, minute, enabled=enableAlarm,
repetitionMask=repetitionMask)
self.alarms.append(alarm)
index = len(self.alarms)-1
print "Writing Alarm {0} at position {1}".format(str(alarm), index)
print("Writing Alarm {0} at position {1}".format(str(alarm), index))
self.char_config.write(alarm.getMessage(index))
self.waitForNotifications(self.timeout)
return index

# Modify alarm
def setAlarm(self, index, hour, minute, repetitionMask, enableAlarm):
if index >= len(self.alarms):
print "Alarm doesn't exist."
print("Alarm doesn't exist.")
return False
else:
if repetitionMask == 0:
repetitionMask = 128
alarm = MiBandAlarm(hour, minute, enabled=enableAlarm,
repetitionMask=repetitionMask)
self.alarms[index] = alarm
print "Writing Alarm {0} at position {1}".format(str(alarm), index)
print("Writing Alarm {0} at position {1}".format(str(alarm), index))
self.char_config.write(alarm.getMessage(index))
self.waitForNotifications(self.timeout)
return True
Expand All @@ -372,7 +372,7 @@ def setAlarm(self, index, hour, minute, repetitionMask, enableAlarm):
def toggleAlarm(self, index):
alarm = self.alarms[index]

print "{0} Alarm {1}".format("Enabling" if not alarm.enabled else "Disabling", str(alarm))
print("{0} Alarm {1}".format("Enabling" if not alarm.enabled else "Disabling", str(alarm)))
self.alarms[index].toggle()

self.char_config.write(alarm.getMessage(index))
Expand All @@ -383,7 +383,7 @@ def toggleAlarmDay(self, index, day):
alarm = self.alarms[index]

self.alarms[index].toggleDay(day)
print "Changing Alarm to {0}".format(str(alarm))
print("Changing Alarm to {0}".format(str(alarm)))

self.char_config.write(alarm.getMessage(index))
self.waitForNotifications(self.timeout)
Expand All @@ -393,7 +393,7 @@ def changeAlarmTime(self, index, hour, minute):

self.alarms[index].hour = hour
self.alarms[index].minute = minute
print "Changing Alarm to {0}".format(str(alarm))
print("Changing Alarm to {0}".format(str(alarm)))

self.char_config.write(alarm.getMessage(index))
self.waitForNotifications(self.timeout)
Expand All @@ -404,7 +404,7 @@ def deleteAlarm(self, index):

alarm = self.alarms[index]

print "Deleting alarm {0}".format(str(alarm))
print("Deleting alarm {0}".format(str(alarm)))
for i in range (index+1, len(self.alarms)):
alarm = self.alarms[i]
self.char_config.write(alarm.getMessage(i))
Expand All @@ -418,7 +418,7 @@ def deleteAlarm(self, index):
del self.alarms[index]

def cleanAlarms(self):
print "Clearing all alarms from device"
print("Clearing all alarms from device")
for i in range(10):
alarm = MiBandAlarm(0, 0, enabled=False)
self.char_config.write(alarm.getMessage(i))
Expand Down Expand Up @@ -597,7 +597,7 @@ def setGoalNotification(self, enable):
# ALEX MUCHO CUIDAO QUE LA LIAS
def factoryReset(self, force=False):
if not force:
print ("Factory resetting will wipe everything and change the device's MAC, use 'force' parameter if you know what you are doing")
print("Factory resetting will wipe everything and change the device's MAC, use 'force' parameter if you know what you are doing")
else:
print("Resetting Device...")
self.char_config.write(b'\x06\x0b\x00\x01')
Expand Down
10 changes: 5 additions & 5 deletions lib/miband2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import json
import array
from abstract_miband import AbstractMiBand
Expand Down Expand Up @@ -33,7 +33,7 @@ def get_model_delegate(self):
return MiBand2Delegate(self)

def setDisplayItems(self, steps=False, distance=False, calories=False, heartrate=False, battery=False):
print ("Setting display items to [{0}{1}{2}{3}{4}]...".format(
print("Setting display items to [{0}{1}{2}{3}{4}]...".format(
" STP" if steps else "", " DST" if distance else "", " CAL" if calories else "",
" HRT" if heartrate else "", " BAT" if battery else ""))

Expand All @@ -57,10 +57,10 @@ def setDisplayItems(self, steps=False, distance=False, calories=False, heartrate
# Changes time display to time or datetime
def setDisplayTimeFormat(self, format):
if format == "date":
print "Enabling Date Format..."
print("Enabling Date Format...")
self.char_config.write(b'\x06\x0a\x00\x03')
elif format == "time":
print "Enabling Time Format..."
print("Enabling Time Format...")
self.char_config.write(b'\x06\x0a\x00\x00')
else:
print "Only 'date' and 'time' formats supported"
print("Only 'date' and 'time' formats supported")
16 changes: 9 additions & 7 deletions lib/miband2delegate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import binascii
import struct
from bluepy.btle import DefaultDelegate
Expand Down Expand Up @@ -57,7 +59,7 @@ def handleNotification(self, hnd, data):

elif hasattr(self.device, 'char_battery') and hnd == self.device.char_battery.getHandle():
if data[:3] == b'\x10\x17\x01':
print "Success reading Battery Level"
print("Success reading Battery Level")
else:
print("Unhandled Battery Response " + hex(hnd) + ": " + str(binascii.hexlify(data)))

Expand Down Expand Up @@ -96,7 +98,7 @@ def handleNotification(self, hnd, data):
self.sessionBytes = 0
if (self.fetchDate.minutesUntilNow() > 0):
if (self.fetchCount >= 5):
print ("Fetched {0} rounds, not fetching any more now".format(self.fetchCount))
print("Fetched {0} rounds, not fetching any more now".format(self.fetchCount))
self.fetchCount = 0
self.sessionBytes = 0
self.totalBytes = 0
Expand Down Expand Up @@ -124,15 +126,15 @@ def handleNotification(self, hnd, data):

elif hasattr(self.device, 'char_config') and hnd == self.device.char_config.getHandle():
if data[:3] == b'\x10\x02\x04':
print "ERROR Configuring"
print("ERROR Configuring")
if data[:3] == b'\x10\x62\x05':
print "ERROR Configuring, too many parameters"
print("ERROR Configuring, too many parameters")
elif data[:3] == b'\x10\x02\x01':
print "SUCCESS Configuring Alarm Endpoint"
print("SUCCESS Configuring Alarm Endpoint")
elif data[:3] == b'\x10\x0a\x01':
print "SUCCESS Configuring Display Endpoint"
print("SUCCESS Configuring Display Endpoint")
elif data[0] == b'\x10' and data[-1] == b'\x01':
print "SUCCESS Configuring %s Endpoint" % str(binascii.hexlify(data[1:-1]))
print("SUCCESS Configuring %s Endpoint" % str(binascii.hexlify(data[1:-1])))
else:
print("Unhandled Configuration Response " + hex(hnd) + ": " + str(binascii.hexlify(data)))

Expand Down
6 changes: 3 additions & 3 deletions lib/miband3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import json
from abstract_miband import AbstractMiBand
from miband3delegate import MiBand3Delegate
Expand Down Expand Up @@ -32,9 +32,9 @@ def get_model_delegate(self):
return MiBand3Delegate(self)

def setDisplayItems(self, steps=False, distance=False, calories=False, heartrate=False, battery=False):
print "UNINMPLEMENTED FOR MB3"
print("UNINMPLEMENTED FOR MB3")
pass

def setDisplayTimeFormat(self, format):
print "CAN'T CHANGE TIME FORMAT ON MB3"
print("CAN'T CHANGE TIME FORMAT ON MB3")
pass
16 changes: 9 additions & 7 deletions lib/miband3delegate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import binascii
import struct
from bluepy.btle import DefaultDelegate
Expand Down Expand Up @@ -60,7 +62,7 @@ def handleNotification(self, hnd, data):

elif hasattr(self.device, 'char_battery') and hnd == self.device.char_battery.getHandle():
if data[:3] == b'\x10\x17\x01':
print "Success reading Battery Level"
print("Success reading Battery Level")
else:
print("Unhandled Battery Response " + hex(hnd) + ": " + str(binascii.hexlify(data)))

Expand Down Expand Up @@ -97,7 +99,7 @@ def handleNotification(self, hnd, data):
self.sessionBytes = 0
if (self.fetchDate.minutesUntilNow() > 0):
if (self.fetchCount >= 5):
print ("Fetched {0} rounds, not fetching any more now".format(self.fetchCount))
print("Fetched {0} rounds, not fetching any more now".format(self.fetchCount))
self.fetchCount = 0
self.sessionBytes = 0
self.totalBytes = 0
Expand Down Expand Up @@ -125,15 +127,15 @@ def handleNotification(self, hnd, data):

elif hasattr(self.device, 'char_config') and hnd == self.device.char_config.getHandle():
if data[:3] == b'\x10\x02\x04':
print "ERROR Configuring"
print("ERROR Configuring")
if data[:3] == b'\x10\x62\x05':
print "ERROR Configuring, too many parameters"
print("ERROR Configuring, too many parameters")
elif data[:3] == b'\x10\x02\x01':
print "SUCCESS Configuring Alarm Endpoint"
print("SUCCESS Configuring Alarm Endpoint")
elif data[:3] == b'\x10\x0a\x01':
print "SUCCESS Configuring Display Endpoint"
print("SUCCESS Configuring Display Endpoint")
elif data[0] == b'\x10' and data[-1] == b'\x01':
print "SUCCESS Configuring %s Endpoint" % str(binascii.hexlify(data[1:-1]))
print("SUCCESS Configuring %s Endpoint" % str(binascii.hexlify(data[1:-1])))
else:
print("Unhandled Configuration Response " + hex(hnd) + ": " + str(binascii.hexlify(data)))

Expand Down
Loading