Skip to content

Use ZDO converter for Mgmt_NWK_Update_req #102

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 2 commits into from
Nov 24, 2021

Conversation

puddly
Copy link
Collaborator

@puddly puddly commented Nov 23, 2021

This decouples the zigpy-znp energy scan tool from the zigpy-znp API. It will be moved into zigpy-cli in a future release.

  • Confirmed working with the Conbee II.
  • Does not work with bellows: the coordinator does not implement Mgmt_NWK_Update_req.

@Adminiuga Thoughts about making this work with bellows? How about a method in zigpy with a default implementation?

class ControllerApplication:
    async def energy_scan(self, channels: t.Channels, duration_exp: int, count: int) -> list[int]:
        rsp = await self.get_device(nwk=0x0000).zdo.Mgmt_NWK_Update_req(
            zdo_t.NwkUpdate(
                ScanChannels=channels,
                ScanDuration=duration_exp,
                ScanCount=count,
            )
        )

        return rsp.EnergyValues

Bellows can then override it to use the appropriate EZSP command.

@codecov-commenter
Copy link

Codecov Report

Merging #102 (5039182) into dev (4ac608c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #102   +/-   ##
=======================================
  Coverage   98.84%   98.84%           
=======================================
  Files          44       44           
  Lines        3800     3801    +1     
=======================================
+ Hits         3756     3757    +1     
  Misses         44       44           
Impacted Files Coverage Δ
zigpy_znp/zigbee/zdo_converters.py 100.00% <ø> (ø)
zigpy_znp/tools/energy_scan.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ac608c...5039182. Read the comment docs.

@Adminiuga
Copy link
Contributor

I'm fine with it.

What happens when you send the request to ezsp coordinator?

@puddly
Copy link
Collaborator Author

puddly commented Nov 23, 2021

Zigpy ends up receiving it:

2021-11-23 14:51:00.765 ubuntu bellows.ezsp.protocol DEBUG Send command sendUnicast: (<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0x0000, EmberApsFrame(profileId=0, clusterId=56, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=7), 8, b'\x07\x00\xf8\xff\x07\x02\x01')
2021-11-23 14:51:00.768 ubuntu bellows.uart DEBUG Sending: b'607721a9602a15b259944a1daa5592099d4e27ace5c9608b0539648bfd15e77e'
2021-11-23 14:51:00.783 ubuntu bellows.uart DEBUG Data frame: b'0777a1a9602a1570d7577e'
2021-11-23 14:51:00.783 ubuntu bellows.uart DEBUG Sending: b'8160597e'
2021-11-23 14:51:00.784 ubuntu bellows.ezsp.protocol DEBUG Application frame 52 (sendUnicast) received: b'00c2'
2021-11-23 14:51:00.789 ubuntu bellows.uart DEBUG Data frame: b'1777b1a9112a15b259ac4a25aa1593499c8cd8abedce9874fac1637103793da69ff77e'
2021-11-23 14:51:00.789 ubuntu bellows.uart DEBUG Sending: b'82503a7e'
2021-11-23 14:51:00.790 ubuntu bellows.ezsp.protocol DEBUG Application frame 69 (incomingMessageHandler) received: b'0000003800000040010000c2ff000000ffff070700f8ff070201'
2021-11-23 14:51:00.790 ubuntu bellows.zigbee.application DEBUG Received incomingMessageHandler frame with [<EmberIncomingMessageType.INCOMING_UNICAST: 0>, EmberApsFrame(profileId=0, clusterId=56, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=194), 255, 0, 0x0000, 255, 255, b'\x07\x00\xf8\xff\x07\x02\x01']
2021-11-23 14:51:00.790 ubuntu bellows.uart DEBUG Data frame: b'2777b1a96b2a15b259944a1daa5592099d4e2769e5ce6728727e'
2021-11-23 14:51:00.791 ubuntu zigpy.zdo DEBUG [0x0000:zdo] ZDO request ZDOCmd.Mgmt_NWK_Update_req: [NwkUpdate(ScanChannels=<Channels.ALL_CHANNELS: 134215680>, ScanDuration=2, ScanCount=1)]
2021-11-23 14:51:00.791 ubuntu bellows.uart DEBUG Sending: b'83401b7e'

2021-11-23 14:51:00.791 ubuntu zigpy.zdo DEBUG [0x0000:zdo] Unsupported ZDO request:ZDOCmd.Mgmt_NWK_Update_req
2021-11-23 14:51:00.792 ubuntu bellows.ezsp.protocol DEBUG Application frame 63 (messageSentHandler) received: b'00000000003800000040010000c2080000'
2021-11-23 14:51:00.793 ubuntu bellows.zigbee.application DEBUG Received messageSentHandler frame with [<EmberOutgoingMessageType.OUTGOING_DIRECT: 0>, 0, EmberApsFrame(profileId=0, clusterId=56, sourceEndpoint=0, destinationEndpoint=0, options=<EmberApsOption.APS_OPTION_ENABLE_ROUTE_DISCOVERY|APS_OPTION_RETRY: 320>, groupId=0, sequence=194), 8, <EmberStatus.SUCCESS: 0>, b'']

You can try it yourself:

diff --git a/zigpy_znp/tools/energy_scan.py b/zigpy_znp/tools/energy_scan.py
index e05f0c1..fac5101 100644
--- a/zigpy_znp/tools/energy_scan.py
+++ b/zigpy_znp/tools/energy_scan.py
@@ -8,7 +8,8 @@ import zigpy.zdo.types as zdo_t

 import zigpy_znp.types as t
 from zigpy_znp.tools.common import setup_parser
-from zigpy_znp.zigbee.application import ControllerApplication
+from bellows.zigbee.application import ControllerApplication

 LOGGER = logging.getLogger(__name__)

@@ -20,7 +21,7 @@ async def perform_energy_scan(radio_path, num_scans=None):
     app = ControllerApplication(config)

     try:
-        await app.startup(read_only=True)
+        await app.startup()
     except RuntimeError as e:
         LOGGER.error("Could not start application: %s", e)
         LOGGER.error("Form a network with `python -m zigpy_znp.tools.form_network`")

@Adminiuga
Copy link
Contributor

Ah, so much d doesn't support it and forwards to the app.
Need to check if we can do a quirk for ZDO and just handle that command by translating into an ezsp command

@puddly puddly merged commit cdd267c into zigpy:dev Nov 24, 2021
Sign up for free to 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.

3 participants