Skip to content

Commit baf7234

Browse files
authored
Merge pull request #28 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 4ad9002 + d596bd2 commit baf7234

File tree

6 files changed

+162
-132
lines changed

6 files changed

+162
-132
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

.pylintrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ spelling-store-unknown-words=no
119119
[MISCELLANEOUS]
120120

121121
# List of note tags to take in consideration, separated by a comma.
122-
notes=FIXME,XXX,TODO
122+
# notes=FIXME,XXX,TODO
123+
notes=FIXME,XXX
123124

124125

125126
[TYPECHECK]
@@ -300,7 +301,7 @@ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
300301

301302
# Good variable names which should always be accepted, separated by a comma
302303
# good-names=i,j,k,ex,Run,_
303-
good-names=r,g,b,i,j,k,n,x,y,z,ex,ok,Run,_
304+
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
304305

305306
# Include a hint for the correct naming format with invalid-name
306307
include-naming-hint=no

adafruit_tcs34725.py

+68-53
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@
5858

5959
# Register and command constants:
6060
# pylint: disable=bad-whitespace
61-
_COMMAND_BIT = const(0x80)
62-
_REGISTER_ENABLE = const(0x00)
63-
_REGISTER_ATIME = const(0x01)
64-
_REGISTER_AILT = const(0x04)
65-
_REGISTER_AIHT = const(0x06)
66-
_REGISTER_ID = const(0x12)
67-
_REGISTER_APERS = const(0x0c)
68-
_REGISTER_CONTROL = const(0x0f)
61+
_COMMAND_BIT = const(0x80)
62+
_REGISTER_ENABLE = const(0x00)
63+
_REGISTER_ATIME = const(0x01)
64+
_REGISTER_AILT = const(0x04)
65+
_REGISTER_AIHT = const(0x06)
66+
_REGISTER_ID = const(0x12)
67+
_REGISTER_APERS = const(0x0C)
68+
_REGISTER_CONTROL = const(0x0F)
6969
_REGISTER_SENSORID = const(0x12)
70-
_REGISTER_STATUS = const(0x13)
71-
_REGISTER_CDATA = const(0x14)
72-
_REGISTER_RDATA = const(0x16)
73-
_REGISTER_GDATA = const(0x18)
74-
_REGISTER_BDATA = const(0x1a)
75-
_ENABLE_AIEN = const(0x10)
76-
_ENABLE_WEN = const(0x08)
77-
_ENABLE_AEN = const(0x02)
78-
_ENABLE_PON = const(0x01)
79-
_GAINS = (1, 4, 16, 60)
70+
_REGISTER_STATUS = const(0x13)
71+
_REGISTER_CDATA = const(0x14)
72+
_REGISTER_RDATA = const(0x16)
73+
_REGISTER_GDATA = const(0x18)
74+
_REGISTER_BDATA = const(0x1A)
75+
_ENABLE_AIEN = const(0x10)
76+
_ENABLE_WEN = const(0x08)
77+
_ENABLE_AEN = const(0x02)
78+
_ENABLE_PON = const(0x01)
79+
_GAINS = (1, 4, 16, 60)
8080
_CYCLES = (0, 1, 2, 3, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60)
8181
_INTEGRATION_TIME_THRESHOLD_LOW = 2.4
8282
_INTEGRATION_TIME_THRESHOLD_HIGH = 614.4
@@ -100,7 +100,7 @@ def __init__(self, i2c, address=0x29):
100100
# Check sensor ID is expectd value.
101101
sensor_id = self._read_u8(_REGISTER_SENSORID)
102102
if sensor_id not in (0x44, 0x10):
103-
raise RuntimeError('Could not find sensor, check wiring!')
103+
raise RuntimeError("Could not find sensor, check wiring!")
104104

