mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-27 10:31:59 +00:00
Correct Quality Issues
- Fix: Decrease log message severity in `feature.py`. - Fix: Rename `_set_range_cli` to `_set_range_from_str`. - Add: Basic tests for string to Motion Range value converter function.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from kasa import Module
|
||||
from kasa import KasaException, Module
|
||||
from kasa.iot import IotDimmer
|
||||
from kasa.iot.modules.motion import Motion, Range
|
||||
|
||||
@@ -45,6 +46,33 @@ async def test_motion_range(dev: IotDimmer, mocker: MockerFixture):
|
||||
)
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
async def test_motion_range_from_string(dev: IotDimmer, mocker: MockerFixture):
|
||||
motion: Motion = dev.modules[Module.IotMotion]
|
||||
query_helper = mocker.patch("kasa.iot.IotDimmer._query_helper")
|
||||
|
||||
ranges_good = {
|
||||
"near": Range.Near,
|
||||
"MID": Range.Mid,
|
||||
"fAr": Range.Far,
|
||||
" Custom ": Range.Custom,
|
||||
}
|
||||
for range_str, range in ranges_good.items():
|
||||
await motion._set_range_from_str(range_str)
|
||||
query_helper.assert_called_with(
|
||||
"smartlife.iot.PIR",
|
||||
"set_trigger_sens",
|
||||
{"index": range.value},
|
||||
)
|
||||
|
||||
query_helper = mocker.patch("kasa.iot.IotDimmer._query_helper")
|
||||
ranges_bad = ["near1", "MD", "F\nAR", "Custom Near", '"FAR"', "'FAR'"]
|
||||
for range_str in ranges_bad:
|
||||
with pytest.raises(KasaException):
|
||||
await motion._set_range_from_str(range_str)
|
||||
query_helper.assert_not_called()
|
||||
|
||||
|
||||
@dimmer_iot
|
||||
async def test_motion_threshold(dev: IotDimmer, mocker: MockerFixture):
|
||||
motion: Motion = dev.modules[Module.IotMotion]
|
||||
|
||||
Reference in New Issue
Block a user