mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-10 17:38:01 +00:00
Fix bug that changed brightness at each HSV update (#124)
* Fix bug that changed brightness at each hsv update The HSV setter should accept a percentage for the brightness value but actually assumed the brightness to be in absolute values between 1 and 255. This resulted in brightness reductions at each HSV update, in steps of 100% -> 100/255=39% -> 39/255=15% -> ... (see also https://github.com/home-assistant/home-assistant/issues/15582, where I originally reported this bug). * Modify HSV property to return brightness in percent Switch from reported brightness values of 1..255 to percentage values, for consistency with the apidoc and 8761dd8. * Add checks and tests for the hsv setter - make sure that new (hue, saturation, brightness) values are within their valid ranges (0..255, 0..100, 0..100) and raise SmartDeviceException if they are not - add test function for the hsv setter
This commit is contained in:
@@ -208,6 +208,23 @@ class TestSmartBulb(TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
self.bulb.color_temp = 10000
|
||||
|
||||
def test_hsv(self):
|
||||
hue, saturation, brightness = self.bulb.hsv
|
||||
self.assertTrue(0 <= hue <= 255)
|
||||
self.assertTrue(0 <= saturation <= 100)
|
||||
self.assertTrue(0 <= brightness <= 100)
|
||||
for invalid_hue in [-1, 256, 0.5]:
|
||||
with self.assertRaises(SmartDeviceException):
|
||||
self.bulb.hsv = (invalid_hue, 0, 0)
|
||||
|
||||
for invalid_saturation in [-1, 101, 0.5]:
|
||||
with self.assertRaises(SmartDeviceException):
|
||||
self.bulb.hsv = (0, invalid_saturation, 0)
|
||||
|
||||
for invalid_brightness in [-1, 101, 0.5]:
|
||||
with self.assertRaises(SmartDeviceException):
|
||||
self.bulb.hsv = (0, 0, invalid_brightness)
|
||||
|
||||
|
||||
class TestSmartBulbLB100(TestSmartBulb):
|
||||
SYSINFO = sysinfo_lb100
|
||||
|
Reference in New Issue
Block a user