generated from ludeeus/integration_blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbf5de7
commit 26aa4f2
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Battery library document generator.""" | ||
|
||
from __future__ import annotations | ||
|
||
import json | ||
|
||
from pytablewriter import MarkdownTableWriter | ||
|
||
|
||
def generate_device_list(): | ||
"""Generate static file containing the device library.""" | ||
|
||
# Load the existing JSON library file | ||
with open("custom_components/battery_notes/data/library.json", | ||
encoding="UTF-8") as f: | ||
devices_json = json.loads(f.read()) | ||
devices = devices_json.get("devices") | ||
|
||
toc_links: list[str] = [] | ||
tables_output: str = "" | ||
rows = [] | ||
|
||
num_devices = len(devices) | ||
|
||
writer = MarkdownTableWriter() | ||
headers = [ | ||
"Manufacturer", | ||
"Model", | ||
"Battery Type", | ||
] | ||
|
||
writer.header_list = headers | ||
|
||
for device in devices: | ||
if device.get("battery_quantity", 1) > 1: | ||
battery_type_qty = f"{device['battery_quantity']}x {device['battery_type']}" | ||
else: | ||
battery_type_qty = device["battery_type"] | ||
row = [ | ||
device['manufacturer'], | ||
device['model'], | ||
battery_type_qty, | ||
] | ||
rows.append(row) | ||
|
||
writer.value_matrix = rows | ||
tables_output += f"## {num_devices} Devices in library\n\n" | ||
tables_output += "This file is auto generated, do not modify\n\n" | ||
tables_output += writer.dumps() | ||
|
||
with open("library.md", "w", encoding="UTF-8") as md_file: | ||
md_file.write("".join(toc_links) + tables_output) | ||
md_file.close() | ||
|
||
generate_device_list() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytablewriter==0.61.0 |