Skip to content

Commit f9bcbf3

Browse files
committed
Fix static checks / code style
1 parent d2a5817 commit f9bcbf3

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed

README.md

+31-29
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ ZHA Toolkit can also:
122122
- [`zha_devices`: Device Information to Event or CSV or Script variable](#zha_devices-device-information-to-event-or-csv-or-script-variable)
123123
- [`register_services`: Reregister ZHA-Toolkit services](#register_services-reregister-zha-toolkit-services)
124124
- [`ha_set_state` - Update HA state](#ha_set_state---update-ha-state)
125-
- [`misc_energy_scan`: Scan Zigbee channels for congestion](#misc_energy_scan-perform-an-energy-scan)
125+
- [`misc_energy_scan`: Perform an energy scan](#misc_energy_scan-perform-an-energy-scan)
126126
- [User method](#user-method)
127127
- [Manufacturers](#manufacturers)
128128
- [Tuya](#tuya)
@@ -1924,44 +1924,46 @@ situations.
19241924

19251925
### `misc_energy_scan`: Perform an energy scan
19261926

1927-
Scan Zigbee channels for congestion level. The value is a percentage from zero
1928-
to 100. A lower value is less congested.
1927+
Scan Zigbee channels for congestion level. The value is a percentage from
1928+
zero to 100. A lower value is less congested.
19291929

19301930
```yaml
19311931
service: zha_toolkit.misc_energy_scan
19321932
data:
19331933
# Optional: CSV file to write attribute to - located in /config/csv/...
19341934
csvout: energy_scan.csv
19351935
```
1936-
The values can vary quite a bit between scans. You can create helpers to store
1937-
results which will allow you to see trends via the History tab. This automation
1938-
runs each hour:
1936+
1937+
The values can vary quite a bit between scans. You can create helpers to
1938+
store results which will allow you to see trends via the History tab. This
1939+
automation runs each hour:
19391940

19401941
```yaml
1941-
- id: 'zigbee_energy_scan'
1942-
alias: Zigbee Energy Scan
1943-
mode: single
1944-
triggers:
1945-
- trigger: time_pattern
1942+
- id: zigbee_energy_scan
1943+
alias: Zigbee Energy Scan
1944+
mode: single
1945+
triggers:
1946+
- trigger: time_pattern
19461947
# Matches every hour at 17 minutes past the hour
1947-
minutes: 17
1948-
actions:
1949-
- action: zha_toolkit.execute
1950-
data:
1951-
command: misc_energy_scan
1952-
response_variable: scan
1953-
- repeat:
1954-
for_each: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
1955-
sequence:
1956-
- action: input_number.set_value
1957-
target:
1958-
entity_id: "input_number.zigbee_energy_channel_{{ repeat.item }}"
1959-
data:
1960-
value: "{{ scan['energy_scan'][repeat.item] | round }}"
1961-
```
1962-
Creating 16 input_number helpers can be tedious. ZHA recommends only channels
1963-
15, 20, and 25 be used. Alternatively you can create just three helpers and
1964-
reduce the for_each list to only those three channels.
1948+
minutes: 17
1949+
actions:
1950+
- action: zha_toolkit.execute
1951+
data:
1952+
command: misc_energy_scan
1953+
response_variable: scan
1954+
- repeat:
1955+
for_each: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
1956+
sequence:
1957+
- action: input_number.set_value
1958+
target:
1959+
entity_id: input_number.zigbee_energy_channel_{{ repeat.item }}
1960+
data:
1961+
value: "{{ scan['energy_scan'][repeat.item] | round }}"
1962+
```
1963+
1964+
Creating 16 input_number helpers can be tedious. ZHA recommends only
1965+
channels 15, 20, and 25 be used. Alternatively you can create just three
1966+
helpers and reduce the for_each list to only those three channels.
19651967

19661968
## User method
19671969

custom_components/zha_toolkit/misc.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -319,28 +319,29 @@ async def misc_settime(
319319
event_data["success"] = False
320320
event_data["msg"] = f"{e!r}"
321321

322+
322323
async def misc_energy_scan(
323-
app, listener, ieee, cmd, data, service, params, event_data
324+
app, listener, ieee, cmd, data, service, params, event_data
324325
):
325-
""" Run energy scan for each channel. """
326-
# See https://github.com/zigpy/zigpy-cli/blob/dev/README.md#performing-an-energy-scan
326+
"""Run energy scan for each channel."""
327+
# See https://github.com/zigpy/zigpy-cli/blob/dev/README.md#performing-an-energy-scan # noqa: E501
327328
# Lower value means less congestion.
328-
329-
LOGGER.debug(f"Energy scan.")
329+
330+
LOGGER.debug("Energy scan.")
330331
scan = await app.energy_scan(
331332
channels=t.Channels.ALL_CHANNELS, duration_exp=4, count=1
332333
)
333-
event_data['energy_scan'] = {
334+
event_data["energy_scan"] = {
334335
channel: 100 * energy / 255 for channel, energy in scan.items()
335336
}
336337

337338
if params[p.CSV_FILE] is not None:
338339
# write CSV header
339340
u.append_to_csvfile(
340-
['channel', 'energy'],
341+
["channel", "energy"],
341342
"csv",
342343
params[p.CSV_FILE],
343-
'Energy Scan',
344+
"Energy Scan",
344345
listener=listener,
345346
overwrite=True,
346347
)

0 commit comments

Comments
 (0)