Skip to content

Commit

Permalink
smartdry: Check if 'volt' is not None before comparison, and before s…
Browse files Browse the repository at this point in the history
…ending the update
  • Loading branch information
yoavf committed Feb 27, 2024
1 parent 3120c4e commit dc77ade
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions custom_components/ble_monitor/ble_parser/smartdry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ def parse_smartdry(self, data: bytes, mac: str):
else:
volt = None

if volt >= 3.00:
batt = 100
elif volt >= 2.60:
batt = 60 + (volt - 2.60) * 100
elif volt >= 2.50:
batt = 40 + (volt - 2.50) * 200
elif volt >= 2.45:
batt = 20 + (volt - 2.45) * 400
else:
batt = 0
if volt:
batt = None

if volt is not None:
if volt >= 3.00:
batt = 100
elif volt >= 2.60:
batt = 60 + (volt - 2.60) * 100
elif volt >= 2.50:
batt = 40 + (volt - 2.50) * 200
elif volt >= 2.45:
batt = 20 + (volt - 2.45) * 400
else:
batt = 0

if volt is not None:
result.update({
"voltage": volt,
"battery": batt
Expand Down

0 comments on commit dc77ade

Please sign in to comment.