Use black to format hassfest generated files (#78794)

This commit is contained in:
Erik Montnemery 2022-09-19 23:37:22 +02:00 committed by GitHub
parent e66f28f3f7
commit 1021c90bb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 633 additions and 624 deletions

View file

@ -1,9 +1,10 @@
"""Generate bluetooth file."""
from __future__ import annotations
import json
import black
from .model import Config, Integration
from .serializer import to_string
BASE = """
\"\"\"Automatically generated by hassfest.
@ -12,8 +13,6 @@ To update, run python3 -m script.hassfest
\"\"\"
from __future__ import annotations
# fmt: off
BLUETOOTH: list[dict[str, bool | str | int | list[int]]] = {}
""".strip()
@ -36,11 +35,7 @@ def generate_and_validate(integrations: list[dict[str, str]]):
for entry in match_types:
match_list.append({"domain": domain, **entry})
return BASE.format(
json.dumps(match_list, indent=4)
.replace('": true', '": True')
.replace('": false', '": False')
)
return black.format_str(BASE.format(to_string(match_list)), mode=black.Mode())
def validate(integrations: dict[str, Integration], config: Config):
@ -52,7 +47,7 @@ def validate(integrations: dict[str, Integration], config: Config):
return
with open(str(bluetooth_path)) as fp:
current = fp.read().strip()
current = fp.read()
if current != content:
config.add_error(
"bluetooth",
@ -66,4 +61,4 @@ def generate(integrations: dict[str, Integration], config: Config):
"""Generate bluetooth file."""
bluetooth_path = config.root / "homeassistant/generated/bluetooth.py"
with open(str(bluetooth_path), "w") as fp:
fp.write(f"{config.cache['bluetooth']}\n")
fp.write(f"{config.cache['bluetooth']}")