Make HSV NamedTuple creation more efficient (#1211)

This commit is contained in:
Steven B.
2024-10-29 17:14:52 +00:00
committed by GitHub
parent 6d8dc1cc5f
commit 673a32258f
2 changed files with 6 additions and 2 deletions

View File

@@ -367,7 +367,9 @@ class IotBulb(IotDevice):
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(

View File

@@ -44,7 +44,9 @@ class Color(SmartModule):
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."""