Skip to content

Fix linter-highlighted issues and improve code legibility #218

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions buildhat/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ def rgb_to_hsv(self, r, g, b):
cmax = max(r, g, b)
cmin = min(r, g, b)
delt = cmax - cmin
if cmax == cmin:
h = 0

if delt == 0:
h = 0
elif cmax == r:
h = 60 * (((g - b) / delt) % 6)
elif cmax == g:
h = 60 * ((((b - r) / delt)) + 2)
h = 60 * (((b - r) / delt) + 2)
elif cmax == b:
h = 60 * ((((r - g) / delt)) + 4)
if cmax == 0:
s = 0
else:
s = delt / cmax
h = 60 * (((r - g) / delt) + 4)

s = 0 if cmax == 0 else delt / cmax
v = cmax
return int(h), int(s * 100), int(v * 100)

Expand Down
15 changes: 8 additions & 7 deletions buildhat/colordistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ def rgb_to_hsv(self, r, g, b):
cmax = max(r, g, b)
cmin = min(r, g, b)
delt = cmax - cmin
if cmax == cmin:
h = 0

if delt == 0:
h = 0
elif cmax == r:
h = 60 * (((g - b) / delt) % 6)
elif cmax == g:
h = 60 * ((((b - r) / delt)) + 2)
h = 60 * (((b - r) / delt) + 2)
elif cmax == b:
h = 60 * ((((r - g) / delt)) + 4)
if cmax == 0:
s = 0
else:
s = delt / cmax
h = 60 * (((r - g) / delt) + 4)

s = 0 if cmax == 0 else delt / cmax
v = cmax

return int(h), int(s * 100), int(v * 100)

def get_color(self):
Expand Down
22 changes: 13 additions & 9 deletions buildhat/hat.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ def get(self):
devices = {}
for i in range(4):
name = Device.UNKNOWN_DEVICE
if Device._instance.connections[i].typeid in Device._device_names:
name = Device._device_names[Device._instance.connections[i].typeid][0]
desc = Device._device_names[Device._instance.connections[i].typeid][1]
elif Device._instance.connections[i].typeid == -1:
desc = ''

typeid = Device._instance.connections[i].typeid
if typeid in Device._device_names:
name, desc = Device._device_names[typeid]
elif typeid == -1:
name = Device.DISCONNECTED_DEVICE
desc = ''
devices[chr(ord('A') + i)] = {"typeid": Device._instance.connections[i].typeid,
"connected": Device._instance.connections[i].connected,
"name": name,
"description": desc}

devices[chr(ord('A') + i)] = {
"typeid": typeid,
"connected": Device._instance.connections[i].connected,
"name": name,
"description": desc
}
return devices

def get_logfile(self):
Expand Down