mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-10 17:38:01 +00:00
Add device fixture for P316M(US) (#1568)
Some checks failed
CI / Perform linting checks (3.13) (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled
Some checks failed
CI / Perform linting checks (3.13) (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled
Adds device fixture and updates powerprotection module to accept the changed enabled key. --------- Co-authored-by: komodo <komodo@komo.do> Co-authored-by: Teemu Rytilahti <tpr@iki.fi>
This commit is contained in:
@@ -112,7 +112,7 @@ SWITCHES_SMART = {
|
||||
}
|
||||
SWITCHES = {*SWITCHES_IOT, *SWITCHES_SMART}
|
||||
STRIPS_IOT = {"HS107", "HS300", "KP303", "KP200", "KP400", "EP40"}
|
||||
STRIPS_SMART = {"P300", "P304M", "TP25", "EP40M", "P210M", "P306"}
|
||||
STRIPS_SMART = {"P300", "P304M", "TP25", "EP40M", "P210M", "P306", "P316M"}
|
||||
STRIPS = {*STRIPS_IOT, *STRIPS_SMART}
|
||||
|
||||
DIMMERS_IOT = {"ES20M", "HS220", "KS220", "KS220M", "KS230", "KP405"}
|
||||
|
3485
tests/fixtures/smart/P316M(US)_1.6_1.0.5.json
vendored
Normal file
3485
tests/fixtures/smart/P316M(US)_1.6_1.0.5.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -48,33 +48,40 @@ async def test_set_enable(dev: SmartDevice, mocker: MockerFixture):
|
||||
# Simple enable with an existing threshold
|
||||
call_spy = mocker.spy(powerprot, "call")
|
||||
await powerprot.set_enabled(True)
|
||||
params = {
|
||||
"enabled": True,
|
||||
"protection_power": mocker.ANY,
|
||||
}
|
||||
call_spy.assert_called_with("set_protection_power", params)
|
||||
|
||||
args, kwargs = call_spy.call_args
|
||||
method, params = args
|
||||
assert method == "set_protection_power"
|
||||
|
||||
enabled_key = next(
|
||||
k for k in powerprot.data["get_protection_power"] if "enabled" in k
|
||||
)
|
||||
assert params[enabled_key] is True
|
||||
assert params["protection_power"] is not None
|
||||
|
||||
# Enable with no threshold param when 0
|
||||
call_spy.reset_mock()
|
||||
await powerprot.set_protection_threshold(0)
|
||||
await device.update()
|
||||
await powerprot.set_enabled(True)
|
||||
params = {
|
||||
"enabled": True,
|
||||
"protection_power": int(powerprot._max_power / 2),
|
||||
}
|
||||
call_spy.assert_called_with("set_protection_power", params)
|
||||
|
||||
args, kwargs = call_spy.call_args
|
||||
method, params = args
|
||||
assert method == "set_protection_power"
|
||||
assert "enabled" in params or "protection_enabled" in params
|
||||
assert params["protection_power"] == int(powerprot._max_power / 2)
|
||||
|
||||
# Enable false should not update the threshold
|
||||
call_spy.reset_mock()
|
||||
await powerprot.set_protection_threshold(0)
|
||||
await device.update()
|
||||
await powerprot.set_enabled(False)
|
||||
params = {
|
||||
"enabled": False,
|
||||
"protection_power": 0,
|
||||
}
|
||||
call_spy.assert_called_with("set_protection_power", params)
|
||||
|
||||
args, kwargs = call_spy.call_args
|
||||
method, params = args
|
||||
assert method == "set_protection_power"
|
||||
assert "enabled" in params or "protection_enabled" in params
|
||||
assert params["protection_power"] == 0
|
||||
|
||||
finally:
|
||||
await powerprot.set_enabled(original_enabled, threshold=original_threshold)
|
||||
@@ -88,11 +95,12 @@ async def test_set_threshold(dev: SmartDevice, mocker: MockerFixture):
|
||||
|
||||
call_spy = mocker.spy(powerprot, "call")
|
||||
await powerprot.set_protection_threshold(123)
|
||||
params = {
|
||||
"enabled": mocker.ANY,
|
||||
"protection_power": 123,
|
||||
}
|
||||
call_spy.assert_called_with("set_protection_power", params)
|
||||
|
||||
args, kwargs = call_spy.call_args
|
||||
method, params = args
|
||||
assert method == "set_protection_power"
|
||||
assert "enabled" in params or "protection_enabled" in params
|
||||
assert params["protection_power"] == 123
|
||||
|
||||
with pytest.raises(ValueError, match="Threshold out of range"):
|
||||
await powerprot.set_protection_threshold(-10)
|
||||
|
Reference in New Issue
Block a user