Skip to content

Commit b9bd479

Browse files
committed
Fixing typing errors
1 parent 8c40de1 commit b9bd479

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

adafruit_ads1x15/ads1015.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,5 @@ def _data_rate_default(self) -> int:
6161
return 1600
6262

6363
def _conversion_value(self, raw_adc: int) -> int:
64-
raw_adc = raw_adc.to_bytes(2, "big")
65-
value = struct.unpack(">h", raw_adc)[0]
64+
value = struct.unpack(">h", raw_adc.to_bytes(2, "big"))[0]
6665
return value >> 4

adafruit_ads1x15/ads1115.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ def _data_rate_default(self) -> int:
6262
return 128
6363

6464
def _conversion_value(self, raw_adc: int) -> int:
65-
raw_adc = raw_adc.to_bytes(2, "big")
66-
value = struct.unpack(">h", raw_adc)[0]
65+
value = struct.unpack(">h", raw_adc.to_bytes(2, "big"))[0]
6766
return value

adafruit_ads1x15/ads1x15.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15.git"
1616

1717
import time
18-
from micropython import const
18+
1919
from adafruit_bus_device.i2c_device import I2CDevice
20+
from micropython import const
2021

2122
try:
2223
from typing import Optional
24+
2325
from busio import I2C
2426
from microcontroller import Pin
2527
except ImportError:
@@ -69,15 +71,17 @@ def __init__(
6971
i2c: I2C,
7072
gain: float = 1,
7173
data_rate: Optional[int] = None,
72-
mode: Mode = Mode.SINGLE,
74+
mode: int = Mode.SINGLE,
7375
address: int = _ADS1X15_DEFAULT_ADDRESS,
7476
):
7577
# pylint: disable=too-many-arguments
7678
self._last_pin_read = None
7779
self.buf = bytearray(3)
78-
self._data_rate = self._gain = self._mode = None
80+
self._gain:float
7981
self.gain = gain
82+
self._data_rate: int
8083
self.data_rate = self._data_rate_default() if data_rate is None else data_rate
84+
self._mode:int
8185
self.mode = mode
8286
self.i2c_device = I2CDevice(i2c, address)
8387

@@ -128,7 +132,7 @@ def mode(self):
128132
return self._mode
129133

130134
@mode.setter
131-
def mode(self, mode: Mode):
135+
def mode(self, mode: int):
132136
if mode not in (Mode.CONTINUOUS, Mode.SINGLE):
133137
raise ValueError("Unsupported mode.")
134138
self._mode = mode

adafruit_ads1x15/analog_in.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"""
1313

1414
try:
15-
from typing import Optional
15+
from typing import Optional, cast
16+
1617
from .ads1x15 import ADS1x15
1718
except ImportError:
1819
pass
@@ -37,7 +38,7 @@ def __init__(
3738
self._negative_pin = negative_pin
3839
self.is_differential = False
3940
if negative_pin is not None:
40-
pins = (self._pin_setting, self._negative_pin)
41+
pins = (self._pin_setting, cast(int, self._negative_pin))
4142
if pins not in _ADS1X15_DIFF_CHANNELS:
4243
raise ValueError(
4344
"Differential channels must be one of: {}".format(

0 commit comments

Comments
 (0)