Skip to content

Commit dc77ade

Browse files
committed
smartdry: Check if 'volt' is not None before comparison, and before sending the update
1 parent 3120c4e commit dc77ade

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

custom_components/ble_monitor/ble_parser/smartdry.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@ def parse_smartdry(self, data: bytes, mac: str):
3535
else:
3636
volt = None
3737

38-
if volt >= 3.00:
39-
batt = 100
40-
elif volt >= 2.60:
41-
batt = 60 + (volt - 2.60) * 100
42-
elif volt >= 2.50:
43-
batt = 40 + (volt - 2.50) * 200
44-
elif volt >= 2.45:
45-
batt = 20 + (volt - 2.45) * 400
46-
else:
47-
batt = 0
48-
if volt:
38+
batt = None
39+
40+
if volt is not None:
41+
if volt >= 3.00:
42+
batt = 100
43+
elif volt >= 2.60:
44+
batt = 60 + (volt - 2.60) * 100
45+
elif volt >= 2.50:
46+
batt = 40 + (volt - 2.50) * 200
47+
elif volt >= 2.45:
48+
batt = 20 + (volt - 2.45) * 400
49+
else:
50+
batt = 0
51+
52+
if volt is not None:
4953
result.update({
5054
"voltage": volt,
5155
"battery": batt

0 commit comments

Comments
 (0)