Skip to content

Add Missing Type Annotations #22

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
Oct 31, 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
15 changes: 10 additions & 5 deletions adafruit_mlx90614.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@

from adafruit_bus_device import i2c_device

try:
import typing # pylint: disable=unused-import
from busio import I2C
except ImportError:
pass

# imports

Expand Down Expand Up @@ -104,28 +109,28 @@ class MLX90614:

"""

def __init__(self, i2c_bus, address=_MLX90614_I2CADDR):
def __init__(self, i2c_bus: I2C, address: int = _MLX90614_I2CADDR) -> None:
self._device = i2c_device.I2CDevice(i2c_bus, address)
self.buf = bytearray(2)
self.buf[0] = _MLX90614_CONFIG

@property
def ambient_temperature(self):
def ambient_temperature(self) -> float:
"""Ambient Temperature in Celsius."""
return self._read_temp(_MLX90614_TA)

@property
def object_temperature(self):
def object_temperature(self) -> float:
"""Object Temperature in Celsius."""
return self._read_temp(_MLX90614_TOBJ1)

def _read_temp(self, register):
def _read_temp(self, register: int) -> float:
temp = self._read_16(register)
temp *= 0.02
temp -= 273.15
return temp

def _read_16(self, register):
def _read_16(self, register: int) -> int:
# Read and return a 16-bit unsigned big endian value read from the
# specified 16-bit register address.
with self._device as i2c:
Expand Down