GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing github.com — Refactor discovery and connection routing by ZeliardM · Pull Request #1725 · python-kasa/python-kasa Conversation
Collaborator
SummaryThis PR consolidates discovery, device creation, and connection routing into a single flow. Discovery responses are decoded and normalized by their respective endpoints, then passed through shared logic that:
Previously, parts of this logic were duplicated across discovery, direct connections, the CLI, and devtools. Centralizing it should make it easier to add new discovery endpoints, device families, and connection types without updating several separate selection paths. This PR also supersedes:
DiscoveryDiscovery supports three endpoints:
The two TDP ports are handled independently because they may serve different device populations. UDP responses are held until discovery finishes. TDP responses are processed immediately and take precedence over UDP responses from the same IP. Once a host responds through TDP, any stored or later UDP response for that host is ignored. TDP remains authoritative even when processing its response results in an authentication error, unsupported-device result, or invalid-response error. This prevents discovery from falling back to a less useful UDP response for the same device. Each endpoint handles its own decoding and then produces a common discovery candidate. The shared processing path also:
Raw-response callbacks now include the discovery source and port, allowing callers to distinguish UDP responses from either TDP endpoint. Device and connection routingDevice-family, protocol, transport, and concrete-class selection now live in Advertised device families are kept separate from connection routes. After discovery or direct connection input has been normalized, the same route definitions are used by:
Existing special cases for cameras, doorbells, hubs, robot vacuums, HTTPS, fixed-encryption devices, and the IOT, SMART, and SMARTCAM protocol families are preserved. Direct-connection attempts are also generated from these route definitions instead of using a separate matrix of possible family and encryption combinations. IOT family names such as This keeps class selection correct for plugs, power strips, wall switches, dimmers, bulbs, and light strips across both discovery methods. Unknown IOT device types now raise Connection parameters and versioned KLAP
The TDP For IOT KLAP devices:
SMART KLAP devices continue to use their existing KLAP V2 route. The CLI and fixture devtool expose this setting as Discovery outcomes and errorsDiscovery distinguishes between:
The discovery API has separate callbacks for unsupported devices and authentication failures. These callbacks use the same task and exception handling as successful-device callbacks. Protocols owned by discovery are also closed when initialization or callback processing fails, or when discovery is interrupted. The new exceptions are exported from the package and included in the API reference. CLIThe discovery CLI now consumes the same normalized discovery and connection data as the library. The default discovery command updates supported devices before displaying them and reports a unique total across successful, unsupported, and authentication-blocked devices.
The format is shared across successful updates, timeouts, authentication failures, unsupported devices, unsupported authentication, and other update errors. Targeted hostname discovery also uses the resolved response identity, avoiding duplicate rows for the hostname and its IP address.
The remaining connection options have been made more predictable:
Credential hashes are preserved through discovery, direct probing, configuration output, and devtools. Devtools
It supports the same device-family, encryption, login-version, KLAP-version, HTTPS, credential-hash, timeout, and port options. It also reports authentication and unsupported-device outcomes and preserves the authoritative raw discovery response when generating fixtures. Redaction and discovery-formatting helpers used across modules have been renamed from private helpers to shared public helpers. Documentation and fixturesThe user and developer documentation has been updated for the revised discovery and connection flow. It covers:
The exception reference includes the new discovery authentication errors. An authenticated IOT KLAP HS300 fixture and a serialized versioned-KLAP API notes
Because ValidationThe relevant discovery, device-factory, device-config, CLI, and devtool tests pass. The changed Python files also pass Ruff and mypy, and the documentation builds successfully with warnings treated as errors.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@ ## master #1725 +/- ## ========================================== - Coverage 93.29% 92.24% -1.05% ========================================== Files 157 157 Lines 9932 10657 +725 Branches 1022 1182 +160 ========================================== + Hits 9266 9831 +565 - Misses 471 569 +98 - Partials 195 257 +62 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing in favour of #1810. Its transport registry covers the connection-routing and Once #1810 is merged I'll send the parts that are still needed as small, separate PRs. The first will be discovery classifying IOT devices from sysinfo: TDP discovery still creates |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.