Skip to content

refactor: adds type annotations reported by mypy and updated pylint v… #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions adafruit_ble_ibbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

InkBird and EasyBBQ (from PyleUSA) are brands that use the iBBQ protocol in their products.
"""
try:
from typing import Optional, Tuple
except ImportError:
pass

import struct

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

uuid = StandardUUID(0xFFF1)

def __init__(self):
def __init__(self) -> None:
super().__init__(properties=Characteristic.NOTIFY)

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

uuid = StandardUUID(0xFFF4)

def __init__(self):
def __init__(self) -> None:
super().__init__(properties=Characteristic.NOTIFY)

def bind(self, service):
def bind(self, service: "IBBQService") -> _bleio.PacketBuffer:
"""Bind to an IBBQService."""
bound_characteristic = super().bind(service)
bound_characteristic.set_cccd(notify=True)
Expand All @@ -74,7 +78,7 @@ class IBBQService(Service):
_UNITS_CELSIUS_MSG = b"\x02\x00\x00\x00\x00\x00"
_REQUEST_BATTERY_LEVEL_MSG = b"\x08\x24\x00\x00\x00\x00"

def __init__(self, service=None):
def __init__(self, service: Optional["IBBQService"] = None) -> None:
super().__init__(service=service)
# Defer creating buffers until needed, since MTU is not known yet.
self._settings_result_buf = None
Expand Down Expand Up @@ -106,27 +110,27 @@ def __init__(self, service=None):
)
"""Send control messages here."""

def init(self):
def init(self) -> None:
"""Perform initial "pairing", which is not regular BLE pairing."""
self.account_and_verify = self._CREDENTIALS_MSG
self.settings_data = self._REALTIME_DATA_ENABLE_MSG

def display_fahrenheit(self):
def display_fahrenheit(self) -> None:
"""Display temperatures on device in degrees Fahrenheit.

Note: This does not change the units returned by `temperatures`.
"""
self.settings_data = self._UNITS_FAHRENHEIT_MSG

def display_celsius(self):
def display_celsius(self) -> None:
"""Display temperatures on device in degrees Celsius.

Note: This does not change the units returned by `temperatures`.
"""
self.settings_data = self._UNITS_CELSIUS_MSG

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

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