This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -29,9 +29,9 @@ def generate_and_validate(integrations: Dict[str, Integration]):
if not integration.manifest:
continue
service_types = integration.manifest.get('zeroconf', [])
homekit = integration.manifest.get('homekit', {})
homekit_models = homekit.get('models', [])
service_types = integration.manifest.get("zeroconf", [])
homekit = integration.manifest.get("homekit", {})
homekit_models = homekit.get("models", [])
if not service_types and not homekit_models:
continue
@ -39,24 +39,32 @@ def generate_and_validate(integrations: Dict[str, Integration]):
try:
with open(str(integration.path / "config_flow.py")) as fp:
content = fp.read()
uses_discovery_flow = 'register_discovery_flow' in content
uses_discovery_flow = "register_discovery_flow" in content
if (service_types and not uses_discovery_flow and
' async_step_zeroconf' not in content):
if (
service_types
and not uses_discovery_flow
and " async_step_zeroconf" not in content
):
integration.add_error(
'zeroconf', 'Config flow has no async_step_zeroconf')
"zeroconf", "Config flow has no async_step_zeroconf"
)
continue
if (homekit_models and not uses_discovery_flow and
' async_step_homekit' not in content):
if (
homekit_models
and not uses_discovery_flow
and " async_step_homekit" not in content
):
integration.add_error(
'zeroconf', 'Config flow has no async_step_homekit')
"zeroconf", "Config flow has no async_step_homekit"
)
continue
except FileNotFoundError:
integration.add_error(
'zeroconf',
'Zeroconf info in a manifest requires a config flow to exist'
"zeroconf",
"Zeroconf info in a manifest requires a config flow to exist",
)
continue
@ -66,9 +74,10 @@ def generate_and_validate(integrations: Dict[str, Integration]):
for model in homekit_models:
if model in homekit_dict:
integration.add_error(
'zeroconf',
'Integrations {} and {} have overlapping HomeKit '
'models'.format(domain, homekit_dict[model]))
"zeroconf",
"Integrations {} and {} have overlapping HomeKit "
"models".format(domain, homekit_dict[model]),
)
break
homekit_dict[model] = domain
@ -86,43 +95,40 @@ def generate_and_validate(integrations: Dict[str, Integration]):
if key.startswith(key_2) or key_2.startswith(key):
integration.add_error(
'zeroconf',
'Integrations {} and {} have overlapping HomeKit '
'models'.format(homekit_dict[key], homekit_dict[key_2]))
"zeroconf",
"Integrations {} and {} have overlapping HomeKit "
"models".format(homekit_dict[key], homekit_dict[key_2]),
)
warned.add(key)
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))
return BASE.format(
json.dumps(zeroconf, indent=4),
json.dumps(homekit, indent=4),
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))
return BASE.format(json.dumps(zeroconf, indent=4), json.dumps(homekit, indent=4))
def validate(integrations: Dict[str, Integration], config: Config):
"""Validate zeroconf file."""
zeroconf_path = config.root / 'homeassistant/generated/zeroconf.py'
config.cache['zeroconf'] = content = generate_and_validate(integrations)
zeroconf_path = config.root / "homeassistant/generated/zeroconf.py"
config.cache["zeroconf"] = content = generate_and_validate(integrations)
with open(str(zeroconf_path), 'r') as fp:
with open(str(zeroconf_path), "r") as fp:
current = fp.read().strip()
if current != content:
config.add_error(
"zeroconf",
"File zeroconf.py is not up to date. "
"Run python3 -m script.hassfest",
fixable=True
"File zeroconf.py is not up to date. " "Run python3 -m script.hassfest",
fixable=True,
)
return
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(config.cache['zeroconf'] + '\n')
zeroconf_path = config.root / "homeassistant/generated/zeroconf.py"
with open(str(zeroconf_path), "w") as fp:
fp.write(config.cache["zeroconf"] + "\n")