Skip to content

Commit

Permalink
Merge pull request #25 from tekktrik/doc/add-typing
Browse files Browse the repository at this point in the history
Add type annotations
  • Loading branch information
dhalbert committed Jun 1, 2022
2 parents e743fbb + 2e9c11c commit d450a5d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions adafruit_ds1307.py
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

0 comments on commit d450a5d

Please sign in to comment.