0

我正在尝试通过 LIFXClient 框架连接我的智能灯,但不幸的是我不明白如何使用这个库。该库看起来很简单,这里是链接

我正在尝试通过此功能更改颜色:

LIFXClient.connect(host: .ipv4(IPv4Address("192.168.1.4")!)).then { client in
    return client.light.setColor(color: .orange)
}

但是每次我使用它都会创建与不同本地端口的新连接。由于快速更改颜色后缺少可用端口,我无法与灯泡建立新连接。

几天来,我一直在尝试不创建新连接,而只使用一个,不幸的是我不知道该怎么做。

LIFXClient 连接到 Lamp 的函数:

public class LIFXClient: LIFXConnection {
    public class func connect(host: NWEndpoint.Host, port: NWEndpoint.Port = 56700, queue: DispatchQueue = DispatchQueue(label: "LIFX Queue"), source: UInt32 = UInt32.random(), target: UInt64 = 0) -> Promise<LIFXClient> {
        return NWConnection(host: host, port: port, using: .udp).connect(queue: queue).map { connection in
            return LIFXClient(connection: connection, source: source, target: target)
        }
    }
}

如果我只能保存 client.light 参考,那就太好了,但不幸的是我不能这样做:

var myClient: LIFXClient

LIFXClient.connect(host: .ipv4(IPv4Address("192.168.1.4")!)).then { client in
    myClient = client.light
    return client.light.setColor(color: .orange)
}

这个框架的开发者没有给我回信,我真的不知道如何解决它。非常感谢您的帮助。

4

0 回答 0