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
|
@ -1,12 +1,14 @@
|
|||
"""Generate zeroconf file."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import OrderedDict, defaultdict
|
||||
import json
|
||||
from collections import defaultdict
|
||||
|
||||
import black
|
||||
|
||||
from homeassistant.loader import async_process_zeroconf_match_dict
|
||||
|
||||
from .model import Config, Integration
|
||||
from .serializer import to_string
|
||||
|
||||
BASE = """
|
||||
\"\"\"Automatically generated by hassfest.
|
||||
|
@ -14,8 +16,6 @@ BASE = """
|
|||
To update, run python3 -m script.hassfest
|
||||
\"\"\"
|
||||
|
||||
# fmt: off
|
||||
|
||||
ZEROCONF = {}
|
||||
|
||||
HOMEKIT = {}
|
||||
|
@ -82,12 +82,12 @@ def generate_and_validate(integrations: dict[str, Integration]):
|
|||
warned.add(key_2)
|
||||
break
|
||||
|
||||
zeroconf = OrderedDict(
|
||||
(key, service_type_dict[key]) for key in sorted(service_type_dict)
|
||||
)
|
||||
homekit = OrderedDict((key, homekit_dict[key]) for key in sorted(homekit_dict))
|
||||
zeroconf = {key: service_type_dict[key] for key in sorted(service_type_dict)}
|
||||
homekit = {key: homekit_dict[key] for key in sorted(homekit_dict)}
|
||||
|
||||
return BASE.format(json.dumps(zeroconf, indent=4), json.dumps(homekit, indent=4))
|
||||
return black.format_str(
|
||||
BASE.format(to_string(zeroconf), to_string(homekit)), mode=black.Mode()
|
||||
)
|
||||
|
||||
|
||||
def validate(integrations: dict[str, Integration], config: Config):
|
||||
|
@ -99,7 +99,7 @@ def validate(integrations: dict[str, Integration], config: Config):
|
|||
return
|
||||
|
||||
with open(str(zeroconf_path)) as fp:
|
||||
current = fp.read().strip()
|
||||
current = fp.read()
|
||||
if current != content:
|
||||
config.add_error(
|
||||
"zeroconf",
|
||||
|
@ -113,4 +113,4 @@ def generate(integrations: dict[str, Integration], config: Config):
|
|||
"""Generate zeroconf file."""
|
||||
zeroconf_path = config.root / "homeassistant/generated/zeroconf.py"
|
||||
with open(str(zeroconf_path), "w") as fp:
|
||||
fp.write(f"{config.cache['zeroconf']}\n")
|
||||
fp.write(f"{config.cache['zeroconf']}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue