From 8275aed06a79b6ea38bbe907a274a9d503dfc175 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:42:45 +0000 Subject: [PATCH] Make HSV NamedTuple creation more efficient --- kasa/iot/iotbulb.py | 4 +++- kasa/smart/modules/color.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/kasa/iot/iotbulb.py b/kasa/iot/iotbulb.py index 7e00bebc8..3302e80db 100644 --- a/kasa/iot/iotbulb.py +++ b/kasa/iot/iotbulb.py @@ -367,7 +367,9 @@ def _hsv(self) -> HSV: saturation = light_state["saturation"] value = self._brightness - return HSV(hue, saturation, value) + # Simple HSV(hue, saturation, value) is less efficent than below + # due to the cpython implementation. + return tuple.__new__(HSV, (hue, saturation, value)) @requires_update async def _set_hsv( diff --git a/kasa/smart/modules/color.py b/kasa/smart/modules/color.py index 772d9335b..3faa1a82e 100644 --- a/kasa/smart/modules/color.py +++ b/kasa/smart/modules/color.py @@ -44,7 +44,9 @@ def hsv(self) -> HSV: self.data.get("brightness", 0), ) - return HSV(hue=h, saturation=s, value=v) + # Simple HSV(h, s, v) is less efficent than below + # due to the cpython implementation. + return tuple.__new__(HSV, (h, s, v)) def _raise_for_invalid_brightness(self, value): """Raise error on invalid brightness value."""