mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-26 15:21:41 +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);
|
DeviceManager.getInstance().startDiscovery(15 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
mDevice.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
private DeviceType getDeviceModel(ThingTypeUID typeUID) {
|
private DeviceType getDeviceModel(ThingTypeUID typeUID) {
|
||||||
if (typeUID.equals(THING_TYPE_CEILING)) {
|
if (typeUID.equals(THING_TYPE_CEILING)) {
|
||||||
return DeviceType.ceiling;
|
return DeviceType.ceiling;
|
||||||
|
@ -299,6 +299,11 @@ public abstract class DeviceBase {
|
|||||||
mConnection.connect();
|
mConnection.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
setConnectionState(ConnectState.DISCONNECTED);
|
||||||
|
mConnection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
public void setConnectionState(ConnectState connectState) {
|
public void setConnectionState(ConnectState connectState) {
|
||||||
logger.debug("{}: set connection state to: {}", TAG, connectState.name());
|
logger.debug("{}: set connection state to: {}", TAG, connectState.name());
|
||||||
if (connectState == ConnectState.DISCONNECTED) {
|
if (connectState == ConnectState.DISCONNECTED) {
|
||||||
|
@ -128,6 +128,20 @@ public class WifiConnection implements ConnectionBase {
|
|||||||
@Override
|
@Override
|
||||||
public boolean disconnect() {
|
public boolean disconnect() {
|
||||||
mDevice.setAutoConnect(false);
|
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