Пример #1
0
def test_update_config(tmpdir, as_root, config_path):
    args = "init --user x --ssid SSID2 --password PWD2 --interface wlan1"
    config_path.write_text(json.dumps(DUMMY_CONTENTS) + "\n")
    with tmpdir.as_cwd():
        assert config_path.exists()
        opts, subcmds = cmd.arguments(args.split())
        subcmds[opts.subcommand].go(opts)
        o = json.loads(config_path.read_text())
        assert o["user"] == "x"
        assert o["interface"] == "wlan1"
        assert o["ssid"] == mangle("SSID2")
        assert o["password"] == mangle("PWD2")
Пример #2
0
def test_first_run(tmpdir, as_root, config_path):
    assert not config_path.exists()
    args = "init --user test --ssid MYSSID --password SECRET"
    args += " --interface MYWLAN"
    with tmpdir.as_cwd():
        opts, subcmds = cmd.arguments(args.split())
        subcmds[opts.subcommand].go(opts)
        o = json.loads(config_path.read_text())
        assert o["user"] == "test"
        assert o["interface"] == "MYWLAN"
        assert o["ssid"] == mangle("MYSSID")
        assert o["password"] == mangle("SECRET")
Пример #3
0
def go(opts):
    config.exists(fail=False)
    cfg = config.load()
    if os.getuid() == 0:
        # root
        opts.ssid = mangle(opts.ssid)
        opts.password = mangle(opts.password)
        config.root_update(cfg, opts)
        config.save(cfg)
    else:
        # Normal user mode
        config.update(cfg, opts)
        config.save(cfg)
Пример #4
0
def go(opts):
    exists(fail=True)
    cfg = load()
    if os.getuid() == 0:
        if opts.ssid:
            opts.ssid = mangle(opts.ssid)
        if opts.password:
            opts.password = mangle(opts.password)

        root_update(cfg, opts)
        save(cfg)
    else:
        # Normal user mode
        update(cfg, opts)
        save(cfg)
    if opts.show:
        print(json.dumps(cfg, indent=4))
Пример #5
0
def connect(name):
    cfg = load()
    devices = list_devices(cfg)
    if name in devices:
        p = dict()
        p["domain"] = cfg["server"]
        p["port"] = cfg["port"]
        p["ca_cert"] = cfg["ca_cert"]
        device = cfg["devices"][name]
        key = mangle(name)
        p["uuid"] = device["hardware"]["uuid"]
        p["devName"] = name
        p["devType"] = device["hardware"]["type"]
        p["hdwareVersion"] = device["hardware"]["version"]
        p["fmwareVersion"] = device["firmware"]["version"]
        return Mss310("token", key, None, **p)
Пример #6
0
def go(opts):
    log = logging.getLogger("meross_powerplug")
    log.setLevel(logging.WARNING)
    cfg = config.load()
    p = dict()
    p["domain"] = cfg["server"]
    p["port"] = cfg["port"]
    p["ca_cert"] = cfg["ca_cert"]

    all_devices = sorted(config.list_devices(cfg))
    devices = []
    for name in opts.name:
        if name == "all":
            devices.extend(all_devices)
            continue
        if name.startswith("~"):
            rm = name.lstrip("~")
            try:
                devices.remove(rm)
            except ValueError:
                print('unknown device: "{}"'.format(rm))
        else:
            devices.append(name)

    plugs = []
    for dev in devices:
        device = cfg["devices"][dev]
        key = mangle(dev)
        p["uuid"] = device["hardware"]["uuid"]
        p["devName"] = dev
        p["devType"] = device["hardware"]["type"]
        p["hdwareVersion"] = device["hardware"]["version"]
        p["fmwareVersion"] = device["firmware"]["version"]
        plugs.append(Mss310("token", key, None, **p))

    if len(plugs) == 1:
        devmon(plugs[0],
               delay=opts.delay,
               abserr=opts.abserr,
               relerr=opts.relerr)
    else:
        for p in plugs:
            dV, mA, mW = electricity(p)
            output(p._name, dV, mA, mW, ts=False)
Пример #7
0
def set_server_details(cfg, opts):
    header = HEADERS.copy()
    header["method"] = "SET"
    header["namespace"] = "Appliance.Config.Key"
    header["payloadVersion"] = 1
    header["timestamp"] = 0
    key = mangle(opts.name)
    payload = dict({
        "key": {
            "gateway": {
                "host": cfg["server"],
                "port": cfg["port"],
                "secondHost": cfg["server"],
                "secondPort": cfg["port"]
            },
            "key": key,
            "userId": key
        }
    })

    data = dict({"header": header, "payload": payload})
    return send(URL + "/config/", data)