From 440f1f453b266b81a8be2cc0f54b6c6f372d744c Mon Sep 17 00:00:00 2001 From: ZeliardM <140266236+ZeliardM@users.noreply.github.com> Date: Sun, 5 Jul 2026 12:16:41 -0400 Subject: [PATCH] tests: fix typos, child device subtype, CLI patch path, and deprecation test logic (#1677) --- CHANGELOG.md | 2 +- kasa/smart/smartchilddevice.py | 1 + pyproject.toml | 2 +- tests/test_cli.py | 4 +--- tests/test_device.py | 24 +++++++++++++++++------- tests/test_discovery.py | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68ddd4fe..5513b9df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ Many thanks to testers and new contributors - @steveredden, @DawidPietrykowski, **Breaking changes:** - `uses_http` is now a readonly property of device config. Consumers that relied on `uses_http` to be persisted with `DeviceConfig.to_dict()` will need to store the value separately. -- `is_color`, `is_dimmable`, `is_variable_color_temp`, `valid_temperate_range`, and `has_effects` attributes from the `Light` module are deprecated, consumers should use `has_feature("hsv")`, `has_feature("brightness")`, `has_feature("color_temp")`, `get_feature("color_temp").range`, and `Module.LightEffect in dev.modules` respectively. Calling the deprecated attributes will emit a `DeprecationWarning` and type checkers will fail them. +- `is_color`, `is_dimmable`, `is_variable_color_temp`, `valid_temperature_range`, and `has_effects` attributes from the `Light` module are deprecated, consumers should use `has_feature("hsv")`, `has_feature("brightness")`, `has_feature("color_temp")`, `get_feature("color_temp").range`, and `Module.LightEffect in dev.modules` respectively. Calling the deprecated attributes will emit a `DeprecationWarning` and type checkers will fail them. - `alarm_volume` on the `smart.Alarm` module is changed from `str` to `int` **Breaking changes:** diff --git a/kasa/smart/smartchilddevice.py b/kasa/smart/smartchilddevice.py index 3f730f0e..f4e01ada 100644 --- a/kasa/smart/smartchilddevice.py +++ b/kasa/smart/smartchilddevice.py @@ -24,6 +24,7 @@ class SmartChildDevice(SmartDevice): CHILD_DEVICE_TYPE_MAP = { "plug.powerstrip.sub-plug": DeviceType.Plug, + "plug.powerstrip.sub-bulb": DeviceType.Bulb, "subg.plugswitch.switch": DeviceType.WallSwitch, "subg.trigger.contact-sensor": DeviceType.Sensor, "subg.trigger.temp-hmdt-sensor": DeviceType.Sensor, diff --git a/pyproject.toml b/pyproject.toml index a7ea0ad2..24f4d207 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -182,7 +182,7 @@ convention = "pep257" warn_unused_configs = true # warns if overrides sections unused/mis-spelled [[tool.mypy.overrides]] -module = [ "kasa.tests.*", "devtools.*" ] +module = [ "tests.*", "devtools.*" ] disable_error_code = "annotation-unchecked" [[tool.mypy.overrides]] diff --git a/tests/test_cli.py b/tests/test_cli.py index 6cba5d2a..dd68031d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -130,9 +130,7 @@ async def test_list_devices(discovery_mock, runner): async def test_discover_raw(discovery_mock, runner, mocker): """Test the discover raw command.""" - redact_spy = mocker.patch( - "kasa.protocols.protocol.redact_data", side_effect=redact_data - ) + redact_spy = mocker.patch("kasa.cli.discover.redact_data", side_effect=redact_data) res = await runner.invoke( cli, ["--username", "foo", "--password", "bar", "discover", "raw"], diff --git a/tests/test_device.py b/tests/test_device.py index 2c001bc6..842c4202 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -217,6 +217,13 @@ deprecated_is_device_type = { "is_strip": DeviceType.Strip, "is_strip_socket": DeviceType.StripSocket, } +deprecated_warns_before_attribute_error = { + "has_effects", + "is_color", + "is_dimmable", + "is_variable_color_temp", + "valid_temperature_range", +} deprecated_is_light_function_smart_module = { "is_color": "Color", "is_dimmable": "Brightness", @@ -244,20 +251,23 @@ def test_deprecated_device_type_attributes(dev: SmartDevice): async def _test_attribute( dev: Device, attribute_name, is_expected, module_name, *args, will_raise=False ): - if is_expected and will_raise: + will_warn = is_expected or attribute_name in deprecated_warns_before_attribute_error + + if will_raise: ctx: AbstractContextManager | nullcontext = pytest.raises(will_raise) - dep_context: pytest.WarningsRecorder | nullcontext = pytest.deprecated_call( - match=(f"{attribute_name} is deprecated, use:") - ) + dep_context: pytest.WarningsRecorder | nullcontext elif is_expected: ctx = nullcontext() - dep_context = pytest.deprecated_call( - match=(f"{attribute_name} is deprecated, use:") - ) else: ctx = pytest.raises( AttributeError, match=f"Device has no attribute '{attribute_name}'" ) + + if will_warn: + dep_context = pytest.deprecated_call( + match=(f"{attribute_name} is deprecated, use:") + ) + else: dep_context = nullcontext() with dep_context, ctx: diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 6fc521b0..e2b5042a 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -415,7 +415,7 @@ async def test_device_update_from_new_discovery_info(discovery_mock): KasaException, match=re.escape("You need to await update() to access the data"), ): - assert device.supported_modules + assert device.modules async def test_discover_single_http_client(discovery_mock, mocker):