[Yeelight] Fix disconnect method (#14670)

* fix disconnect

---------

Signed-off-by: Alexandr Salamatov <goopilot@gmail.com>
This commit is contained in:
goopilot 2023-03-26 05:16:09 -05:00 committed by GitHub
parent 43f016c98a
commit 6757a84b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -80,6 +80,11 @@ public abstract class YeelightHandlerBase extends BaseThingHandler
DeviceManager.getInstance().startDiscovery(15 * 1000);
}
@Override
public void dispose() {
mDevice.disconnect();
}
private DeviceType getDeviceModel(ThingTypeUID typeUID) {
if (typeUID.equals(THING_TYPE_CEILING)) {
return DeviceType.ceiling;

View File

@ -299,6 +299,11 @@ public abstract class DeviceBase {
mConnection.connect();
}
public void disconnect() {
setConnectionState(ConnectState.DISCONNECTED);
mConnection.disconnect();
}
public void setConnectionState(ConnectState connectState) {
logger.debug("{}: set connection state to: {}", TAG, connectState.name());
if (connectState == ConnectState.DISCONNECTED) {

View File

@ -128,6 +128,20 @@ public class WifiConnection implements ConnectionBase {
@Override
public boolean disconnect() {
mDevice.setAutoConnect(false);
return false;
mCmdRun = false;
try {
if (mConnectThread != null) {
mConnectThread.interrupt();
}
if (mSocket != null) {
mSocket.close();
}
} catch (Exception e) {
logger.debug("Exception while terminating connection", e);
} finally {
mSocket = null;
mDevice.setConnectionState(ConnectState.DISCONNECTED);
}
return true;
}
}