Skip to content

Add type annotations #4

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 1 commit into from
Feb 4, 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
13 changes: 9 additions & 4 deletions adafruit_ble_lywsd03mmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
from adafruit_ble.uuid import VendorUUID
from adafruit_ble.characteristics import Characteristic, ComplexCharacteristic

try:
from typing import Optional, Tuple
except ImportError:
pass

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_LYWSD03MMC.git"

Expand All @@ -38,10 +43,10 @@ class _Readings(ComplexCharacteristic):

uuid = VendorUUID("ebe0ccc1-7a0a-4b0c-8a1a-6ff2997da3a6")

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

def bind(self, service):
def bind(self, service: "LYWSD03MMCService") -> _bleio.PacketBuffer:
"""Bind to an LYWSD03MMCService."""
bound_characteristic = super().bind(service)
bound_characteristic.set_cccd(notify=True)
Expand All @@ -52,7 +57,7 @@ def bind(self, service):
class LYWSD03MMCService(Service):
"""Service for reading from an LYWSD03MMC sensor."""

def __init__(self, service=None):
def __init__(self, service: Optional["LYWSD03MMCService"] = None) -> None:
super().__init__(service=service)
# Defer creating buffers until needed, since MTU is not known yet.
self._settings_result_buf = None
Expand All @@ -63,7 +68,7 @@ def __init__(self, service=None):
readings = _Readings()

@property
def temperature_humidity(self):
def temperature_humidity(self) -> Optional[Tuple[float, int]]:
"""Return a tuple of (temperature, humidity)."""
if self._readings_buf is None:
self._readings_buf = bytearray(self.readings.incoming_packet_length)
Expand Down