diff --git a/buildhat/color.py b/buildhat/color.py index 5959263..8f9d1cf 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..809ac72 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):