Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/smart/features/test_brightness.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@brightness
async def test_brightness_component(dev: SmartDevice):
async def test_brightness_component(dev: SmartDevice) -> None:
"""Test brightness feature."""
brightness = next(get_parent_and_child_modules(dev, "Brightness"))
assert brightness
Expand All @@ -35,7 +35,7 @@ async def test_brightness_component(dev: SmartDevice):


@dimmable_iot
async def test_brightness_dimmable(dev: IotDevice):
async def test_brightness_dimmable(dev: IotDevice) -> None:
"""Test brightness feature."""
assert isinstance(dev, IotDevice)
assert "brightness" in dev.sys_info or bool(dev.sys_info["is_dimmable"])
Expand Down
2 changes: 1 addition & 1 deletion tests/smart/features/test_colortemp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@variable_temp_smart
async def test_colortemp_component(dev: SmartDevice):
async def test_colortemp_component(dev: SmartDevice) -> None:
"""Test brightness feature."""
assert isinstance(dev, SmartDevice)
assert "color_temperature" in dev._components
Expand Down
32 changes: 27 additions & 5 deletions tests/smart/modules/test_alarm.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
from __future__ import annotations

from typing import TypedDict

import pytest
from pytest_mock import MockerFixture

from kasa import Module
from kasa.smart import SmartDevice
from kasa.smart.modules import Alarm
from kasa.smart.modules.alarm import AlarmVolume

from ...device_fixtures import get_parent_and_child_modules, parametrize

alarm = parametrize("has alarm", component_filter="alarm", protocol_filter={"SMART"})


class PlayAlarmKwargs(TypedDict, total=False):
duration: int
volume: AlarmVolume | int
sound: str


class PlayAlarmRequestParams(TypedDict, total=False):
alarm_duration: int
alarm_volume: AlarmVolume
alarm_type: str


@alarm
@pytest.mark.parametrize(
("feature", "prop_name", "type"),
Expand All @@ -23,7 +38,9 @@
("alarm_volume_level", "alarm_volume", int),
],
)
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
async def test_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
assert alarm is not None
Expand All @@ -37,7 +54,7 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty


@alarm
async def test_volume_feature(dev: SmartDevice):
async def test_volume_feature(dev: SmartDevice) -> None:
"""Test that volume features have correct choices and range."""
alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
assert alarm is not None
Expand All @@ -64,7 +81,12 @@ async def test_volume_feature(dev: SmartDevice):
),
],
)
async def test_play(dev: SmartDevice, kwargs, request_params, mocker: MockerFixture):
async def test_play(
dev: SmartDevice,
kwargs: PlayAlarmKwargs,
request_params: PlayAlarmRequestParams,
mocker: MockerFixture,
) -> None:
"""Test that play parameters are handled correctly."""
alarm: Alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
call_spy = mocker.spy(alarm, "call")
Expand All @@ -86,7 +108,7 @@ async def test_play(dev: SmartDevice, kwargs, request_params, mocker: MockerFixt


@alarm
async def test_stop(dev: SmartDevice, mocker: MockerFixture):
async def test_stop(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test that stop creates the correct call."""
alarm: Alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
call_spy = mocker.spy(alarm, "call")
Expand All @@ -112,7 +134,7 @@ async def test_set_alarm_configure(
method: str,
value: str | int,
target_key: str,
):
) -> None:
"""Test that set_alarm_sound creates the correct call."""
alarm: Alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
call_spy = mocker.spy(alarm, "call")
Expand Down
6 changes: 3 additions & 3 deletions tests/smart/modules/test_autooff.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
async def test_autooff_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
):
) -> None:
"""Test that features are registered and work as expected."""
autooff = next(get_parent_and_child_modules(dev, Module.AutoOff))
assert autooff is not None
Expand All @@ -40,7 +40,7 @@ async def test_autooff_features(


@autooff
async def test_settings(dev: SmartDevice, mocker: MockerFixture):
async def test_settings(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test autooff settings."""
autooff = next(get_parent_and_child_modules(dev, Module.AutoOff))
assert autooff
Expand Down Expand Up @@ -79,7 +79,7 @@ async def test_settings(dev: SmartDevice, mocker: MockerFixture):
@pytest.mark.parametrize("is_timer_active", [True, False])
async def test_auto_off_at(
dev: SmartDevice, mocker: MockerFixture, is_timer_active: bool
):
) -> None:
"""Test auto-off at sensor."""
autooff = next(get_parent_and_child_modules(dev, Module.AutoOff))
assert autooff
Expand Down
12 changes: 7 additions & 5 deletions tests/smart/modules/test_childlock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from kasa import Module
from kasa.smart.modules import ChildLock
from kasa.smart import SmartDevice

from ...device_fixtures import parametrize

Expand All @@ -19,9 +19,11 @@
("child_lock", "enabled", bool),
],
)
async def test_features(dev, feature, prop_name, type):
async def test_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
protect: ChildLock = dev.modules[Module.ChildLock]
protect = dev.modules[Module.ChildLock]
assert protect is not None

