Skip to content

Commit 1f9d8c5

Browse files
Resolve review comments from tekktrik
1 parent ef0473b commit 1f9d8c5

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

adafruit_as726x.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from micropython import const
3333

3434
try:
35-
from typing import Tuple
35+
from typing import Tuple, Optional, Union
3636

3737
# This is only needed for typing
3838
import busio # pylint: disable=unused-import
@@ -267,12 +267,12 @@ def conversion_mode(self, val: int) -> None:
267267
self._virtual_write(_AS726X_CONTROL_SETUP, state | (val << 2))
268268

269269
@property
270-
def gain(self) -> int:
270+
def gain(self) -> float:
271271
"""The gain for the sensor"""
272272
return self._gain
273273

274274
@gain.setter
275-
def gain(self, val: int) -> None:
275+
def gain(self, val: float) -> None:
276276
if val not in AS726x.GAIN:
277277
raise ValueError("Must be 1, 3.7, 16 or 64")
278278
if self._gain == val:
@@ -394,10 +394,10 @@ def raw_red(self) -> int:
394394
"""Raw red (650nm) 16-bit value"""
395395
return self.read_channel(_AS7262_RED)
396396

397-
def _virtual_read(self, addr: int) -> int:
397+
def _virtual_read(self, addr: int) -> Union[int, float]:
398398
raise NotImplementedError("Must be implemented.")
399399

400-
def _virtual_write(self, addr: int, value: int) -> None:
400+
def _virtual_write(self, addr: int, value: Union[int, float]) -> None:
401401
raise NotImplementedError("Must be implemented.")
402402

403403

@@ -439,7 +439,7 @@ class AS726x_I2C(AS726x):
439439
440440
"""
441441

442-
def __init__(self, i2c_bus: busio.I2C, address: int = _AS726X_ADDRESS):
442+
def __init__(self, i2c_bus: busio.I2C, address: int = _AS726X_ADDRESS) -> None:
443443
self.i2c_device = I2CDevice(i2c_bus, address)
444444
super().__init__()
445445

@@ -460,7 +460,7 @@ def __write_u8(self, command: int, abyte: int) -> None:
460460
with self.i2c_device as i2c:
461461
i2c.write(buf)
462462

463-
def _virtual_read(self, addr: int) -> int:
463+
def _virtual_read(self, addr: int) -> Union[int, float]:
464464
"""read a virtual register"""
465465
while True:
466466
# Read slave I2C status to see if the read buffer is ready.
@@ -480,7 +480,7 @@ def _virtual_read(self, addr: int) -> int:
480480
data = self._read_u8(_AS726X_SLAVE_READ_REG)
481481
return data
482482

483-
def _virtual_write(self, addr: int, value: int) -> None:
483+
def _virtual_write(self, addr: int, value: Union[int, float]) -> None:
484484
"""write a virtual register"""
485485
while True:
486486
# Read slave I2C status to see if the write buffer is ready.
@@ -536,20 +536,20 @@ class AS726x_UART(AS726x):
536536
537537
"""
538538

539-
def __init__(self, uart: busio.UART):
539+
def __init__(self, uart: busio.UART) -> None:
540540
self._uart = uart
541541
self._uart.baudrate = 115200
542542
super().__init__()
543543

544-
def read_channel(self, channel: int) -> int:
544+
def read_channel(self, channel: int) -> float:
545545
"""Read an individual sensor channel"""
546546
return self._virtual_read(channel)
547547

548548
def read_calibrated_value(self, channel: int) -> float:
549549
"""Read a calibrated sensor channel"""
550550
return self._virtual_read(channel)
551551

552-
def _uart_xfer(self, cmd: int) -> int:
552+
def _uart_xfer(self, cmd: Optional[str]) -> str:
553553
self._uart.reset_input_buffer()
554554
cmd += "\n"
555555
self._uart.write(cmd.encode())
@@ -559,7 +559,7 @@ def _uart_xfer(self, cmd: int) -> int:
559559
return resp.rstrip(b" OK\n")
560560
return None
561561

562-
def _virtual_read(self, addr: int) -> int:
562+
def _virtual_read(self, addr: int) -> Union[int, float]:
563563
if addr == _AS726X_HW_VERSION:
564564
# just return what is expected
565565
return 0x40
@@ -582,7 +582,7 @@ def _virtual_read(self, addr: int) -> int:
582582
resp = resp.decode().split(",")
583583
return float(resp[_COLOR_REGS_CALIBRATED.index(addr)])
584584

585-
def _virtual_write(self, addr: int, value: int) -> None:
585+
def _virtual_write(self, addr: int, value: Union[int, float]) -> None:
586586
if addr == _AS726X_CONTROL_SETUP:
587587
# check for reset
588588
if (value >> 7) & 0x01:

0 commit comments

Comments
 (0)