Skip to content
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

Add type annotations #25

Merged
merged 1 commit into from
Jun 1, 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: 10 additions & 3 deletions adafruit_ds1307.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
from adafruit_register import i2c_bit
from adafruit_register import i2c_bcd_datetime

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

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

Expand Down Expand Up @@ -94,7 +101,7 @@ class DS1307:
datetime_register = i2c_bcd_datetime.BCDDateTimeRegister(0x00)
"""Current date and time."""

def __init__(self, i2c_bus):
def __init__(self, i2c_bus: I2C) -> None:
self.i2c_device = I2CDevice(i2c_bus, 0x68)

# Try and verify this is the RTC we expect by checking constant fields.
Expand All @@ -115,12 +122,12 @@ def __init__(self, i2c_bus):
raise ValueError("Unable to find DS1307 at i2c address 0x68.")

@property
def datetime(self):
def datetime(self) -> struct_time:
"""Gets the current date and time or sets the current date and time then starts the
clock."""
return self.datetime_register

@datetime.setter
def datetime(self, value):
def datetime(self, value: struct_time) -> None:
self.disable_oscillator = False
self.datetime_register = value