Skip to content

Commit 2257af3

Browse files
authored
Merge pull request #24 from tekktrik/feature/add-typing
Add typing and required imports
2 parents dceeafc + 6dda9ab commit 2257af3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

adafruit_pcf8523.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class is inherited by the chip-specific subclasses.
5252
from adafruit_register import i2c_bcd_alarm
5353
from adafruit_register import i2c_bcd_datetime
5454

55+
try:
56+
import typing # pylint: disable=unused-import
57+
from busio import I2C
58+
from time import struct_time
59+
except ImportError:
60+
pass
61+
5562
STANDARD_BATTERY_SWITCHOVER_AND_DETECTION = 0b000
5663
BATTERY_SWITCHOVER_OFF = 0b111
5764

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

139-
def __init__(self, i2c_bus):
146+
def __init__(self, i2c_bus: I2C):
140147
self.i2c_device = I2CDevice(i2c_bus, 0x68)
141148

142149
# Try and verify this is the RTC we expect by checking the timer B
@@ -151,13 +158,13 @@ def __init__(self, i2c_bus):
151158
raise ValueError("Unable to find PCF8523 at i2c address 0x68.")
152159

153160
@property
154-
def datetime(self):
161+
def datetime(self) -> struct_time:
155162
"""Gets the current date and time or sets the current date and time then starts the
156163
clock."""
157164
return self.datetime_register
158165

159166
@datetime.setter
160-
def datetime(self, value):
167+
def datetime(self, value: struct_time):
161168
# Automatically sets lost_power to false.
162169
self.power_management = STANDARD_BATTERY_SWITCHOVER_AND_DETECTION
163170
self.datetime_register = value

0 commit comments

Comments
 (0)