From 1d867bb75ea662a7f39a3145911ed0cab0d80f6b Mon Sep 17 00:00:00 2001 From: Greg Annandale Date: Thu, 10 Jul 2025 11:44:27 +0100 Subject: [PATCH 1/3] Fix linter-highlighted issues and improve code legibility --- buildhat/color.py | 14 +++++++------- buildhat/colordistance.py | 15 ++++++++------- buildhat/hat.py | 22 +++++++++++++--------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/buildhat/color.py b/buildhat/color.py index 5959263..c033e7b 100644 --- a/buildhat/color.py +++ b/buildhat/color.py @@ -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) diff --git a/buildhat/colordistance.py b/buildhat/colordistance.py index 3c722a3..98c9039 100644 --- a/buildhat/colordistance.py +++ b/buildhat/colordistance.py @@ -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): diff --git a/buildhat/hat.py b/buildhat/hat.py index 0a277eb..56c5594 100644 --- a/buildhat/hat.py +++ b/buildhat/hat.py @@ -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): From f601cece3843129db4efb347039cb24426c26337 Mon Sep 17 00:00:00 2001 From: Greg Annandale Date: Thu, 10 Jul 2025 11:47:03 +0100 Subject: [PATCH 2/3] Whitespace fixes --- buildhat/color.py | 2 +- buildhat/hat.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildhat/color.py b/buildhat/color.py index c033e7b..8f9d1cf 100644 --- a/buildhat/color.py +++ b/buildhat/color.py @@ -68,7 +68,7 @@ def rgb_to_hsv(self, r, g, b): cmin = min(r, g, b) delt = cmax - cmin h = 0 - + if delt == 0: h = 0 elif cmax == r: diff --git a/buildhat/hat.py b/buildhat/hat.py index 56c5594..1870c34 100644 --- a/buildhat/hat.py +++ b/buildhat/hat.py @@ -36,7 +36,7 @@ def get(self): name, desc = Device._device_names[typeid] elif typeid == -1: name = Device.DISCONNECTED_DEVICE - + devices[chr(ord('A') + i)] = { "typeid": typeid, "connected": Device._instance.connections[i].connected, From 51c8b11d1a815fcc33174066540ef62e8c88c0d8 Mon Sep 17 00:00:00 2001 From: Greg Annandale Date: Thu, 10 Jul 2025 11:48:05 +0100 Subject: [PATCH 3/3] Whitespace fix --- buildhat/hat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildhat/hat.py b/buildhat/hat.py index 1870c34..809ac72 100644 --- a/buildhat/hat.py +++ b/buildhat/hat.py @@ -36,7 +36,7 @@ def get(self): name, desc = Device._device_names[typeid] elif typeid == -1: name = Device.DISCONNECTED_DEVICE - + devices[chr(ord('A') + i)] = { "typeid": typeid, "connected": Device._instance.connections[i].connected,