Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion .github/dependabot.yml → .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ updates:
interval: "weekly"
ignore:
# Dependabot should not update Home Assistant as that should match the homeassistant key in hacs.json
- dependency-name: "homeassistant"
- dependency-name: "homeassistant"
- dependency-name: "mkdocs-material"
- dependency-name: "pytablewriter"
1 change: 0 additions & 1 deletion .github/scripts/library_doc/requirements.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
"""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."""

def get_device_list() -> None:
"""Sort the device library JSON file."""
# Load the existing JSON library file
with open(
"library/library.json", encoding="UTF-8"
file="library/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",
"Model ID (optional)",
"HW Version (optional)",
]
# Sort the devices by manufacturer and model
devices.sort(
key=lambda k: (
k["manufacturer"].lower(),
k.get("model_match_method", "").lower(),
k["model"].lower(),
k.get("model_id", "").lower(),
k.get("hw_version", "").lower(),
)
)
with open("library/library.json", "w", encoding="UTF-8") as f:
f.write(json.dumps(devices_json, indent=4))


def regenerate_device_list() -> None:
"""Generate static file containing the device library."""

writer.header_list = headers
# Load the existing JSON library file
with open("library/library.json", encoding="UTF-8") as file:
devices_json = json.loads(file.read())
devices = devices_json.get("devices")

rows = []
for device in devices:
if device.get("battery_quantity", 1) > 1:
battery_type_qty = f"{device['battery_quantity']}× {device['battery_type']}"
Expand All @@ -58,15 +62,28 @@ def generate_device_list():
]
rows.append(row)

writer = MarkdownTableWriter()
writer.header_list = [
"Manufacturer",
"Model",
"Battery Type",
"Model ID (optional)",
"HW Version (optional)",
]
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 += "Request new devices to be added to the library [here](https://github.com/andrew-codechimp/HA-Battery-Notes/issues/new?template=new_device_request.yml&title=%5BDevice%5D%3A+)\n\n"
tables_output += writer.dumps()

tables_output = [f"## {len(devices)} Devices in library\n\n"]
tables_output.append("This file is auto generated, do not modify\n\n")
tables_output.append(
"Request new devices to be added to the library [here](https://github.com/andrew-codechimp/HA-Battery-Notes/issues/new?template=new_device_request.yml&title=%5BDevice%5D%3A+)\n\n"
)
tables_output.append(writer.dumps())

with open("library.md", "w", encoding="UTF-8") as md_file:
md_file.write("".join(toc_links) + tables_output)
md_file.write("".join(tables_output))
md_file.close()


generate_device_list()
if __name__ == "__main__":
get_device_list()
regenerate_device_list()
31 changes: 31 additions & 0 deletions .github/workflows/deploy_docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy docs
on:
push:
paths:
- 'mkdocs.yaml'
- 'docs/**'
Comment thread
EVWorth marked this conversation as resolved.
branches:
- main
permissions:
contents: write
jobs:
deploy_docs:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5

- uses: actions/cache@v4
with:
key: mkdocs-material-${{ runner.os }}-${{ hashFiles('mkdocs.yaml', 'pyproject.toml', 'uv.lock') }}
path: .cache
restore-keys: |
mkdocs-material-

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Deploy documentation
run: |
uv run --only-group docs mkdocs gh-deploy --force
28 changes: 0 additions & 28 deletions .github/workflows/deploy_docs.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/json_librarian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: JSON Library Sorter and Doc Gen

on:
workflow_dispatch:
push:
branches:
- "main"
paths:
- "library/library.json"
- ".github/workflows/json_librarian.yaml"
- ".github/workflows/scripts/library_doc/**"
Comment thread
EVWorth marked this conversation as resolved.

jobs:
librarian:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Sort and Update Library Files
run: |
uv run --only-group library .github/scripts/library_doc/update_library_files.py

- name: Commit any changes
uses: stefanzweifel/git-auto-commit-action@v7
55 changes: 0 additions & 55 deletions .github/workflows/json_librarian.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
- "main"
paths:
- "library/**"
- ".github/workflows/json*.yml"
- ".github/workflows/json*.yaml"
pull_request:
branches:
- "main"
paths:
- "library/**"
- ".github/workflows/json*.yml"
- ".github/workflows/json*.yaml"

jobs:
verify-json-validation:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml → .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ on:
- "main"
paths:
- '**.py' # Run if pushed commits include a change to a Python (.py) file.
- '.github/workflows/lint.yml' # Run if pushed commits include a change to a github actions workflow file.
- '.github/workflows/lint.yaml' # Run if pushed commits include a change to a github actions workflow file.
- '.pyproject.toml' # Run if project configuration file changes.
pull_request:
branches:
- "main"
paths:
- '**.py' # Run if pushed commits include a change to a Python (.py) file.
- '.github/workflows/lint.yml' # Run if pushed commits include a change to a github actions workflow file.
- '.github/workflows/lint.yaml' # Run if pushed commits include a change to a github actions workflow file.
- '.pyproject.toml' # Run if project configuration file changes.
workflow_dispatch:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: issue-ops/parser@v4
with:
body: ${{ github.event.issue.body }}
issue-form-template: new_device_request.yml
issue-form-template: new_device_request.yaml

- name: Install jq
run: sudo apt install jq
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- 'library/**'
- 'docs/**'
- '*.md'
- '*.yml'
- '*.yaml'
- 'LICENSE'
pull_request:
branches:
Expand All @@ -20,7 +20,7 @@ on:
- 'library/**'
- 'docs/**'
- '*.md'
- '*.yml'
- '*.yaml'
- 'LICENSE'

jobs:
Expand Down
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"git.autofetch": true,
"python.createEnvironment.trigger": "off",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always",
},
"python.formatting.provider": "none"
"python.terminal.activateEnvInCurrentTerminal": true,
}
File renamed without changes.
18 changes: 14 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
"Programming Language :: Python :: 3",
]
requires-python = "==3.13.2"
dependencies = ["homeassistant==2025.4.0"]
dependencies = [] # Use dev for all dependencies

[project.urls]
documentation = "https://github.com/andrew-codechimp/HA-Battery-Notes"
Expand All @@ -26,11 +26,21 @@ repository = "https://github.com/andrew-codechimp/HA-Battery-Notes"
Changelog = "https://github.com/andrew-codechimp/HA-Battery-Notes/releases"

[dependency-groups]
dev = [
"colorlog>=6.10.1",
"ruff>=0.14.2",
dev = [
"colorlog",
"homeassistant==2025.4.0",
"ruff",
]

docs = [
"mkdocs-material",
]
library = [
"pytablewriter==0.61.0",
]

[tool.uv]
default-groups = ["dev"]
[tool.ruff]
target-version = "py313"
src = ["custom_components/battery_notes"]
Expand Down
6 changes: 3 additions & 3 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

set -e

# Move to project root
cd "$(dirname "$0")/.."

ruff check . --fix
uv run ruff check . --fix
Loading
Loading