mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[Yeelight] Fix disconnect method (#14670)
* fix disconnect --------- Signed-off-by: Alexandr Salamatov <goopilot@gmail.com>
This commit is contained in:
parent
43f016c98a
commit
6757a84b6b
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user