prop = getattr(protect, prop_name)
Expand All @@ -33,9 +35,9 @@ async def test_features(dev, feature, prop_name, type):


@childlock
async def test_enabled(dev):
async def test_enabled(dev: SmartDevice) -> None:
"""Test the API."""
protect: ChildLock = dev.modules[Module.ChildLock]
protect = dev.modules[Module.ChildLock]
assert protect is not None

assert isinstance(protect.enabled, bool)
Expand Down
12 changes: 7 additions & 5 deletions tests/smart/modules/test_childprotection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from kasa import Module
from kasa.smart.modules import ChildProtection
from kasa.smart import SmartDevice

from ...device_fixtures import parametrize

Expand All @@ -19,9 +19,11 @@
("child_lock", "enabled", bool),
],
)
async def test_features(dev, feature, prop_name, type):
async def test_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
protect: ChildProtection = dev.modules[Module.ChildProtection]
protect = dev.modules[Module.ChildProtection]
assert protect is not None

prop = getattr(protect, prop_name)
Expand All @@ -33,9 +35,9 @@ async def test_features(dev, feature, prop_name, type):


@child_protection
async def test_enabled(dev):
async def test_enabled(dev: SmartDevice) -> None:
"""Test the API."""
protect: ChildProtection = dev.modules[Module.ChildProtection]
protect = dev.modules[Module.ChildProtection]
assert protect is not None

