|
15 | 15 | import zigpy.zdo.types |
16 | 16 |
|
17 | 17 | from zigpy_cli.cli import cli, click_coroutine |
18 | | -from zigpy_cli.common import HEX_OR_DEC_INT |
19 | 18 | from zigpy_cli.const import RADIO_LOGGING_CONFIGS, RADIO_TO_PACKAGE, RADIO_TO_PYPI |
20 | 19 |
|
21 | 20 | LOGGER = logging.getLogger(__name__) |
@@ -55,7 +54,9 @@ async def radio(ctx, radio, port, baudrate=None, database=None): |
55 | 54 | { |
56 | 55 | "device": {"path": port}, |
57 | 56 | "backup_enabled": False, |
| 57 | + "startup_energy_scan": False, |
58 | 58 | "database_path": database, |
| 59 | + "use_thread": False, |
59 | 60 | } |
60 | 61 | ) |
61 | 62 |
|
@@ -171,45 +172,33 @@ async def permit(app, join_time): |
171 | 172 |
|
172 | 173 | @radio.command() |
173 | 174 | @click.pass_obj |
174 | | -@click.option("--nwk", type=HEX_OR_DEC_INT, default=0x0000) |
175 | 175 | @click.option("-n", "--num-scans", type=int, default=-1) |
176 | 176 | @click_coroutine |
177 | | -async def energy_scan(app, nwk, num_scans): |
| 177 | +async def energy_scan(app, num_scans): |
178 | 178 | await app.startup() |
179 | 179 | LOGGER.info("Running scan...") |
180 | 180 |
|
181 | | - # Temporarily create a zigpy device for scans not using the coordinator itself |
182 | | - if nwk != 0x0000: |
183 | | - app.add_device( |
184 | | - nwk=nwk, |
185 | | - ieee=zigpy.types.EUI64.convert("AA:AA:AA:AA:AA:AA:AA:AA"), |
186 | | - ) |
187 | | - |
188 | 181 | # We compute an average over the last 5 scans |
189 | 182 | channel_energies = collections.defaultdict(lambda: collections.deque([], maxlen=5)) |
190 | 183 |
|
191 | 184 | for scan in itertools.count(): |
192 | 185 | if num_scans != -1 and scan > num_scans: |
193 | 186 | break |
194 | 187 |
|
195 | | - rsp = await app.get_device(nwk=nwk).zdo.Mgmt_NWK_Update_req( |
196 | | - zigpy.zdo.types.NwkUpdate( |
197 | | - ScanChannels=zigpy.types.Channels.ALL_CHANNELS, |
198 | | - ScanDuration=0x02, |
199 | | - ScanCount=1, |
200 | | - ) |
| 188 | + results = await app.energy_scan( |
| 189 | + channels=zigpy.types.Channels.ALL_CHANNELS, duration_exp=2, count=1 |
201 | 190 | ) |
202 | 191 |
|
203 | | - _, scanned_channels, _, _, energy_values = rsp |
204 | | - |
205 | | - for channel, energy in zip(scanned_channels, energy_values): |
| 192 | + for channel, energy in results.items(): |
206 | 193 | energies = channel_energies[channel] |
207 | 194 | energies.append(energy) |
208 | 195 |
|
209 | 196 | total = 0xFF * len(energies) |
210 | 197 |
|
211 | 198 | print(f"Channel energy (mean of {len(energies)} / {energies.maxlen}):") |
212 | 199 | print("------------------------------------------------") |
| 200 | + print(" ! Different radios compute channel energy differently") |
| 201 | + print() |
213 | 202 | print(" + Lower energy is better") |
214 | 203 | print(" + Active Zigbee networks on a channel may still cause congestion") |
215 | 204 | print(" + TX on 26 in North America may be with lower power due to regulations") |
|
0 commit comments