mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-21 20:20:11 +00:00
Fix set_state for common light modules (#929)
PR contains a number of fixes from testing with HA devices: - Fixes a bug with turning the light on and off via `set_state` - Aligns `set_brightness` behaviour across `smart` and `iot` devices such that a value of 0 is off. - Aligns `set_brightness` behaviour for `IotDimmer` such that setting the brightness turns on the device with a transition of 1ms. ([HA comment](https://github.com/home-assistant/core/pull/117839#discussion_r1608720006)) - Fixes a typing issue in `LightState`. - Adds `ColorTempRange` and `HSV` to `__init__.py` - Adds a `state` property to the interface returning `LightState` for validating `set_state` changes. - Adds tests for `set_state`
This commit is contained in:
@@ -7,19 +7,19 @@ from .conftest import dimmer_iot, handle_turn_on, turn_on
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
@turn_on
|
||||
async def test_set_brightness(dev, turn_on):
|
||||
await handle_turn_on(dev, turn_on)
|
||||
async def test_set_brightness(dev):
|
||||
await handle_turn_on(dev, False)
|
||||
assert dev.is_on is False
|
||||
|
||||
await dev.set_brightness(99)
|
||||
await dev.update()
|
||||
assert dev.brightness == 99
|
||||
assert dev.is_on == turn_on
|
||||
assert dev.is_on is True
|
||||
|
||||
await dev.set_brightness(0)
|
||||
await dev.update()
|
||||
assert dev.brightness == 1
|
||||
assert dev.is_on == turn_on
|
||||
assert dev.brightness == 99
|
||||
assert dev.is_on is False
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
@@ -41,7 +41,7 @@ async def test_set_brightness_transition(dev, turn_on, mocker):
|
||||
|
||||
await dev.set_brightness(0, transition=1000)
|
||||
await dev.update()
|
||||
assert dev.brightness == 1
|
||||
assert dev.is_on is False
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
@@ -50,7 +50,7 @@ async def test_set_brightness_invalid(dev):
|
||||
with pytest.raises(ValueError):
|
||||
await dev.set_brightness(invalid_brightness)
|
||||
|
||||
for invalid_transition in [-1, 0, 0.5]:
|
||||
for invalid_transition in [-1, 0.5]:
|
||||
with pytest.raises(ValueError):
|
||||
await dev.set_brightness(1, transition=invalid_transition)
|
||||
|
||||
@@ -133,7 +133,7 @@ async def test_set_dimmer_transition_invalid(dev):
|
||||
with pytest.raises(ValueError):
|
||||
await dev.set_dimmer_transition(invalid_brightness, 1000)
|
||||
|
||||
for invalid_transition in [-1, 0, 0.5]:
|
||||
for invalid_transition in [-1, 0.5]:
|
||||
with pytest.raises(ValueError):
|
||||
await dev.set_dimmer_transition(1, invalid_transition)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user