def read_config(args): while True: CORE.reset() data = json.loads(input()) assert data["type"] == "validate" CORE.vscode = True CORE.ace = args.ace f = data["file"] if CORE.ace: CORE.config_path = os.path.join(args.configuration[0], f) else: CORE.config_path = data["file"] vs = VSCodeResult() try: res = load_config( dict(args.substitution) if args.substitution else {}) except Exception as err: # pylint: disable=broad-except vs.add_yaml_error(str(err)) else: for err in res.errors: try: range_ = _get_invalid_range(res, err) vs.add_validation_error(range_, _format_vol_invalid(err, res)) except Exception: # pylint: disable=broad-except continue print(vs.dump())
def read_config(args): while True: CORE.reset() data = json.loads(safe_input()) assert data['type'] == 'validate' CORE.vscode = True CORE.ace = args.ace f = data['file'] if CORE.ace: CORE.config_path = os.path.join(args.configuration[0], f) else: CORE.config_path = data['file'] vs = VSCodeResult() try: res = load_config() except Exception as err: # pylint: disable=broad-except vs.add_yaml_error(text_type(err)) else: for err in res.errors: try: range_ = _get_invalid_range(res, err) vs.add_validation_error(range_, _format_vol_invalid(err, res)) except Exception: # pylint: disable=broad-except continue print(vs.dump())
def run_esphome(argv): args = parse_args(argv) CORE.dashboard = args.dashboard setup_log( args.verbose, args.quiet, # Show timestamp for dashboard access logs args.command == "dashboard", ) if args.deprecated_argv_suggestion is not None and args.command != "vscode": _LOGGER.warning( "Calling ESPHome with the configuration before the command is deprecated " "and will be removed in the future. ") _LOGGER.warning("Please instead use:") _LOGGER.warning(" esphome %s", " ".join(args.deprecated_argv_suggestion)) if sys.version_info < (3, 8, 0): _LOGGER.error( "You're running ESPHome with Python <3.8. ESPHome is no longer compatible " "with this Python version. Please reinstall ESPHome with Python 3.8+" ) return 1 if args.command in PRE_CONFIG_ACTIONS: try: return PRE_CONFIG_ACTIONS[args.command](args) except EsphomeError as e: _LOGGER.error(e, exc_info=args.verbose) return 1 for conf_path in args.configuration: if any(os.path.basename(conf_path) == x for x in SECRETS_FILES): _LOGGER.warning("Skipping secrets file %s", conf_path) continue CORE.config_path = conf_path CORE.dashboard = args.dashboard config = read_config( dict(args.substitution) if args.substitution else {}) if config is None: return 2 CORE.config = config if args.command not in POST_CONFIG_ACTIONS: safe_print(f"Unknown command {args.command}") try: rc = POST_CONFIG_ACTIONS[args.command](args, config) except EsphomeError as e: _LOGGER.error(e, exc_info=args.verbose) return 1 if rc != 0: return rc CORE.reset() return 0
def generate_main(): """Generates the C++ main.cpp file and returns it in string form.""" def generator(path: str) -> str: CORE.config_path = path CORE.config = read_config({}) generate_cpp_contents(CORE.config) print(CORE.cpp_main_section) return CORE.cpp_main_section yield generator CORE.reset()
def run_esphome(argv): args = parse_args(argv) CORE.dashboard = args.dashboard setup_log(args.verbose, args.quiet) if args.deprecated_argv_suggestion is not None and args.command != "vscode": _LOGGER.warning( "Calling ESPHome with the configuration before the command is deprecated " "and will be removed in the future. ") _LOGGER.warning("Please instead use:") _LOGGER.warning(" esphome %s", " ".join(args.deprecated_argv_suggestion[1:])) if sys.version_info < (3, 7, 0): _LOGGER.error( "You're running ESPHome with Python <3.7. ESPHome is no longer compatible " "with this Python version. Please reinstall ESPHome with Python 3.7+" ) return 1 if args.command in PRE_CONFIG_ACTIONS: try: return PRE_CONFIG_ACTIONS[args.command](args) except EsphomeError as e: _LOGGER.error(e, exc_info=args.verbose) return 1 for conf_path in args.configuration: CORE.config_path = conf_path CORE.dashboard = args.dashboard config = read_config( dict(args.substitution) if args.substitution else {}) if config is None: return 1 CORE.config = config if args.command not in POST_CONFIG_ACTIONS: safe_print(f"Unknown command {args.command}") try: rc = POST_CONFIG_ACTIONS[args.command](args, config) except EsphomeError as e: _LOGGER.error(e, exc_info=args.verbose) return 1 if rc != 0: return rc CORE.reset() return 0
def run_esphome(argv): args = parse_args(argv) CORE.dashboard = args.dashboard setup_log(args.verbose, args.quiet) if args.command != "version" and not args.configuration: _LOGGER.error("Missing configuration parameter, see esphome --help.") return 1 if sys.version_info < (3, 7, 0): _LOGGER.error( "You're running ESPHome with Python <3.7. ESPHome is no longer compatible " "with this Python version. Please reinstall ESPHome with Python 3.7+" ) return 1 if args.command in PRE_CONFIG_ACTIONS: try: return PRE_CONFIG_ACTIONS[args.command](args) except EsphomeError as e: _LOGGER.error(e) return 1 for conf_path in args.configuration: CORE.config_path = conf_path CORE.dashboard = args.dashboard # Added so that the creds generator for TecnoCore knows if it should sanitize passwords or not. CORE.command = args.command config = read_config( dict(args.substitution) if args.substitution else {}) if config is None: return 1 CORE.config = config if args.command not in POST_CONFIG_ACTIONS: safe_print(f"Unknown command {args.command}") try: rc = POST_CONFIG_ACTIONS[args.command](args, config) except EsphomeError as e: _LOGGER.error(e) return 1 if rc != 0: return rc CORE.reset() return 0
def run_esphome(argv): args = parse_args(argv) CORE.dashboard = args.dashboard setup_log(args.verbose, args.quiet) if args.command != 'version' and not args.configuration: _LOGGER.error("Missing configuration parameter, see esphome --help.") return 1 if IS_PY2: _LOGGER.warning( "You're using ESPHome with python 2. Support for python 2 is deprecated " "and will be removed in 1.15.0. Please reinstall ESPHome with python 3.6 " "or higher.") elif IS_PY3 and sys.version_info < (3, 6, 0): _LOGGER.warning( "You're using ESPHome with python 3.5. Support for python 3.5 is " "deprecated and will be removed in 1.15.0. Please reinstall ESPHome with " "python 3.6 or higher.") if args.command in PRE_CONFIG_ACTIONS: try: return PRE_CONFIG_ACTIONS[args.command](args) except EsphomeError as e: _LOGGER.error(e) return 1 for conf_path in args.configuration: CORE.config_path = conf_path CORE.dashboard = args.dashboard config = read_config() if config is None: return 1 CORE.config = config if args.command not in POST_CONFIG_ACTIONS: safe_print(u"Unknown command {}".format(args.command)) try: rc = POST_CONFIG_ACTIONS[args.command](args, config) except EsphomeError as e: _LOGGER.error(e) return 1 if rc != 0: return rc CORE.reset() return 0
def run_esphome(argv): args = parse_args(argv) CORE.dashboard = args.dashboard setup_log(args.verbose, args.quiet) if args.command != 'version' and not args.configuration: _LOGGER.error("Missing configuration parameter, see esphome --help.") return 1 if sys.version_info < (3, 6, 0): _LOGGER.error( "You're running ESPHome with Python <3.6. ESPHome is no longer compatible " "with this Python version. Please reinstall ESPHome with Python 3.6+" ) return 1 if args.command in PRE_CONFIG_ACTIONS: try: return PRE_CONFIG_ACTIONS[args.command](args) except EsphomeError as e: _LOGGER.error(e) return 1 for conf_path in args.configuration: CORE.config_path = conf_path CORE.dashboard = args.dashboard config = read_config() if config is None: return 1 CORE.config = config if args.command not in POST_CONFIG_ACTIONS: safe_print(f"Unknown command {args.command}") try: rc = POST_CONFIG_ACTIONS[args.command](args, config) except EsphomeError as e: _LOGGER.error(e) return 1 if rc != 0: return rc CORE.reset() return 0
def run_esphome(argv): args = parse_args(argv) CORE.dashboard = args.dashboard setup_log(args.verbose, args.quiet) if args.command != 'version' and not args.configuration: _LOGGER.error("Missing configuration parameter, see esphome --help.") return 1 if args.command in PRE_CONFIG_ACTIONS: try: return PRE_CONFIG_ACTIONS[args.command](args) except EsphomeError as e: _LOGGER.error(e) return 1 for conf_path in args.configuration: CORE.config_path = conf_path CORE.dashboard = args.dashboard config = read_config(args.verbose) if config is None: return 1 CORE.config = config if args.command not in POST_CONFIG_ACTIONS: safe_print(u"Unknown command {}".format(args.command)) try: rc = POST_CONFIG_ACTIONS[args.command](args, config) except EsphomeError as e: _LOGGER.error(e) return 1 if rc != 0: return rc CORE.reset() return 0