Skip to content

Subscribe to all ZDO cluster callbacks at once #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2022
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
Binary file modified docs/Z-Stack Monitor and Test API.pdf
Binary file not shown.
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,12 @@ def zdo_route_check(self, request):

@reply_to(c.ZDO.MsgCallbackRegister.Req(partial=True))
def register_zdo_callback(self, request):
self.zdo_callbacks.add(request.ClusterId)
if request.ClusterId == 0xFFFF:
for cluster_id in zdo_t.ZDOCmd:
self.zdo_callbacks.add(cluster_id)
else:
self.zdo_callbacks.add(request.ClusterId)

return c.ZDO.MsgCallbackRegister.Rsp(Status=t.Status.SUCCESS)

@reply_to(c.UTIL.AssocFindDevice.Req(Index=0))
Expand Down
17 changes: 11 additions & 6 deletions zigpy_znp/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,7 @@ async def start_network(self, *, read_only=False):
await self.register_endpoints()

# Receive a callback for every known ZDO command
for cluster_id in zdo_t.ZDOCmd:
# Ignore outgoing ZDO requests, only receive announcements and responses
if cluster_id.name.endswith(("_req", "_set")):
continue

await self._znp.request(c.ZDO.MsgCallbackRegister.Req(ClusterId=cluster_id))
await self._znp.request(c.ZDO.MsgCallbackRegister.Req(ClusterId=0xFFFF))

# Setup the coordinator as a zigpy device and initialize it to request node info
self.devices[self.state.node_info.ieee] = ZNPCoordinator(
Expand Down Expand Up @@ -521,6 +516,16 @@ async def on_zdo_message(self, msg: c.ZDO.MsgCbIncoming.Callback) -> None:
Global callback for all ZDO messages.
"""

try:
zdo_t.ZDOCmd(msg.ClusterId)
except ValueError:
pass
else:
# Ignore loopback ZDO requests, only receive announcements and responses
if zdo_t.ZDOCmd(msg.ClusterId).name.endswith(("_req", "_set")):
LOGGER.debug("Ignoring loopback ZDO request")
return

message = t.uint8_t(msg.TSN).serialize() + msg.Data
hdr, data = zdo_t.ZDOHeader.deserialize(msg.ClusterId, message)
names, types = zdo_t.CLUSTERS[msg.ClusterId]
Expand Down