105105
@property
106106
def lux(self):
@@ -122,9 +122,9 @@ def color_rgb_bytes(self):
122122
if clear == 0:
123123
return (0, 0, 0)
124124
# pylint: disable=bad-whitespace
125-
red = int(pow((int((r/clear) * 256) / 255), 2.5) * 255)
126-
green = int(pow((int((g/clear) * 256) / 255), 2.5) * 255)
127-
blue = int(pow((int((b/clear) * 256) / 255), 2.5) * 255)
125+
red = int(pow((int((r / clear) * 256) / 255), 2.5) * 255)
126+
green = int(pow((int((g / clear) * 256) / 255), 2.5) * 255)
127+
blue = int(pow((int((b / clear) * 256) / 255), 2.5) * 255)
128128
# Handle possible 8-bit overflow
129129
if red > 255:
130130
red = 255
@@ -163,8 +163,7 @@ def active(self, val):
163163
time.sleep(0.003)
164164
self._write_u8(_REGISTER_ENABLE, enable | _ENABLE_PON | _ENABLE_AEN)
165165
else:
166-
self._write_u8(_REGISTER_ENABLE,
167-
enable & ~(_ENABLE_PON | _ENABLE_AEN))
166+
self._write_u8(_REGISTER_ENABLE, enable & ~(_ENABLE_PON | _ENABLE_AEN))
168167

169168
@property
170169
def integration_time(self):
@@ -173,12 +172,21 @@ def integration_time(self):
173172

174173
@integration_time.setter
175174
def integration_time(self, val):
176-
if not _INTEGRATION_TIME_THRESHOLD_LOW <= val <= _INTEGRATION_TIME_THRESHOLD_HIGH:
177-
raise ValueError("Integration Time must be between '{0}' and '{1}'".format(
178-
_INTEGRATION_TIME_THRESHOLD_LOW, _INTEGRATION_TIME_THRESHOLD_HIGH))
175+
if (
176+
not _INTEGRATION_TIME_THRESHOLD_LOW
177+
<= val
178+
<= _INTEGRATION_TIME_THRESHOLD_HIGH
179+
):
180+
raise ValueError(
181+
"Integration Time must be between '{0}' and '{1}'".format(
182+
_INTEGRATION_TIME_THRESHOLD_LOW, _INTEGRATION_TIME_THRESHOLD_HIGH
183+
)
184+
)
179185
cycles = int(val / 2.4)
180-
self._integration_time = cycles * 2.4 # pylint: disable=attribute-defined-outside-init
181-
self._write_u8(_REGISTER_ATIME, 256-cycles)
186+
self._integration_time = (
187+
cycles * 2.4
188+
) # pylint: disable=attribute-defined-outside-init
189+
self._write_u8(_REGISTER_ATIME, 256 - cycles)
182190

183191
@property
184192
def gain(self):
@@ -190,7 +198,9 @@ def gain(self):
190198
@gain.setter
191199
def gain(self, val):
192200
if val not in _GAINS:
193-
raise ValueError("Gain should be one of the following values: {0}".format(_GAINS))
201+
raise ValueError(
202+
"Gain should be one of the following values: {0}".format(_GAINS)
203+
)
194204
self._write_u8(_REGISTER_CONTROL, _GAINS.index(val))
195205

196206
@property
@@ -203,9 +213,11 @@ def interrupt(self):
203213
@interrupt.setter
204214
def interrupt(self, val):
205215
if val:
206-
raise ValueError("Interrupt should be set to False in order to clear the interrupt")
216+
raise ValueError(
217+
"Interrupt should be set to False in order to clear the interrupt"
218+
)
207219
with self._device:
208-
self._device.write(b'\xe6')
220+
self._device.write(b"\xe6")
209221