assert isinstance(protect.enabled, bool)
Expand Down
6 changes: 3 additions & 3 deletions tests/smart/modules/test_childsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@childsetup
async def test_childsetup_features(dev: Device):
async def test_childsetup_features(dev: Device) -> None:
"""Test the exposed features."""
cs = dev.modules.get(Module.ChildSetup)
assert cs
Expand All @@ -28,7 +28,7 @@ async def test_childsetup_features(dev: Device):
@childsetup
async def test_childsetup_pair(
dev: Device, mocker: MockerFixture, caplog: pytest.LogCaptureFixture
):
) -> None:
"""Test device pairing."""
caplog.set_level(logging.INFO)
mock_query_helper = mocker.spy(dev, "_query_helper")
Expand All @@ -52,7 +52,7 @@ async def test_childsetup_pair(
@childsetup
async def test_childsetup_unpair(
dev: Device, mocker: MockerFixture, caplog: pytest.LogCaptureFixture
):
) -> None:
"""Test unpair."""
mock_query_helper = mocker.spy(dev, "_query_helper")
DUMMY_ID = "dummy_id"
Expand Down
14 changes: 8 additions & 6 deletions tests/smart/modules/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
("battery_level", "battery", int),
],
)
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
async def test_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
clean = next(get_parent_and_child_modules(dev, Module.Clean))
assert clean is not None
Expand Down Expand Up @@ -94,7 +96,7 @@ async def test_actions(
value: str | int,
method: str,
params: dict,
):
) -> None:
"""Test the clean actions."""
clean = next(get_parent_and_child_modules(dev, Module.Clean))
call = mocker.spy(clean, "call")
Expand Down Expand Up @@ -130,7 +132,7 @@ async def test_post_update_hook(
error: ErrorCode,
warning_msg: str | None,
caplog: pytest.LogCaptureFixture,
):
) -> None:
"""Test that post update hook sets error states correctly."""
clean = next(get_parent_and_child_modules(dev, Module.Clean))
assert clean
Expand Down Expand Up @@ -160,7 +162,7 @@ async def test_post_update_hook(


@clean
async def test_resume(dev: SmartDevice, mocker: MockerFixture):
async def test_resume(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test that start calls resume if the state is paused."""
clean = next(get_parent_and_child_modules(dev, Module.Clean))

Expand All @@ -182,7 +184,7 @@ async def test_resume(dev: SmartDevice, mocker: MockerFixture):
@clean
async def test_unknown_status(
dev: SmartDevice, mocker: MockerFixture, caplog: pytest.LogCaptureFixture
):
) -> None:
"""Test that unknown status is logged."""
clean = next(get_parent_and_child_modules(dev, Module.Clean))

Expand Down Expand Up @@ -227,7 +229,7 @@ async def test_invalid_settings(
value: str,
exc: type[Exception],
exc_message: str,
):
) -> None:
"""Test invalid settings."""
clean = next(get_parent_and_child_modules(dev, Module.Clean))

Expand Down
6 changes: 4 additions & 2 deletions tests/smart/modules/test_cleanrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
("last_clean_timestamp", "last_clean_timestamp", datetime),
],
)
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
async def test_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
records = next(get_parent_and_child_modules(dev, Module.CleanRecords))
assert records is not None
Expand All @@ -41,7 +43,7 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty


@cleanrecords
async def test_timezone(dev: SmartDevice):
async def test_timezone(dev: SmartDevice) -> None:
"""Test that timezone is added to timestamps."""
clean_records = next(get_parent_and_child_modules(dev, Module.CleanRecords))
assert clean_records is not None
Expand Down
4 changes: 2 additions & 2 deletions tests/smart/modules/test_consumables.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"consumable_name", [consumable.id for consumable in CONSUMABLE_METAS]
)
@pytest.mark.parametrize("postfix", ["used", "remaining"])
async def test_features(dev: SmartDevice, consumable_name: str, postfix: str):
async def test_features(dev: SmartDevice, consumable_name: str, postfix: str) -> None:
"""Test that features are registered and work as expected."""
consumables = next(get_parent_and_child_modules(dev, Module.Consumables))
assert consumables is not None
Expand All @@ -39,7 +39,7 @@ async def test_features(dev: SmartDevice, consumable_name: str, postfix: str):
)
async def test_erase(
dev: SmartDevice, mocker: MockerFixture, consumable_name: str, data_key: str
):
) -> None:
"""Test autocollection switch."""
consumables = next(get_parent_and_child_modules(dev, Module.Consumables))
call = mocker.spy(consumables, "call")
Expand Down
2 changes: 1 addition & 1 deletion tests/smart/modules/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
("is_open", bool),
],
)
async def test_contact_features(dev: Device, feature, type):
async def test_contact_features(dev: Device, feature: str, type: type) -> None:
"""Test that features are registered and work as expected."""
contact = dev.modules.get(Module.ContactSensor)
assert contact is not None
Expand Down
12 changes: 7 additions & 5 deletions tests/smart/modules/test_dustbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
("dustbin_mode", "mode", str),
],
)
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
async def test_features(
dev: SmartDevice, feature: str, prop_name: str, type: type
) -> None:
"""Test that features are registered and work as expected."""
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
assert dustbin is not None
Expand All @@ -36,7 +38,7 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty


@dustbin
async def test_dustbin_mode(dev: SmartDevice, mocker: MockerFixture):
async def test_dustbin_mode(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test dust mode."""
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
call = mocker.spy(dustbin, "call")
Expand All @@ -61,7 +63,7 @@ async def test_dustbin_mode(dev: SmartDevice, mocker: MockerFixture):


@dustbin
async def test_dustbin_mode_off(dev: SmartDevice, mocker: MockerFixture):
async def test_dustbin_mode_off(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test dustbin_mode == Off."""
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
call = mocker.spy(dustbin, "call")
Expand All @@ -80,7 +82,7 @@ async def test_dustbin_mode_off(dev: SmartDevice, mocker: MockerFixture):


@dustbin
async def test_autocollection(dev: SmartDevice, mocker: MockerFixture):
async def test_autocollection(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test autocollection switch."""
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
call = mocker.spy(dustbin, "call")
Expand All @@ -101,7 +103,7 @@ async def test_autocollection(dev: SmartDevice, mocker: MockerFixture):


@dustbin
async def test_empty_dustbin(dev: SmartDevice, mocker: MockerFixture):
async def test_empty_dustbin(dev: SmartDevice, mocker: MockerFixture) -> None:
"""Test the empty dustbin feature."""
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
call = mocker.spy(dustbin, "call")
Expand Down
Loading
Loading