async def wrapped(conf): cg.add(cg.LineComment(f"{name}:")) if comp.config_schema is not None: conf_str = yaml_util.dump(conf) conf_str = conf_str.replace("//", "") cg.add(cg.LineComment(indent(conf_str))) await coro(conf)
def import_config(path: str, name: str, project_name: str, import_url: str) -> None: p = Path(path) if p.exists(): raise FileExistsError if project_name == "esphome.web": p.write_text( wizard_file( name=name, platform="ESP32" if "esp32" in import_url else "ESP8266", board="esp32dev" if "esp32" in import_url else "esp01_1m", ssid="!secret wifi_ssid", psk="!secret wifi_password", ), encoding="utf8", ) else: config = { "substitutions": {"name": name}, "packages": {project_name: import_url}, "esphome": {"name_add_mac_suffix": False}, } p.write_text( dump(config) + WIFI_CONFIG, encoding="utf8", )
def show_new(value): from esphome import yaml_util for key in BINARY_SENSOR_REGISTRY: if key in value: break else: raise cv.Invalid( "This platform has been removed in 1.13, please see the docs for updated " "instructions.") val = value[key] args = [("platform", "template")] if "id" in value: args.append(("id", value["id"])) if "name" in value: args.append(("name", value["name"])) args.append(("turn_on_action", { f"remote_transmitter.transmit_{key}": val })) text = yaml_util.dump([OrderedDict(args)]) raise cv.Invalid( "This platform has been removed in 1.13, please change to:\n\n{}\n\n." "".format(text))
def wrapped(conf): cg.add(cg.LineComment(f"{name}:")) if comp.config_schema is not None: conf_str = yaml_util.dump(conf) conf_str = conf_str.replace('//', '') cg.add(cg.LineComment(indent(conf_str))) yield coro(conf)
def wrapped(conf): cg.add(cg.LineComment(u"{}:".format(name))) if comp.config_schema is not None: conf_str = yaml_util.dump(conf) if IS_PY2: conf_str = conf_str.decode('utf-8') cg.add(cg.LineComment(indent(conf_str))) yield coro(conf)
async def wrapped(conf): cg.add(cg.LineComment(f"{name}:")) if comp.config_schema is not None: conf_str = yaml_util.dump(conf) conf_str = conf_str.replace("//", "") # remove tailing \ to avoid multi-line comment warning conf_str = conf_str.replace("\\\n", "\n") cg.add(cg.LineComment(indent(conf_str))) await coro(conf)
def import_config(path: str, name: str, project_name: str, import_url: str) -> None: p = Path(path) if p.exists(): raise FileExistsError config = { "substitutions": {"name": name}, "packages": {project_name: import_url}, "esphome": {"name_add_mac_suffix": False}, } p.write_text( dump(config) + WIFI_MESSAGE, encoding="utf8", )
def command_hass_config(args, config): from esphome.components import mqtt as mqtt_component _LOGGER.info( "This is what you should put in your Home Assistant YAML configuration." ) _LOGGER.info( "Please note this is only necessary if you're not using MQTT discovery." ) data = mqtt_component.GenerateHassConfigData(config) hass_config = OrderedDict() for domain, component, conf in iter_components(config): if not hasattr(component, 'to_hass_config'): continue func = getattr(component, 'to_hass_config') ret = func(data, conf) if not isinstance(ret, (list, tuple)): ret = [ret] ret = [x for x in ret if x is not None] domain_conf = hass_config.setdefault(domain.split('.')[0], []) domain_conf += ret safe_print(yaml_util.dump(hass_config)) return 0
def show_new(value): from esphome import yaml_util for key in BINARY_SENSOR_REGISTRY: if key in value: break else: raise cv.Invalid( "This platform has been removed in 1.13, please see the docs for updated " "instructions.") val = value[key] args = [('platform', 'template')] if 'id' in value: args.append(('id', value['id'])) if 'name' in value: args.append(('name', value['name'])) args.append(('turn_on_action', { 'remote_transmitter.transmit_{}'.format(key): val })) text = yaml_util.dump([OrderedDict(args)]) raise cv.Invalid( u"This platform has been removed in 1.13, please change to:\n\n{}\n\n." u"".format(text))
def command_config(args, config): _LOGGER.info("Configuration is valid!") if not CORE.verbose: config = strip_default_ids(config) safe_print(yaml_util.dump(config)) return 0
def _dump_config(): return dump(strip_default_ids(load_yaml(CORE.config_path)))