Skip to content
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

Channel energy scan #149

Merged
merged 5 commits into from
Oct 1, 2023
Merged

Channel energy scan #149

merged 5 commits into from
Oct 1, 2023

Conversation

Shulyaka
Copy link
Contributor

@Shulyaka Shulyaka commented Sep 26, 2023

Add support for per-channel energy detect for XBee coordinators.

Logs:

2023-09-26 09:05:26.779 DEBUG (MainThread) [zigpy_xbee.api] at command: ED (4,)
2023-09-26 09:05:26.779 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'ED', b'\x00\x00\x00\x00')
2023-09-26 09:05:26.779 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x14ED\x00\x00\x00\x00'
2023-09-26 09:05:27.153 DEBUG (MainThread) [homeassistant.bootstrap] Running timeout Zones: {'xbee_humidifier': <xbee_humidifier: 0 / 1>}
2023-09-26 09:05:27.154 DEBUG (MainThread) [homeassistant.bootstrap] Integration remaining: {'zha': 14.551212}
2023-09-26 09:05:27.467 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x14ED\x00/D1>\x06"\x16.*90IEKK7'
2023-09-26 09:05:27.467 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2023-09-26 09:05:27.478 DEBUG (MainThread) [zigpy.application] Startup energy scan: {11: -47, 12: -68, 13: -49, 14: -62, 15: -6, 16: -34, 17: -22, 18: -46, 19: -42, 20: -57, 21: -48, 22: -73, 23: -69, 24: -75, 25: -75, 26: -55}

Prtially implements #112 though it is not a stand-alone tool.

@Shulyaka Shulyaka changed the title XBee: energy scan Channel energy scan Sep 26, 2023
@puddly
Copy link
Contributor

puddly commented Sep 26, 2023

The energy scanning API is expected to return a number between 0 and 255, with 0 being "low" and 255 being "high". This is to make values comparable across radios, since all others return a number 0-255.

In bellows, I implemented it like so: https://github.com/zigpy/bellows/blob/58f8a8079a6fa1d25fe536e5d9e3fcfcbf41389c/bellows/zigbee/util.py#L105-L132. RSSI_MIN and RSSI_MAX can be found above. I generated the test tones with bellows as well: bellows --baudrate 115200 -d /dev/serial/by-id/... tone -c 15 -p 20

@Shulyaka
Copy link
Contributor Author

Thanks! Will update the code.

@Shulyaka Shulyaka marked this pull request as draft September 26, 2023 14:45
@Shulyaka
Copy link
Contributor Author

Shulyaka commented Sep 26, 2023

Fixed.
Using the same formula for compatibility (i.e. compare values between radios)

2023-09-26 17:50:06.980 DEBUG (MainThread) [zigpy_xbee.api] at command: ED (4,)
2023-09-26 17:50:06.980 DEBUG (MainThread) [zigpy_xbee.api] Command at (b'ED', b'\x00\x00\x00\x00')
2023-09-26 17:50:06.980 DEBUG (MainThread) [zigpy_xbee.uart] Sending: b'\x08\x14ED\x00\x00\x00\x00'
2023-09-26 17:50:07.669 DEBUG (MainThread) [zigpy_xbee.uart] Frame received: b'\x88\x14ED\x00QRGI;\x1d@%JCFEKLKM'
2023-09-26 17:50:07.669 DEBUG (MainThread) [zigpy_xbee.api] Frame received: at_response
2023-09-26 17:50:07.673 DEBUG (MainThread) [zigpy.application] Startup energy scan: {11: 6.400294434546168, 12: 5.637317837053025, 13: 22.00997262297472, 14: 17.31295187283794, 15: 79.08378338907617, 16: 244.0129080387192, 17: 48.47002474921316, 18: 226.18609483339876, 19: 15.32929809960923, 20: 34.963161543474534, 21: 24.768782664129375, 22: 27.832084152058194, 23: 13.559957792182884, 24: 11.984626537983768, 25: 13.559957792182884, 26: 10.584286741584284}

@Shulyaka Shulyaka marked this pull request as ready for review September 26, 2023 17:55
@Shulyaka
Copy link
Contributor Author

Shulyaka commented Oct 1, 2023

Rebased and added tests

@codecov
Copy link

codecov bot commented Oct 1, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (f387a0f) 98.86% compared to head (6b08af3) 99.13%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #149      +/-   ##
==========================================
+ Coverage   98.86%   99.13%   +0.26%     
==========================================
  Files           6        6              
  Lines         793      807      +14     
==========================================
+ Hits          784      800      +16     
+ Misses          9        7       -2     
Files Coverage Δ
zigpy_xbee/api.py 99.37% <ø> (ø)
zigpy_xbee/zigbee/application.py 97.78% <100.00%> (+1.08%) ⬆️

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

tests/test_application.py Outdated Show resolved Hide resolved
@puddly puddly merged commit f1eeca8 into zigpy:dev Oct 1, 2023
14 checks passed
@Shulyaka Shulyaka deleted the energy_scan branch October 1, 2023 17:54
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.

2 participants