Skip to content

Commit 13cf6a2

Browse files
pre-commit-ci[bot]henryk
authored andcommitted
chore(pre-commit.ci): auto fixes
1 parent d433137 commit 13cf6a2

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/thermopro_ble/parser.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
ABSOLUTE_MAX_HUMIDITY__PERCENTAGE = 100
3535
ABSOLUTE_MIN_TEMPERATURE__CELCIUS = -273.15
3636

37+
3738
# TP96x battery values appear to be a voltage reading, probably in millivolts.
3839
# This means that calculating battery life from it is a non-linear function.
3940
# Examining the curve, it looked fairly close to a curve from the tanh function.
@@ -45,16 +46,22 @@ def tp96_battery(voltage: int) -> float:
4546
clamped = max(0, min(raw, 100))
4647
return round(clamped, 2)
4748

48-
def is_temp_hum_invalid(temperature: Union[int, float], humidity: Union[int, float]) -> bool:
49+
50+
def is_temp_hum_invalid(temperature: int | float, humidity: int | float) -> bool:
4951
"""Returns true if the measured values are outside the physically possible range."""
5052
# Note: This will not catch implausibly high temperature values, but a clear
5153
# upper temperature cutoff is not easy to define
5254
if temperature < ABSOLUTE_MIN_TEMPERATURE__CELCIUS:
5355
return True
54-
if not (ABSOLUTE_MIN_HUMIDITY__PERCENTAGE <= humidity <= ABSOLUTE_MAX_HUMIDITY__PERCENTAGE):
56+
if not (
57+
ABSOLUTE_MIN_HUMIDITY__PERCENTAGE
58+
<= humidity
59+
<= ABSOLUTE_MAX_HUMIDITY__PERCENTAGE
60+
):
5561
return True
5662
return False
5763

64+
5865
class ThermoProBluetoothDeviceData(BluetoothData):
5966
"""Date update for ThermoPro Bluetooth devices."""
6067

@@ -105,10 +112,12 @@ def _start_update(self, service_info: BluetoothServiceInfo) -> None:
105112
ambient_temp = ambient_temp - 30
106113
battery_percent = tp96_battery(battery_voltage)
107114

108-
if is_temp_hum_invalid(internal_temp, 0) or is_temp_hum_invalid(ambient_temp, 0):
115+
if is_temp_hum_invalid(internal_temp, 0) or is_temp_hum_invalid(
116+
ambient_temp, 0
117+
):
109118
# Invalid packet, probably corrupted
110119
return
111-
120+
112121
self.update_predefined_sensor(
113122
SensorLibrary.TEMPERATURE__CELSIUS,
114123
internal_temp,
@@ -129,20 +138,20 @@ def _start_update(self, service_info: BluetoothServiceInfo) -> None:
129138
name=f"Probe {probe_one_indexed} Battery",
130139
)
131140
else:
132-
# TP357S seems to be in 6, TP397 and TP393 in 4
141+
# TP357S seems to be in 6, TP397 and TP393 in 4
133142
battery_byte = data[6] if len(data) == 7 else data[4]
134143
(temp_deci, humi) = UNPACK_TEMP_HUMID(data[1:4])
135144
temp = temp_deci / 10
136145

137146
if is_temp_hum_invalid(temp, humi):
138147
# Invalid data, probably corrupted
139148
return
140-
149+
141150
if battery_byte in BATTERY_VALUE_TO_LEVEL:
142151
self.update_predefined_sensor(
143152
SensorLibrary.BATTERY__PERCENTAGE,
144153
BATTERY_VALUE_TO_LEVEL[battery_byte],
145154
)
146-
155+
147156
self.update_predefined_sensor(SensorLibrary.TEMPERATURE__CELSIUS, temp)
148157
self.update_predefined_sensor(SensorLibrary.HUMIDITY__PERCENTAGE, humi)

0 commit comments

Comments
 (0)