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 #4

Merged
merged 2 commits into from
Mar 21, 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
17 changes: 13 additions & 4 deletions adafruit_pcf8563.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ class is inherited by the chip-specific subclasses.
from adafruit_register import i2c_bcd_alarm
from adafruit_register import i2c_bcd_datetime

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


class PCF8563:
"""Interface to the PCF8563 RTC."""
"""Interface to the PCF8563 RTC.

:param I2C i2c_bus: The I2C bus object
"""

datetime_compromised = i2c_bit.RWBit(0x2, 7)
"""True if the clock integrity is compromised."""
Expand All @@ -74,7 +83,7 @@ class PCF8563:
alarm_status = i2c_bit.RWBit(0x01, 3)
"""True if alarm is alarming. Set to False to reset."""

def __init__(self, i2c_bus):
def __init__(self, i2c_bus: I2C) -> None:
time.sleep(0.05)
self.i2c_device = I2CDevice(i2c_bus, 0x51)

Expand All @@ -87,13 +96,13 @@ def __init__(self, i2c_bus):
i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)

@property
def datetime(self):
def datetime(self) -> time.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: time.struct_time) -> None:
# Automatically sets lost_power to false.
self.datetime_register = value
self.datetime_compromised = False