Add ADC Value to PIR Enabled Switches

- Add: ADC value reporting to PIR enabled switches, so that it may be used in polling automations.
- Add: ADC trigger state value reporting, for simpler automations.
- Add: Ability for features to use custom value parsers.
This commit is contained in:
Ryan Nitcher
2024-11-14 12:09:56 -07:00
parent cb89342be1
commit 84aa74546e
5 changed files with 232 additions and 21 deletions

View File

@@ -1,6 +1,8 @@
import pytest
from pytest_mock import MockerFixture
from kasa import Module
from kasa.exceptions import KasaException
from kasa.iot import IotDimmer
from kasa.iot.modules.motion import Motion, Range
@@ -36,7 +38,14 @@ async def test_motion_range(dev: IotDimmer, mocker: MockerFixture):
motion: Motion = dev.modules[Module.IotMotion]
query_helper = mocker.patch("kasa.iot.IotDimmer._query_helper")
await motion.set_range(custom_range=123)
await motion.set_range(value=123)
query_helper.assert_called_with(
"smartlife.iot.PIR",
"set_trigger_sens",
{"index": Range.Custom.value, "value": 123},
)
await motion.set_range(range=Range.Custom, value=123)
query_helper.assert_called_with(
"smartlife.iot.PIR",
"set_trigger_sens",
@@ -48,6 +57,14 @@ async def test_motion_range(dev: IotDimmer, mocker: MockerFixture):
"smartlife.iot.PIR", "set_trigger_sens", {"index": Range.Far.value}
)
with pytest.raises(KasaException, match="Refusing to set non-custom range"):
await motion.set_range(range=Range.Near, value=100) # type: ignore[call-overload]
with pytest.raises(
KasaException, match="Either range or value needs to be defined"
):
await motion.set_range() # type: ignore[call-overload]
@dimmer_iot
def test_motion_feature(dev: IotDimmer):