Skip to content

Add collecting of network info - zigbee channel - #404

Closed
bouwew wants to merge 18 commits into
mainfrom
show_channel
Closed

Add collecting of network info - zigbee channel#404
bouwew wants to merge 18 commits into
mainfrom
show_channel

Conversation

@bouwew

@bouwewbouwew commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added Zigbee channel information collection and access capability to the Stick device.
  • Refactor

    • Updated internal NodeFeature class structure.
  • Tests

    • Added test data for network information responses and improved lint annotations.
  • Chores

    • Bumped version to 0.48.0a0.

@coderabbitai

coderabbitaiBot commented Feb 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Introduces network information collection to retrieve Zigbee channel data, adds a public channel property to the Stick class that delegates to the underlying network, enhances network discovery to request network info after ping, and bumps the project version to 0.48.0a0. The NodeFeature enum is refactored to use StrEnum.

Changes

Cohort / File(s)Summary
Changelog and Version
CHANGELOG.md, pyproject.toml
Adds "Ongoing" section to changelog with network info collection entry; version bumped from 0.47.2 to 0.48.0a0.
Network Channel Collection
plugwise_usb/network/__init__.py, plugwise_usb/messages/responses.py
Adds channel property and _channel attribute to StickNetwork; imports StickNetworkInfoRequest/Response; enhance discovery flow to request network info after ping and store channel. Response parsing disables MAC decoding.
Public API
plugwise_usb/__init__.py, plugwise_usb/api.py
Adds channel property to Stick class returning network channel or None; refactors NodeFeature from str/Enum inheritance to StrEnum.
Tests
tests/stick_test_data.py, tests/test_usb.py
Adds RESPONSE_MESSAGES entry for network info request with channel and device MAC data; updates lint annotation with noqa comment for lambda suppression.

Sequence Diagram

sequenceDiagram
participant Stick as Stick
participant Network as StickNetwork
participant Discovery as discover_network_coordinator
participant Msg as StickNetworkInfoRequest
participant Response as StickNetworkInfoResponse
Stick->>Network: access channel property
Network-->>Stick: return stored _channel (int | None)
Discovery->>Network: discover_network_coordinator()
Discovery->>Network: ping()
Network-->>Discovery: ping response
Discovery->>Msg: create StickNetworkInfoRequest
Discovery->>Network: send request & await response
Network->>Response: parse response (decode_mac=False)
Response-->>Network: extracted channel value
Network->>Network: set _channel = response.channel
Network-->>Discovery: success
Stick->>Network: access channel property
Network-->>Stick: return _channel (now populated)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • dirixmjm
  • brefra
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe PR title 'Add collecting of network info - zigbee channel' directly and accurately summarizes the main change: introducing functionality to collect and expose the Zigbee channel as part of network information gathering.
Docstring Coverage✅ PassedDocstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch show_channel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
coderabbitaiBot requested a review from dirixmjmFebruary 6, 2026 18:51

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@plugwise_usb/__init__.py`:
- Around line 94-97: The property channel currently returns
self._network.channel without checking if self._network is None, causing
AttributeError; update the channel property (def channel) to first guard for
self._network being None and return None (or the same sentinel used by
nodes/joined_nodes/network_discovered) when no network is initialized, otherwise
return self._network.channel so its behavior matches the sibling properties
(nodes, joined_nodes, network_discovered) that already check for self._network.
In `@plugwise_usb/connection/__init__.py`:
- Around line 237-238: The except clause in plugwise_usb.connection currently
uses the Python 2 comma form "except NodeError, StickError:" which is a
SyntaxError in Python 3; update the exception handler to use the tuple form
(catching NodeError and StickError together) so the module can import correctly,
i.e. change the handler that mentions NodeError and StickError to the
parenthesized tuple form and keep the existing return None behavior.
🧹 Nitpick comments (1)
plugwise_usb/network/__init__.py (1)

356-363: Wrap network-info request in try/except to prevent blocking coordinator discovery.

Channel info is supplementary. If the StickNetworkInfoRequest raises an exception (e.g., StickError, MessageError), it will propagate and fail the entire discover_network_coordinator call, even though the coordinator ping already succeeded.

Also, the isinstance check on line 359 is redundant — StickNetworkInfoRequest.send() already validates the return type and raises MessageError for unexpected responses.

♻️ Suggested resilient fetch
 # Collect network info
- request = StickNetworkInfoRequest(self._controller.send, None)- if (response := await request.send()) is not None:- if not isinstance(response, StickNetworkInfoResponse):- raise MessageError(- f"Invalid response message type ({response.__class__.__name__}) received, expected StickNetworkInfoResponse"- )- self._channel = response.channel+ try:+ request = StickNetworkInfoRequest(self._controller.send, None)+ if (response := await request.send()) is not None:+ self._channel = response.channel+ except (MessageError, StickError) as err:+ _LOGGER.warning("Failed to collect network info: %s", err)

Comment threadplugwise_usb/__init__.py
Comment threadplugwise_usb/connection/__init__.py Outdated
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecovBot commented Feb 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.22222% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.22%. Comparing base (413364a) to head (9effec2).

Files with missing linesPatch %Lines
plugwise_usb/__init__.py40.00%3 Missing ⚠️
plugwise_usb/network/__init__.py80.00%2 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #404 +/- ##
==========================================
+ Coverage 82.08% 82.22% +0.14% 
==========================================
Files 36 36 Lines 8181 8195 +14 ==========================================
+ Hits 6715 6738 +23 + Misses 1466 1457 -9 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bouwew

Copy link
Copy Markdown
ContributorAuthor

This does not work!
Sending a 0001 message when a Plus-device is paired, will break the pairing!!

@bouwewbouwew closed this Feb 7, 2026
@bouwew
bouwew deleted the show_channel branch May 18, 2026 17:51
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@bouwew