[mikrotik] WiFi client logging and presence problem fix (#11386)
* [mikrotik] WiFi client fix Signed-off-by: Oleg Vivtash <oleg@vivtash.net> * [mikrotik] Thing types and WiFi client presence update Signed-off-by: Oleg Vivtash <oleg@vivtash.net>
This commit is contained in:
@@ -127,10 +127,10 @@ public class MikrotikInterfaceThingHandler extends MikrotikBaseThingHandler<Inte
|
||||
newState = StateUtil.stringOrNull(iface.getMacAddress());
|
||||
break;
|
||||
case MikrotikBindingConstants.CHANNEL_ENABLED:
|
||||
newState = StateUtil.boolOrNull(iface.isEnabled());
|
||||
newState = StateUtil.boolSwitchOrNull(iface.isEnabled());
|
||||
break;
|
||||
case MikrotikBindingConstants.CHANNEL_CONNECTED:
|
||||
newState = StateUtil.boolOrNull(iface.isConnected());
|
||||
newState = StateUtil.boolContactOrNull(iface.isConnected());
|
||||
break;
|
||||
case MikrotikBindingConstants.CHANNEL_LAST_LINK_DOWN_TIME:
|
||||
newState = StateUtil.timeOrNull(iface.getLastLinkDownTime());
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MikrotikWirelessClientThingHandler extends MikrotikBaseThingHandler
|
||||
super(thing);
|
||||
}
|
||||
|
||||
private boolean fetchModels() {
|
||||
private void fetchModels() {
|
||||
var cfg = this.config;
|
||||
if (cfg != null) {
|
||||
RouterosDevice routeros = getRouterOs();
|
||||
@@ -91,19 +91,15 @@ public class MikrotikWirelessClientThingHandler extends MikrotikBaseThingHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.wifiReg != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshModels() {
|
||||
this.online = fetchModels();
|
||||
if (online) {
|
||||
lastSeen = LocalDateTime.now();
|
||||
} else {
|
||||
continuousConnection = false;
|
||||
}
|
||||
fetchModels();
|
||||
var wifiReg = this.wifiReg;
|
||||
if (wifiReg != null) {
|
||||
this.lastSeen = LocalDateTime.now();
|
||||
this.online = true;
|
||||
var cfg = this.config;
|
||||
int considerContinuous = 180;
|
||||
if (cfg != null) {
|
||||
@@ -116,28 +112,27 @@ public class MikrotikWirelessClientThingHandler extends MikrotikBaseThingHandler
|
||||
LocalDateTime uptimeStart = wifiReg.getUptimeStart();
|
||||
continuousConnection = (uptimeStart != null)
|
||||
&& LocalDateTime.now().isAfter(uptimeStart.plusSeconds(considerContinuous));
|
||||
} else {
|
||||
this.online = false;
|
||||
this.continuousConnection = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshChannel(ChannelUID channelUID) {
|
||||
var wifiReg = this.wifiReg;
|
||||
if (wifiReg == null) {
|
||||
logger.warn("wifiReg is null in refreshChannel({})", channelUID);
|
||||
return;
|
||||
}
|
||||
|
||||
String channelID = channelUID.getIdWithoutGroup();
|
||||
State oldState = currentState.getOrDefault(channelID, UnDefType.NULL);
|
||||
State newState = oldState;
|
||||
|
||||
if (channelID.equals(CHANNEL_CONNECTED)) {
|
||||
newState = StateUtil.boolOrNull(online);
|
||||
newState = StateUtil.boolContactOrNull(this.online);
|
||||
} else if (channelID.equals(CHANNEL_LAST_SEEN)) {
|
||||
newState = StateUtil.timeOrNull(lastSeen);
|
||||
} else if (channelID.equals(CHANNEL_CONTINUOUS)) {
|
||||
newState = StateUtil.boolOrNull(continuousConnection);
|
||||
} else if (!online) {
|
||||
newState = StateUtil.boolContactOrNull(this.continuousConnection);
|
||||
} else if (!this.online || wifiReg == null) {
|
||||
newState = UnDefType.NULL;
|
||||
} else {
|
||||
switch (channelID) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
@@ -63,13 +64,20 @@ public class StateUtil {
|
||||
return value == null ? UnDefType.NULL : new DecimalType(value);
|
||||
}
|
||||
|
||||
public static State boolOrNull(@Nullable Boolean value) {
|
||||
public static State boolSwitchOrNull(@Nullable Boolean value) {
|
||||
if (value == null) {
|
||||
return UnDefType.NULL;
|
||||
}
|
||||
return value ? OnOffType.ON : OnOffType.OFF;
|
||||
}
|
||||
|
||||
public static State boolContactOrNull(@Nullable Boolean value) {
|
||||
if (value == null) {
|
||||
return UnDefType.NULL;
|
||||
}
|
||||
return value ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
|
||||
}
|
||||
|
||||
public static State timeOrNull(@Nullable LocalDateTime value) {
|
||||
return value == null ? UnDefType.NULL : new DateTimeType(value.atZone(ZoneId.systemDefault()));
|
||||
}
|
||||
|
||||
@@ -237,14 +237,14 @@
|
||||
</channel-type>
|
||||
|
||||
<channel-type id="connected">
|
||||
<item-type>Switch</item-type>
|
||||
<item-type>Contact</item-type>
|
||||
<label>Connected</label>
|
||||
<description>Reflects connected or disconnected state</description>
|
||||
<state readOnly="true"/>
|
||||
</channel-type>
|
||||
|
||||
<channel-type id="continuous">
|
||||
<item-type>Switch</item-type>
|
||||
<item-type>Contact</item-type>
|
||||
<label>Continuous</label>
|
||||
<description>Connection is considered long-running</description>
|
||||
<state readOnly="true"/>
|
||||
|
||||
Reference in New Issue
Block a user