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 typing and required imports #24

Merged
merged 3 commits into from
Oct 28, 2021
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_pcf8523.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ 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
from time import struct_time
except ImportError:
pass

STANDARD_BATTERY_SWITCHOVER_AND_DETECTION = 0b000
BATTERY_SWITCHOVER_OFF = 0b111

Expand Down Expand Up @@ -136,7 +143,7 @@ class PCF8523:
"""Calibration offset to apply, from -64 to +63. See the PCF8523 datasheet
figure 18 for the offset calibration calculation workflow."""

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

# Try and verify this is the RTC we expect by checking the timer B
Expand All @@ -151,13 +158,13 @@ def __init__(self, i2c_bus):
raise ValueError("Unable to find PCF8523 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):
# Automatically sets lost_power to false.
self.power_management = STANDARD_BATTERY_SWITCHOVER_AND_DETECTION
self.datetime_register = value