tests: add type annotations to Smart tests#1686
Open
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
Open
tests: add type annotations to Smart tests#1686ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1686 +/- ##
=======================================
Coverage 93.22% 93.22%
=======================================
Files 157 157
Lines 9815 9815
Branches 1003 1003
=======================================
Hits 9150 9150
Misses 472 472
Partials 193 193 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Incrementally modernizes the “smart” test suite by adding Python type annotations and replacing a few # type: ignore patterns with explicit typing.cast() to satisfy mypy.
Changes:
- Added
-> Nonereturn annotations and parameter type annotations across smart tests. - Replaced several module-dict access assignment ignores with
cast(...)for clearer typing. - Added a targeted mypy suppression in
test_smartdevice.pyand corrected return annotations where functions actually return values.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/smart/test_smartdevice.py | Adds/adjusts type annotations for async tests/helpers and updates a mypy-related narrowing case. |
| tests/smart/modules/test_waterleak.py | Adds SmartDevice typing and uses cast() for module lookups. |
| tests/smart/modules/test_triggerlogs.py | Adds -> None return type for the async test. |
| tests/smart/modules/test_temperaturecontrol.py | Adds SmartDevice typing and uses cast() for TemperatureControl module lookups. |
| tests/smart/modules/test_temperature.py | Adds SmartDevice typing and uses cast() for TemperatureSensor module lookups. |
| tests/smart/modules/test_speaker.py | Adds -> None return types and formats typed signatures. |
| tests/smart/modules/test_powerprotection.py | Adds SmartDevice typing for feature tests and -> None returns elsewhere. |
| tests/smart/modules/test_motionsensor.py | Adds parameter/return type annotations to the async test. |
| tests/smart/modules/test_mop.py | Adds -> None returns and typed signatures for mop module tests. |
| tests/smart/modules/test_matter.py | Adds -> None return type for the async test. |
| tests/smart/modules/test_lighttransition.py | Adds -> None return types for async tests. |
| tests/smart/modules/test_light_strip_effect.py | Adds -> None return types and signature formatting for async tests. |
| tests/smart/modules/test_light_effect.py | Adds -> None return types and signature formatting for async tests. |
| tests/smart/modules/test_humidity.py | Adds SmartDevice typing and uses cast() for HumiditySensor module lookups. |
| tests/smart/modules/test_homekit.py | Adds -> None return type for the async test. |
| tests/smart/modules/test_firmware.py | Adds richer parameter typing and context-manager typing for firmware tests. |
| tests/smart/modules/test_fan.py | Adds -> None return types for fan module async tests. |
| tests/smart/modules/test_energy.py | Adds -> None return types for energy module async tests. |
| tests/smart/modules/test_dustbin.py | Adds -> None return types and typed signatures for dustbin tests. |
| tests/smart/modules/test_contact.py | Adds parameter/return type annotations to the async test. |
| tests/smart/modules/test_consumables.py | Adds -> None return types and typed signatures for consumables tests. |
| tests/smart/modules/test_cleanrecords.py | Adds -> None return types and signature formatting. |
| tests/smart/modules/test_clean.py | Adds -> None returns and parameter annotations across multiple async tests. |
| tests/smart/modules/test_childsetup.py | Adds -> None return types and parameter annotations for child setup tests. |
| tests/smart/modules/test_childprotection.py | Adds SmartDevice typing and uses cast() for module lookups. |
| tests/smart/modules/test_childlock.py | Adds SmartDevice typing and uses cast() for module lookups. |
| tests/smart/modules/test_autooff.py | Adds -> None return types and signature formatting. |
| tests/smart/modules/test_alarm.py | Adds more explicit typing (e.g., Any, dict shapes) and -> None returns. |
| tests/smart/features/test_colortemp.py | Adds -> None return type for the async feature test. |
| tests/smart/features/test_brightness.py | Adds -> None return types for async feature tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b17e709 to
0c82070
Compare
This was referenced Apr 7, 2026
This was referenced Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
-> Nonereturn type annotations, parameter type annotations, andcast()for module dict lookups across all 30 smart test files. This enables mypy to check test function bodies, catching type errors that were previously hidden.Changes
All 30 smart test files (
tests/smart/features/,tests/smart/modules/,tests/smart/test_smartdevice.py):-> Nonereturn type annotations to 95 test/helper functionsdev: SmartDevice,mocker: MockerFixture,feature: str,type: type,mode: ThermostatState, etc.)SmartDevice,MockerFixture,AbstractContextManager,Any,castModule dict lookups — use
cast()instead of# type: ignore:var: Type = dev.modules[key] # type: ignore[assignment]patterns withvar = cast(Type, dev.modules[key])across 6 files (test_childlock,test_childprotection,test_humidity,test_temperature,test_temperaturecontrol,test_waterleak)cast()usage intest_smartdevice.pyMypy fixes in
test_smartdevice.py:if raise_error:blocks so mypy can narrowSmartErrorCode | TimeoutErrorwithout# type: ignore[union-attr]-> Nonefrom_get_child_responsesand two inner_queryfunctions that return valuesDocstring fix in
test_firmware.py:"Test light effect features."→"Test firmware features."Files changed (30)
tests/smart/features/test_brightness.py,tests/smart/features/test_colortemp.py,tests/smart/modules/test_alarm.py,tests/smart/modules/test_autooff.py,tests/smart/modules/test_childlock.py,tests/smart/modules/test_childprotection.py,tests/smart/modules/test_childsetup.py,tests/smart/modules/test_clean.py,tests/smart/modules/test_cleanrecords.py,tests/smart/modules/test_consumables.py,tests/smart/modules/test_contact.py,tests/smart/modules/test_dustbin.py,tests/smart/modules/test_energy.py,tests/smart/modules/test_fan.py,tests/smart/modules/test_firmware.py,tests/smart/modules/test_homekit.py,tests/smart/modules/test_humidity.py,tests/smart/modules/test_light_effect.py,tests/smart/modules/test_light_strip_effect.py,tests/smart/modules/test_lighttransition.py,tests/smart/modules/test_matter.py,tests/smart/modules/test_mop.py,tests/smart/modules/test_motionsensor.py,tests/smart/modules/test_powerprotection.py,tests/smart/modules/test_speaker.py,tests/smart/modules/test_temperature.py,tests/smart/modules/test_temperaturecontrol.py,tests/smart/modules/test_triggerlogs.py,tests/smart/modules/test_waterleak.py,tests/smart/test_smartdevice.pyMerge order
This is PR 7 of 9 in the test modernization series. No file overlaps with other PRs.
Verification
mypy tests/smart/→ 0 errorsD100Cfixture)