Skip to content

Commit

Permalink
Merge pull request #19 from jorisvaesen/patch-1
Browse files Browse the repository at this point in the history
Fix battery level above 100%
  • Loading branch information
JsBergbau authored Feb 28, 2020
2 parents b57b4b0 + b5d1043 commit 1728dee
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions LYWSD03MMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def handleNotification(self, cHandle, data):
measurement.voltage = voltage
if args.battery:
#measurement.battery = globalBatteryLevel
batteryLevel = int(round((voltage - 2.1),2) * 100) #3.1 or above --> 100% 2.1 --> 0 %
batteryLevel = min(int(round((voltage - 2.1),2) * 100), 100) #3.1 or above --> 100% 2.1 --> 0 %
measurement.battery = batteryLevel
print("Battery level:",batteryLevel)

Expand Down Expand Up @@ -313,4 +313,4 @@ def connect():
logging.debug(traceback.format_exc())

print ("Waiting...")
# Perhaps do something else here
# Perhaps do something else here

0 comments on commit 1728dee

Please sign in to comment.