Use black to format hassfest generated files (#78794)
This commit is contained in:
parent
e66f28f3f7
commit
1021c90bb8
19 changed files with 633 additions and 624 deletions
|
@ -2,9 +2,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections import defaultdict
|
||||
import json
|
||||
|
||||
import black
|
||||
|
||||
from .model import Config, Integration
|
||||
from .serializer import to_string
|
||||
|
||||
BASE = """
|
||||
\"\"\"Automatically generated by hassfest.
|
||||
|
@ -12,8 +14,6 @@ BASE = """
|
|||
To update, run python3 -m script.hassfest
|
||||
\"\"\"
|
||||
|
||||
# fmt: off
|
||||
|
||||
MQTT = {}
|
||||
""".strip()
|
||||
|
||||
|
@ -37,7 +37,7 @@ def generate_and_validate(integrations: dict[str, Integration]):
|
|||
for topic in mqtt:
|
||||
data[domain].append(topic)
|
||||
|
||||
return BASE.format(json.dumps(data, indent=4))
|
||||
return black.format_str(BASE.format(to_string(data)), mode=black.Mode())
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config):
|
||||
|
@ -49,7 +49,7 @@ def validate(integrations: dict[str, Integration], config: Config):
|
|||
return
|
||||
|
||||
with open(str(mqtt_path)) as fp:
|
||||
if fp.read().strip() != content:
|
||||
if fp.read() != content:
|
||||
config.add_error(
|
||||
"mqtt",
|
||||
"File mqtt.py is not up to date. Run python3 -m script.hassfest",
|
||||
|
@ -62,4 +62,4 @@ def generate(integrations: dict[str, Integration], config: Config):
|
|||
"""Generate MQTT file."""
|
||||
mqtt_path = config.root / "homeassistant/generated/mqtt.py"
|
||||
with open(str(mqtt_path), "w") as fp:
|
||||
fp.write(f"{config.cache['mqtt']}\n")
|
||||
fp.write(f"{config.cache['mqtt']}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue