mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
Type check homeassistant.scripts (#25464)
* Run mypy on homeassistant.scripts, disabling bunch of checks for now * Declare async_initialize in AuthProvider * Add some type hints * Remove unreachable code * Help mypy out * Script docstring fixes
This commit is contained in:
parent
10b120f11f
commit
e8e84fb764
@ -108,6 +108,10 @@ class AuthProvider:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def async_initialize(self) -> None:
|
||||
"""Initialize the auth provider."""
|
||||
pass
|
||||
|
||||
|
||||
async def auth_provider_from_config(
|
||||
hass: HomeAssistant, store: AuthStore,
|
||||
|
@ -14,6 +14,8 @@ from homeassistant.util.package import (
|
||||
install_package, is_virtual_env, is_installed)
|
||||
|
||||
|
||||
# mypy: allow-untyped-defs, allow-incomplete-defs, no-warn-return-any
|
||||
|
||||
def run(args: List) -> int:
|
||||
"""Run a script."""
|
||||
scripts = []
|
||||
@ -57,7 +59,7 @@ def run(args: List) -> int:
|
||||
print('Aborting script, could not install dependency', req)
|
||||
return 1
|
||||
|
||||
return script.run(args[1:])
|
||||
return script.run(args[1:]) # type: ignore
|
||||
|
||||
|
||||
def extract_config_dir(args=None) -> str:
|
||||
|
@ -10,6 +10,8 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.config import get_default_config_dir
|
||||
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||
|
||||
def run(args):
|
||||
"""Handle Home Assistant auth provider script."""
|
||||
parser = argparse.ArgumentParser(
|
||||
|
@ -5,17 +5,22 @@ from contextlib import suppress
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from timeit import default_timer as timer
|
||||
from typing import Callable, Dict
|
||||
|
||||
from homeassistant import core
|
||||
from homeassistant.const import (
|
||||
ATTR_NOW, EVENT_STATE_CHANGED, EVENT_TIME_CHANGED)
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
BENCHMARKS = {}
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs
|
||||
# mypy: no-warn-return-any
|
||||
|
||||
BENCHMARKS = {} # type: Dict[str, Callable]
|
||||
|
||||
|
||||
def run(args):
|
||||
"""Handle ensure configuration commandline script."""
|
||||
"""Handle benchmark commandline script."""
|
||||
# Disable logging
|
||||
logging.getLogger('homeassistant.core').setLevel(logging.CRITICAL)
|
||||
|
||||
@ -40,8 +45,6 @@ def run(args):
|
||||
loop.run_until_complete(hass.async_stop())
|
||||
loop.close()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def benchmark(func):
|
||||
"""Decorate to mark a benchmark."""
|
||||
|
@ -5,7 +5,7 @@ import logging
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
from glob import glob
|
||||
from typing import Dict, List, Sequence
|
||||
from typing import Dict, List, Sequence, Any, Tuple, Callable
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import bootstrap, core
|
||||
@ -14,6 +14,9 @@ from homeassistant.helpers.check_config import async_check_ha_config_file
|
||||
import homeassistant.util.yaml.loader as yaml_loader
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||
|
||||
REQUIREMENTS = ('colorlog==4.0.2',)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -24,7 +27,7 @@ MOCKS = {
|
||||
'load*': ("homeassistant.config.load_yaml", yaml_loader.load_yaml),
|
||||
'secrets': ("homeassistant.util.yaml.loader.secret_yaml",
|
||||
yaml_loader.secret_yaml),
|
||||
}
|
||||
} # type: Dict[str, Tuple[str, Callable]]
|
||||
SILENCE = (
|
||||
'homeassistant.scripts.check_config.yaml_loader.clear_secret_cache',
|
||||
)
|
||||
@ -49,7 +52,7 @@ def color(the_color, *args, reset=None):
|
||||
|
||||
|
||||
def run(script_args: List) -> int:
|
||||
"""Handle ensure config commandline script."""
|
||||
"""Handle check config commandline script."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Check Home Assistant configuration.")
|
||||
parser.add_argument(
|
||||
@ -81,7 +84,7 @@ def run(script_args: List) -> int:
|
||||
|
||||
res = check(config_dir, args.secrets)
|
||||
|
||||
domain_info = []
|
||||
domain_info = [] # type: List[str]
|
||||
if args.info:
|
||||
domain_info = args.info.split(',')
|
||||
|
||||
@ -121,7 +124,7 @@ def run(script_args: List) -> int:
|
||||
dump_dict(res['components'].get(domain, None))
|
||||
|
||||
if args.secrets:
|
||||
flatsecret = {}
|
||||
flatsecret = {} # type: Dict[str, str]
|
||||
|
||||
for sfn, sdict in res['secret_cache'].items():
|
||||
sss = []
|
||||
@ -152,9 +155,9 @@ def check(config_dir, secrets=False):
|
||||
'yaml_files': OrderedDict(), # yaml_files loaded
|
||||
'secrets': OrderedDict(), # secret cache and secrets loaded
|
||||
'except': OrderedDict(), # exceptions raised (with config)
|
||||
'components': None, # successful components
|
||||
#'components' is a HomeAssistantConfig # noqa: E265
|
||||
'secret_cache': None,
|
||||
}
|
||||
} # type: Dict[str, Any]
|
||||
|
||||
# pylint: disable=possibly-unused-variable
|
||||
def mock_load(filename):
|
||||
|
@ -4,6 +4,9 @@ import getpass
|
||||
|
||||
from homeassistant.util.yaml import _SECRET_NAMESPACE
|
||||
|
||||
|
||||
# mypy: allow-untyped-defs
|
||||
|
||||
REQUIREMENTS = ['credstash==1.15.0']
|
||||
|
||||
|
||||
|
@ -6,6 +6,8 @@ from homeassistant.core import HomeAssistant
|
||||
import homeassistant.config as config_util
|
||||
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||
|
||||
def run(args):
|
||||
"""Handle ensure config commandline script."""
|
||||
parser = argparse.ArgumentParser(
|
||||
|
@ -5,6 +5,9 @@ import os
|
||||
|
||||
from homeassistant.util.yaml import _SECRET_NAMESPACE
|
||||
|
||||
|
||||
# mypy: allow-untyped-defs
|
||||
|
||||
REQUIREMENTS = ['keyring==17.1.1', 'keyrings.alt==3.1.1']
|
||||
|
||||
|
||||
@ -39,9 +42,9 @@ def run(args):
|
||||
return 1
|
||||
|
||||
if args.action == 'set':
|
||||
the_secret = getpass.getpass(
|
||||
entered_secret = getpass.getpass(
|
||||
'Please enter the secret for {}: '.format(args.name))
|
||||
keyring.set_password(_SECRET_NAMESPACE, args.name, the_secret)
|
||||
keyring.set_password(_SECRET_NAMESPACE, args.name, entered_secret)
|
||||
print('Secret {} set successfully'.format(args.name))
|
||||
elif args.action == 'get':
|
||||
the_secret = keyring.get_password(_SECRET_NAMESPACE, args.name)
|
||||
|
@ -3,6 +3,8 @@ import os
|
||||
import time
|
||||
|
||||
|
||||
# mypy: allow-untyped-calls, allow-untyped-defs
|
||||
|
||||
def install_osx():
|
||||
"""Set up to run via launchd on OS X."""
|
||||
with os.popen('which hass') as inp:
|
||||
|
Loading…
x
Reference in New Issue
Block a user