Skip to content

Commit 24a6cc8

Browse files
authored
Merge pull request #9 from sabadam32/add_type_annotations_6
refactor: adds type annotations reported by mypy and updated pylint v…
2 parents 7a16f41 + 8e68e6c commit 24a6cc8

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

adafruit_ble_ibbq.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
2121
InkBird and EasyBBQ (from PyleUSA) are brands that use the iBBQ protocol in their products.
2222
"""
23+
try:
24+
from typing import Optional, Tuple
25+
except ImportError:
26+
pass
2327

2428
import struct
2529

@@ -38,10 +42,10 @@ class _SettingsResult(ComplexCharacteristic):
3842

3943
uuid = StandardUUID(0xFFF1)
4044

41-
def __init__(self):
45+
def __init__(self) -> None:
4246
super().__init__(properties=Characteristic.NOTIFY)
4347

44-
def bind(self, service):
48+
def bind(self, service: "IBBQService") -> _bleio.PacketBuffer:
4549
"""Bind to an IBBQService."""
4650
bound_characteristic = super().bind(service)
4751
bound_characteristic.set_cccd(notify=True)
@@ -54,10 +58,10 @@ class _RealtimeData(ComplexCharacteristic):
5458

5559
uuid = StandardUUID(0xFFF4)
5660

57-
def __init__(self):
61+
def __init__(self) -> None:
5862
super().__init__(properties=Characteristic.NOTIFY)
5963

60-
def bind(self, service):
64+
def bind(self, service: "IBBQService") -> _bleio.PacketBuffer:
6165
"""Bind to an IBBQService."""
6266
bound_characteristic = super().bind(service)
6367
bound_characteristic.set_cccd(notify=True)
@@ -74,7 +78,7 @@ class IBBQService(Service):
7478
_UNITS_CELSIUS_MSG = b"\x02\x00\x00\x00\x00\x00"
7579
_REQUEST_BATTERY_LEVEL_MSG = b"\x08\x24\x00\x00\x00\x00"
7680

77-
def __init__(self, service=None):
81+
def __init__(self, service: Optional["IBBQService"] = None) -> None:
7882
super().__init__(service=service)
7983
# Defer creating buffers until needed, since MTU is not known yet.
8084
self._settings_result_buf = None
@@ -106,27 +110,27 @@ def __init__(self, service=None):
106110
)
107111
"""Send control messages here."""
108112

109-
def init(self):
113+
def init(self) -> None:
110114
"""Perform initial "pairing", which is not regular BLE pairing."""
111115
self.account_and_verify = self._CREDENTIALS_MSG
112116
self.settings_data = self._REALTIME_DATA_ENABLE_MSG
113117

114-
def display_fahrenheit(self):
118+
def display_fahrenheit(self) -> None:
115119
"""Display temperatures on device in degrees Fahrenheit.
116120
117121
Note: This does not change the units returned by `temperatures`.
118122
"""
119123
self.settings_data = self._UNITS_FAHRENHEIT_MSG
120124

121-
def display_celsius(self):
125+
def display_celsius(self) -> None:
122126
"""Display temperatures on device in degrees Celsius.
123127
124128
Note: This does not change the units returned by `temperatures`.
125129
"""
126130
self.settings_data = self._UNITS_CELSIUS_MSG
127131

128132
@property
129-
def temperatures(self):
133+
def temperatures(self) -> Optional[Tuple]:
130134
"""Return a tuple of temperatures for all the possible temperature probes on the device.
131135
Temperatures are in degrees Celsius. Unconnected probes return 0.0.
132136
"""
@@ -145,7 +149,7 @@ def temperatures(self):
145149
return None
146150

147151
@property
148-
def battery_level(self):
152+
def battery_level(self) -> Optional[Tuple[float, float]]:
149153
"""Get current battery level in volts as ``(current_voltage, max_voltage)``.
150154
Results are approximate and may differ from the
151155
actual battery voltage by 0.1v or so.

0 commit comments

Comments
 (0)