Exemplo n.º 1
0
def test_network_key_not_set():
    from set_config import ConfigBuilder
    config = {}
    options = json.loads(TEST_JSON)
    cfg = ConfigBuilder(config, options)
    if options.get("network_key", None):
        cfg.set_option('network_key', category='advanced')
    assert cfg.get_config('network_key', category='advanced') is None
Exemplo n.º 2
0
def test_config_set_log_dir():
    from set_config import ConfigBuilder
    config = {}
    options = json.loads(TEST_JSON)
    cfg = ConfigBuilder(config, options)
    cfg.set_log_dir("/share/zigbee2mqtt")
    assert cfg.get_config(
        "log_directory",
        category="advanced") == Path("/share/zigbee2mqtt/logs/")
Exemplo n.º 3
0
def test_config_disable_overwrite():
    from set_config import ConfigBuilder
    options_path = Path('./zigbee2mqtt/test_hassio_options.json')
    with open(options_path) as f:
        options = json.load(f)
    # set_option should do nothing when overwrite set to True
    options["overwrite"] = True
    options["mqtt_base_topic"] = "neversetme"
    cfg = ConfigBuilder({"mqtt": {"base_topic": "zigbee2mqtt"}}, options)
    cfg.set_option('mqtt_base_topic',
                   category='mqtt',
                   alt_config_name='base_topic')
    assert cfg.get_config('base_topic', category="mqtt") == "zigbee2mqtt"
Exemplo n.º 4
0
def test_config_build_end_to_end():
    from set_config import ConfigBuilder
    options = json.loads(TEST_JSON)
    config = {}
    cfg = ConfigBuilder(config, options)
    data_path = "/share/zigbee2mqtt"

    cfg.set_option('homeassistant')
    cfg.set_option('permit_join')
    cfg.set_option('mqtt_base_topic',
                   category='mqtt',
                   alt_config_name='base_topic')
    cfg.set_option('mqtt_server', category='mqtt', alt_config_name='server')
    cfg.set_option('mqtt_client_id',
                   category='mqtt',
                   alt_config_name='client_id')
    if options.get("mqtt_user", None) or options.get("mqtt_pass", None):
        cfg.set_option('mqtt_user', category='mqtt', alt_config_name='user')
        cfg.set_option('mqtt_pass',
                       category='mqtt',
                       alt_config_name='password')
    cfg.set_option('serial_port', category='serial', alt_config_name='port')
    cfg.set_option('disable_led', category='serial')
    cfg.set_option('cache_state', category='advanced')
    cfg.set_log_dir(data_path)
    cfg.set_option('log_level', category='advanced')
    cfg.set_option('rtscts', category='advanced')

    print(config)

    assert cfg.get_config('homeassistant') is True
    assert cfg.get_config('permit_join') is True
    assert cfg.get_config('base_topic', category='mqtt') == "zigbee2mqtt"
    assert cfg.get_config('server', category='mqtt') == "mqtt://localhost"
    assert cfg.get_config('client_id', category='mqtt') == "test"
    assert cfg.get_config('user', category='mqtt') == "username"
    assert cfg.get_config('password', category='mqtt') == "secret"
    assert cfg.get_config('port', category='serial') == "/dev/ttyACM0"
    assert cfg.get_config('disable_led', category='serial') is True
    assert cfg.get_config('log_level', category='advanced') == "debug"
    assert cfg.get_config(
        'log_directory',
        category='advanced') == Path("/share/zigbee2mqtt/logs/")
    assert cfg.get_config('rtscts', category='advanced') is False
    assert cfg.get_config('cache_state', category='advanced') is True