Skip to content

Commit

Permalink
Merge pull request #137 from mdeweerd/dev
Browse files Browse the repository at this point in the history
csvout parameter: do not cleanup path when provided by user.
  • Loading branch information
mdeweerd authored Feb 3, 2023
2 parents 062771d + ef402bf commit 3c30a67
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/gen_stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DEST=$(dirname $0)/../../STATS.md
TEMPLATE='- ![badge VERSION](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/VERSION/total.svg)'

# Exclude stuff that results in invalid badges
EXCLUDES="v0.7.9 v0.7.7 v0.7.6 v0.7.5 v0.7.3 v0.7.2 v0.7.1 v0.7.23 v0.7.24"
EXCLUDES="v0.7.9 v0.7.7 v0.7.6 v0.7.5 v0.7.3 v0.7.2 v0.7.1 v0.7.23 v0.7.24, v0.8.30"

(
echo '# Badges showing number of downloads per version'
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ documentation updates.
- Use `home_assistant.log` to see what happened.
- Check this README.
- Check the
[Github issues](https://github.com/mdeweerd/zha-toolkit/issues?q=is%3Aissue)
[Github open and closed issues](https://github.com/mdeweerd/zha-toolkit/issues?q=is%3Aissue)
- Check the
[Home Assistant Forum](https://community.home-assistant.io/search?q=zha_toolkit)
- Check the [examples directory](examples)
Expand Down Expand Up @@ -1525,6 +1525,8 @@ service: zha_toolkit.zha_devices
data:
# Optional list of fields to write to the CSV, all non-list fields by default.
command_data: [name, ieee, rssi, lqi]
# Optional, field the list is sorted by (example: sort by signal strength)
csvlabel: rssi
csvout: ../www/devices.csv
event_done: zha_devices
```
Expand Down
2 changes: 1 addition & 1 deletion STATS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Badges showing number of downloads per version

- ![badge latest](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/latest/total.svg)
- ![badge v0.8.31](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.31/total.svg)
- ![badge v0.8.29](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.29/total.svg)
- ![badge v0.8.28](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.28/total.svg)
- ![badge v0.8.27](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.27/total.svg)
Expand All @@ -27,7 +28,6 @@
- ![badge v0.8.6](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.6/total.svg)
- ![badge v0.8.5](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.5/total.svg)
- ![badge v0.8.4](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.4/total.svg)
- ![badge v0.8.3](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.3/total.svg)
- ![badge v0.8.2](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.2/total.svg)
- ![badge v0.8.1](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.1/total.svg)
- ![badge v0.8.0](https://img.shields.io/github/downloads/mdeweerd/zha-toolkit/v0.8.0/total.svg)
Expand Down
1 change: 1 addition & 0 deletions custom_components/zha_toolkit/scan_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,5 @@ async def scan_device(
fname=file_name,
desc="scan results",
listener=listener,
normalize_name=True,
)
23 changes: 19 additions & 4 deletions custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ def get_cluster_from_params(
return cluster


def write_json_to_file(data, subdir, fname, desc, listener=None):
def write_json_to_file(
data, subdir, fname, desc, listener=None, normalize_name=False
):
if listener is None or subdir == "local":
base_dir = os.path.dirname(__file__)
else:
Expand All @@ -417,13 +419,23 @@ def write_json_to_file(data, subdir, fname, desc, listener=None):
if not os.path.isdir(out_dir):
os.mkdir(out_dir)

file_name = os.path.join(out_dir, normalize_filename(fname))
if normalize_name:
file_name = os.path.join(out_dir, normalize_filename(fname))
else:
file_name = os.path.join(out_dir, fname)

save_json(file_name, data)
LOGGER.debug(f"Finished writing {desc} in '{file_name}'")


def append_to_csvfile(
fields, subdir, fname, desc, listener=None, overwrite=False
fields,
subdir,
fname,
desc,
listener=None,
overwrite=False,
normalize_name=False,
):
if listener is None or subdir == "local":
base_dir = os.path.dirname(__file__)
Expand All @@ -434,7 +446,10 @@ def append_to_csvfile(
if not os.path.isdir(out_dir):
os.mkdir(out_dir)

file_name = os.path.join(out_dir, normalize_filename(fname))
if normalize_name:
file_name = os.path.join(out_dir, normalize_filename(fname))
else:
file_name = os.path.join(out_dir, fname)

import csv

Expand Down
9 changes: 6 additions & 3 deletions custom_components/zha_toolkit/zha.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ async def zha_devices(
params[p.CSV_LABEL], str
):
try:
# Lambda function gets column and returns false if None
# This make compares possible for ints)
# Lambda function gets column and returns False if None
# This makes compares possible for ints)
devices = sorted(
devices,
key=lambda item: ( # pylint: disable=C3002
lambda a: (a is None, a)
lambda a: (
a is None,
str.lower(a) if isinstance(a, str) else a,
)
)(item[params[p.CSV_LABEL]]),
)
except Exception: # nosec
Expand Down

0 comments on commit 3c30a67

Please sign in to comment.