-
Notifications
You must be signed in to change notification settings - Fork 18
Adding type annotations #36
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_APDS9960.git" | ||
|
||
|
||
def calculate_color_temperature(r, g, b): | ||
def calculate_color_temperature(r: float, g: float, b: float) -> float: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure where these are used, so it was hard to infer the types expected for args here. There's definitely a lot of floating point math going on so it seemed logical to keep the return a The functionality here also might be duplicated elsewhere or out of scope for the library if it isn't making use of it internally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the types used for This line in one of the example scripts passes those individual values from that tuple into However I'm not certain whether that type would be int or float. I would need to hook up a sensor and look at the values it returns to know for sure. I think maybe this sensor is used on the CLUE or perhaps Feather Sense. I'll try to see if I have one and check the value types. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FoamyGuy - Thanks for the review. :) It makes total sense that the utility bundled here should operate on the same types that the library itself returns. In the follow-up commit I changed the param types to Changing it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure the color data returned is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed that the library indeed returns Adafruit CircuitPython 7.1.0-beta.0 on 2021-11-12; Adafruit CLUE nRF52840 Express with nRF52840
>>> import board
>>> from adafruit_apds9960.apds9960 import APDS9960
>>> apds = APDS9960(board.I2C())
>>>
>>> color = apds.color_data
>>>
>>> type(color)
<class 'tuple'>
>>> len(color)
4
>>> type(color[0])
<class 'int'>
>>> type(color[1])
<class 'int'>
>>> type(color[2])
<class 'int'>
>>> type(color[3])
<class 'int'> So we're good there. :) |
||
"""Converts the raw R/G/B values to color temperature in degrees Kelvin""" | ||
|
||
# 1. Map RGB values to their XYZ counterparts. | ||
|
@@ -40,7 +40,7 @@ def calculate_color_temperature(r, g, b): | |
return cct | ||
|
||
|
||
def calculate_lux(r, g, b): | ||
def calculate_lux(r: float, g: float, b: float) -> float: | ||
"""Calculate ambient light values""" | ||
# This only uses RGB ... how can we integrate clear or calculate lux | ||
# based exclusively on clear since this might be more reliable? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This buffer being declared as
None
but then getting used later ingesture()
is a bit weird but understandable. Definitely causes a headache for some more aggressive linter configs though.Not allocating it saves a decent chunk of memory but maybe there's a better way to handle it, like a
gesture_enabled
flag? Outside the scope here but maybe worth raising an issue for if you guys think its worth improving.