* Add __main__ type hints * Fix most errors of __main__ * Add ignore for script.run() * Add type annotations for from_config_dict and from_config_file * Fix errors * Fix requirement error * Add mypy type check to tests * Enable travis typing check * Messed up the tox deps * Laxer type checker
23 lines
670 B
Python
23 lines
670 B
Python
"""Home Assistant command line scripts."""
|
|
import importlib
|
|
import os
|
|
|
|
|
|
def run(args: str) -> int:
|
|
"""Run a script."""
|
|
scripts = [fil[:-3] for fil in os.listdir(os.path.dirname(__file__))
|
|
if fil.endswith('.py') and fil != '__init__.py']
|
|
|
|
if not args:
|
|
print('Please specify a script to run.')
|
|
print('Available scripts:', ', '.join(scripts))
|
|
return 1
|
|
|
|
if args[0] not in scripts:
|
|
print('Invalid script specified.')
|
|
print('Available scripts:', ', '.join(scripts))
|
|
return 1
|
|
|
|
script = importlib.import_module('homeassistant.scripts.' + args[0])
|
|
return script.run(args[1:]) # type: ignore
|