Skip to content

Commit 9c81386

Browse files
authored
Merge pull request #38 from process1183/type_annotations
[#37] Add type annotations
2 parents d6c31bc + 18ca38c commit 9c81386

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

adafruit_ds3231.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
from adafruit_register import i2c_bcd_alarm
5252
from adafruit_register import i2c_bcd_datetime
5353

54+
try:
55+
# Used only for typing
56+
import typing # pylint: disable=unused-import
57+
from busio import I2C
58+
from time import struct_time
59+
except ImportError:
60+
pass
61+
5462
__version__ = "0.0.0-auto.0"
5563
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DS3231.git"
5664

@@ -131,28 +139,28 @@ class DS3231:
131139
_busy = i2c_bit.ROBit(0x0F, 2)
132140
_conv = i2c_bit.RWBit(0x0E, 5)
133141

134-
def __init__(self, i2c):
142+
def __init__(self, i2c: I2C) -> None:
135143
self.i2c_device = I2CDevice(i2c, 0x68)
136144

137145
@property
138-
def datetime(self):
146+
def datetime(self) -> struct_time:
139147
"""Gets the current date and time or sets the current date and time
140148
then starts the clock."""
141149
return self.datetime_register
142150

143151
@datetime.setter
144-
def datetime(self, value):
152+
def datetime(self, value: struct_time) -> None:
145153
self.datetime_register = value
146154
self.disable_oscillator = False
147155
self.lost_power = False
148156

149157
@property
150-
def temperature(self):
158+
def temperature(self) -> float:
151159
"""Returns the last temperature measurement. Temperature is updated
152160
only every 64 seconds, or when a conversion is forced."""
153161
return self._temperature / 4
154162

155-
def force_temperature_conversion(self):
163+
def force_temperature_conversion(self) -> float:
156164
"""Forces a conversion and returns the new temperature"""
157165
while self._busy:
158166
pass # Wait for any normal in-progress conversion to complete
@@ -162,7 +170,7 @@ def force_temperature_conversion(self):
162170
return self.temperature
163171

164172
@property
165-
def calibration(self):
173+
def calibration(self) -> int:
166174
"""Calibrate the frequency of the crystal oscillator by adding or
167175
removing capacitance. The datasheet calls this the Aging Offset.
168176
Calibration values range from -128 to 127; each step is approximately
@@ -172,6 +180,6 @@ def calibration(self):
172180
return self._calibration
173181

174182
@calibration.setter
175-
def calibration(self, value):
183+
def calibration(self, value: int) -> None:
176184
self._calibration = value
177185
self.force_temperature_conversion()

0 commit comments

Comments
 (0)