示例#1
0
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",
        )
示例#2
0
def test_config_file_should_include_ota(default_config):
    """
    The Over-The-Air update should be enabled by default
    """
    # Given

    # When
    config = wz.wizard_file(**default_config)

    # Then
    assert "ota:" in config
示例#3
0
def test_config_file_should_include_ota_when_password_set(default_config):
    """
    The Over-The-Air update should be enabled when a password is set
    """
    # Given
    default_config["password"] = "******"

    # When
    config = wz.wizard_file(**default_config)

    # Then
    assert "ota:" in config
示例#4
0
def test_config_file_fallback_ap_includes_descriptive_name(default_config):
    """
    The fallback AP should include the node and a descriptive name
    """
    # Given
    default_config["name"] = "test_node"

    # When
    config = wz.wizard_file(**default_config)

    # Then
    assert 'ssid: "Test Node Fallback Hotspot"' in config
示例#5
0
def test_config_file_fallback_ap_name_less_than_32_chars(default_config):
    """
    The fallback AP name must be less than 32 chars.
    Since it is composed of the node name and "Fallback Hotspot" this can be too long and needs truncating
    """
    # Given
    default_config["name"] = "a_very_long_name_for_this_node"

    # When
    config = wz.wizard_file(**default_config)

    # Then
    assert 'ssid: "A Very Long Name For This Node"' in config