Skip to content

Commit 1d867bb

Browse files
committed
Fix linter-highlighted issues and improve code legibility
1 parent 535de87 commit 1d867bb

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

buildhat/color.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ def rgb_to_hsv(self, r, g, b):
6767
cmax = max(r, g, b)
6868
cmin = min(r, g, b)
6969
delt = cmax - cmin
70-
if cmax == cmin:
70+
h = 0
71+
72+
if delt == 0:
7173
h = 0
7274
elif cmax == r:
7375
h = 60 * (((g - b) / delt) % 6)
7476
elif cmax == g:
75-
h = 60 * ((((b - r) / delt)) + 2)
77+
h = 60 * (((b - r) / delt) + 2)
7678
elif cmax == b:
77-
h = 60 * ((((r - g) / delt)) + 4)
78-
if cmax == 0:
79-
s = 0
80-
else:
81-
s = delt / cmax
79+
h = 60 * (((r - g) / delt) + 4)
80+
81+
s = 0 if cmax == 0 else delt / cmax
8282
v = cmax
8383
return int(h), int(s * 100), int(v * 100)
8484

buildhat/colordistance.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,20 @@ def rgb_to_hsv(self, r, g, b):
7070
cmax = max(r, g, b)
7171
cmin = min(r, g, b)
7272
delt = cmax - cmin
73-
if cmax == cmin:
73+
h = 0
74+
75+
if delt == 0:
7476
h = 0
7577
elif cmax == r:
7678
h = 60 * (((g - b) / delt) % 6)
7779
elif cmax == g:
78-
h = 60 * ((((b - r) / delt)) + 2)
80+
h = 60 * (((b - r) / delt) + 2)
7981
elif cmax == b:
80-
h = 60 * ((((r - g) / delt)) + 4)
81-
if cmax == 0:
82-
s = 0
83-
else:
84-
s = delt / cmax
82+
h = 60 * (((r - g) / delt) + 4)
83+
84+
s = 0 if cmax == 0 else delt / cmax
8585
v = cmax
86+
8687
return int(h), int(s * 100), int(v * 100)
8788

8889
def get_color(self):

buildhat/hat.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ def get(self):
2929
devices = {}
3030
for i in range(4):
3131
name = Device.UNKNOWN_DEVICE
32-
if Device._instance.connections[i].typeid in Device._device_names:
33-
name = Device._device_names[Device._instance.connections[i].typeid][0]
34-
desc = Device._device_names[Device._instance.connections[i].typeid][1]
35-
elif Device._instance.connections[i].typeid == -1:
32+
desc = ''
33+
34+
typeid = Device._instance.connections[i].typeid
35+
if typeid in Device._device_names:
36+
name, desc = Device._device_names[typeid]
37+
elif typeid == -1:
3638
name = Device.DISCONNECTED_DEVICE
37-
desc = ''
38-
devices[chr(ord('A') + i)] = {"typeid": Device._instance.connections[i].typeid,
39-
"connected": Device._instance.connections[i].connected,
40-
"name": name,
41-
"description": desc}
39+
40+
devices[chr(ord('A') + i)] = {
41+
"typeid": typeid,
42+
"connected": Device._instance.connections[i].connected,
43+
"name": name,
44+
"description": desc
45+
}
4246
return devices
4347

4448
def get_logfile(self):

0 commit comments

Comments
 (0)