210222
@property
211223
def color_raw(self):
@@ -215,21 +227,24 @@ def color_raw(self):
215227
was_active = self.active
216228
self.active = True
217229
while not self._valid():
218-
time.sleep((self._integration_time + 0.9)/1000.0)
219-
data = tuple(self._read_u16(reg) for reg in (
220-
_REGISTER_RDATA,
221-
_REGISTER_GDATA,
222-
_REGISTER_BDATA,
223-
_REGISTER_CDATA,
224-
))
230+
time.sleep((self._integration_time + 0.9) / 1000.0)
231+
data = tuple(
232+
self._read_u16(reg)
233+
for reg in (
234+
_REGISTER_RDATA,
235+
_REGISTER_GDATA,
236+
_REGISTER_BDATA,
237+
_REGISTER_CDATA,
238+
)
239+
)
225240
self.active = was_active
226241
return data
227242

228243
@property
229244
def cycles(self):
230245
"""The persistence cycles of the sensor."""
231246
if self._read_u8(_REGISTER_ENABLE) & _ENABLE_AIEN:
232-
return _CYCLES[self._read_u8(_REGISTER_APERS) & 0x0f]
247+
return _CYCLES[self._read_u8(_REGISTER_APERS) & 0x0F]
233248
return -1
234249

235250
@cycles.setter
@@ -239,7 +254,9 @@ def cycles(self, val):
239254
self._write_u8(_REGISTER_ENABLE, enable & ~(_ENABLE_AIEN))
240255
else:
241256
if val not in _CYCLES:
242-
raise ValueError("Only the following cycles are permitted: {0}".format(_CYCLES))
257+
raise ValueError(
258+
"Only the following cycles are permitted: {0}".format(_CYCLES)
259+
)
243260
self._write_u8(_REGISTER_ENABLE, enable | _ENABLE_AIEN)
244261
self._write_u8(_REGISTER_APERS, _CYCLES.index(val))
245262

@@ -280,13 +297,13 @@ def _temperature_and_lux_dn40(self):
280297
R, G, B, C = self.color_raw
281298

282299
# Device specific values (DN40 Table 1 in Appendix I)
283-
GA = self.glass_attenuation # Glass Attenuation Factor
284-
DF = 310.0 # Device Factor
285-
R_Coef = 0.136 # |
286-
G_Coef = 1.0 # | used in lux computation
287-
B_Coef = -0.444 # |
288-
CT_Coef = 3810 # Color Temperature Coefficient
289-
CT_Offset = 1391 # Color Temperatuer Offset
300+
GA = self.glass_attenuation # Glass Attenuation Factor
301+
DF = 310.0 # Device Factor
302+
R_Coef = 0.136 # |
303+
G_Coef = 1.0 # | used in lux computation
304+
B_Coef = -0.444 # |
305+
CT_Coef = 3810 # Color Temperature Coefficient
306+
CT_Offset = 1391 # Color Temperatuer Offset
290307

291308
# Analog/Digital saturation (DN40 3.5)
292309
SATURATION = 65535 if 256 - ATIME > 63 else 1024 * (256 - ATIME)
@@ -300,7 +317,7 @@ def _temperature_and_lux_dn40(self):
300317
return None, None
301318

302319
# IR Rejection (DN40 3.1)
303-
IR = (R + G + B - C) / 2 if R + G + B > C else 0.
320+
IR = (R + G + B - C) / 2 if R + G + B > C else 0.0
304321
R2 = R - IR
305322
G2 = G - IR
306323
B2 = B - IR
@@ -342,16 +359,14 @@ def _read_u8(self, address):
342359
# Read an 8-bit unsigned value from the specified 8-bit address.
343360
with self._device as i2c:
344361
self._BUFFER[0] = (address | _COMMAND_BIT) & 0xFF
345-
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
346-
out_end=1, in_end=1)
362+
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1)
347363
return self._BUFFER[0]
348364

349365
def _read_u16(self, address):
350366
# Read a 16-bit unsigned value from the specified 8-bit address.
351367
with self._device as i2c:
352368
self._BUFFER[0] = (address | _COMMAND_BIT) & 0xFF
353-
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
354-
out_end=1, in_end=2)
369+
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=2)
355370
return (self._BUFFER[1] << 8) | self._BUFFER[0]
356371

357372
def _write_u8(self, address, val):

0 commit comments

Comments
 (0)