mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[freeboxos] Avoid useless API requests (server/player) (#17237)
Signed-off-by: Laurent Garnier <lg.hc@free.fr> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
53828a12d9
commit
81261c6da8
@ -89,15 +89,16 @@ public class FreeboxOsBindingConstants {
|
|||||||
// List of all Group Channel ids
|
// List of all Group Channel ids
|
||||||
public static final String GROUP_SENSORS = "sensors";
|
public static final String GROUP_SENSORS = "sensors";
|
||||||
public static final String GROUP_FANS = "fans";
|
public static final String GROUP_FANS = "fans";
|
||||||
public static final String CONNECTION_STATUS = "connection-status";
|
public static final String GROUP_CONNECTION_STATUS = "connection-status";
|
||||||
public static final String SYS_INFO = "sysinfo";
|
public static final String GROUP_SYS_INFO = "sysinfo";
|
||||||
public static final String ACTIONS = "actions";
|
public static final String GROUP_ACTIONS = "actions";
|
||||||
public static final String FILE_SHARING = "file-sharing";
|
public static final String GROUP_PLAYER_STATUS = "player-status";
|
||||||
public static final String CONNECTIVITY = "connectivity";
|
public static final String GROUP_FILE_SHARING = "file-sharing";
|
||||||
public static final String DISPLAY = "display";
|
public static final String GROUP_CONNECTIVITY = "connectivity";
|
||||||
public static final String VM_STATUS = "vmstatus";
|
public static final String GROUP_DISPLAY = "display";
|
||||||
|
public static final String GROUP_VM_STATUS = "vmstatus";
|
||||||
public static final String GROUP_WIFI = "wifi";
|
public static final String GROUP_WIFI = "wifi";
|
||||||
public static final String REPEATER_MISC = "repeater-misc";
|
public static final String GROUP_REPEATER_MISC = "repeater-misc";
|
||||||
|
|
||||||
// List of all Channel ids
|
// List of all Channel ids
|
||||||
public static final String RSSI = "rssi";
|
public static final String RSSI = "rssi";
|
||||||
@ -122,6 +123,7 @@ public class FreeboxOsBindingConstants {
|
|||||||
public static final String BYTES_DOWN = "bytes-down";
|
public static final String BYTES_DOWN = "bytes-down";
|
||||||
public static final String BW = "bandwidth";
|
public static final String BW = "bandwidth";
|
||||||
public static final String PCT_BW = "bandwidth-usage";
|
public static final String PCT_BW = "bandwidth-usage";
|
||||||
|
public static final String CONNECTION_STATUS = "connection-status";
|
||||||
public static final String ONHOOK = "onhook";
|
public static final String ONHOOK = "onhook";
|
||||||
public static final String RINGING = "ringing";
|
public static final String RINGING = "ringing";
|
||||||
public static final String HARDWARE_STATUS = "hardware-status";
|
public static final String HARDWARE_STATUS = "hardware-status";
|
||||||
|
@ -17,6 +17,7 @@ import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.binding.freeboxos.internal.action.ActivePlayerActions;
|
import org.openhab.binding.freeboxos.internal.action.ActivePlayerActions;
|
||||||
@ -52,7 +53,7 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
|
|||||||
public ActivePlayerHandler(Thing thing) {
|
public ActivePlayerHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
statusDrivenByLanConnectivity = false;
|
statusDrivenByLanConnectivity = false;
|
||||||
eventChannelUID = new ChannelUID(getThing().getUID(), SYS_INFO, BOX_EVENT);
|
eventChannelUID = new ChannelUID(getThing().getUID(), GROUP_SYS_INFO, BOX_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,12 +91,14 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
|
|||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-player-not-reachable");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-player-not-reachable");
|
||||||
}
|
}
|
||||||
if (player.reachable()) {
|
if (player.reachable()) {
|
||||||
Status status = getManager(PlayerManager.class).getPlayerStatus(getClientId());
|
if (anyChannelLinked(GROUP_PLAYER_STATUS, Set.of(PLAYER_STATUS, PACKAGE))) {
|
||||||
if (status != null) {
|
Status status = getManager(PlayerManager.class).getPlayerStatus(getClientId());
|
||||||
updateChannelString(PLAYER_STATUS, PLAYER_STATUS, status.powerState().name());
|
if (status != null) {
|
||||||
ForegroundApp foreground = status.foregroundApp();
|
updateChannelString(GROUP_PLAYER_STATUS, PLAYER_STATUS, status.powerState().name());
|
||||||
if (foreground != null) {
|
ForegroundApp foreground = status.foregroundApp();
|
||||||
updateChannelString(PLAYER_STATUS, PACKAGE, foreground._package());
|
if (foreground != null) {
|
||||||
|
updateChannelString(GROUP_PLAYER_STATUS, PACKAGE, foreground._package());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Configuration config = getManager(PlayerManager.class).getConfig(getClientId());
|
Configuration config = getManager(PlayerManager.class).getConfig(getClientId());
|
||||||
@ -105,7 +108,7 @@ public class ActivePlayerHandler extends PlayerHandler implements FreeDeviceIntf
|
|||||||
uptime = 0;
|
uptime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateChannelQuantity(SYS_INFO, UPTIME, uptime, Units.SECOND);
|
updateChannelQuantity(GROUP_SYS_INFO, UPTIME, uptime, Units.SECOND);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("{}: poll with reachable={}", thing.getUID(), reachable);
|
logger.debug("{}: poll with reachable={}", thing.getUID(), reachable);
|
||||||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-player-not-reachable");
|
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "@text/info-player-not-reachable");
|
||||||
|
@ -17,6 +17,7 @@ import java.time.ZonedDateTime;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -355,6 +356,12 @@ public abstract class ApiConsumerHandler extends BaseThingHandler implements Api
|
|||||||
super.updateProperties(properties);
|
super.updateProperties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean anyChannelLinked(String groupId, Set<String> channelSet) {
|
||||||
|
return channelSet.stream().map(id -> new ChannelUID(getThing().getUID(), groupId, id))
|
||||||
|
.anyMatch(uid -> isLinked(uid));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Configuration getConfig() {
|
public Configuration getConfig() {
|
||||||
return super.getConfig();
|
return super.getConfig();
|
||||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.freeboxos.internal.handler;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
@ -45,6 +46,8 @@ public interface ApiConsumerIntf extends ThingHandler {
|
|||||||
|
|
||||||
void updateStatus(ThingStatus status, ThingStatusDetail statusDetail, @Nullable String description);
|
void updateStatus(ThingStatus status, ThingStatusDetail statusDetail, @Nullable String description);
|
||||||
|
|
||||||
|
boolean anyChannelLinked(String groupId, Set<String> channelSet);
|
||||||
|
|
||||||
void stopJobs();
|
void stopJobs();
|
||||||
|
|
||||||
void addJob(String name, Runnable command, long initialDelay, long delay, TimeUnit unit);
|
void addJob(String name, Runnable command, long initialDelay, long delay, TimeUnit unit);
|
||||||
|
@ -119,9 +119,9 @@ public class HostHandler extends ApiConsumerHandler {
|
|||||||
|
|
||||||
public void updateConnectivityChannels(LanHost host) {
|
public void updateConnectivityChannels(LanHost host) {
|
||||||
logger.debug("{}: updateConnectivityChannels with host.reachable() = {}", thing.getUID(), host.reachable());
|
logger.debug("{}: updateConnectivityChannels with host.reachable() = {}", thing.getUID(), host.reachable());
|
||||||
updateChannelOnOff(CONNECTIVITY, REACHABLE, host.reachable());
|
updateChannelOnOff(GROUP_CONNECTIVITY, REACHABLE, host.reachable());
|
||||||
updateChannelDateTimeState(CONNECTIVITY, LAST_SEEN, host.getLastSeen());
|
updateChannelDateTimeState(GROUP_CONNECTIVITY, LAST_SEEN, host.getLastSeen());
|
||||||
updateChannelString(CONNECTIVITY, IP_ADDRESS, host.getIpv4());
|
updateChannelString(GROUP_CONNECTIVITY, IP_ADDRESS, host.getIpv4());
|
||||||
if (statusDrivenByLanConnectivity) {
|
if (statusDrivenByLanConnectivity) {
|
||||||
if (host.reachable()) {
|
if (host.reachable()) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
|
@ -48,7 +48,7 @@ public class RepeaterHandler extends HostHandler implements FreeDeviceIntf {
|
|||||||
|
|
||||||
public RepeaterHandler(Thing thing) {
|
public RepeaterHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
eventChannelUID = new ChannelUID(getThing().getUID(), REPEATER_MISC, BOX_EVENT);
|
eventChannelUID = new ChannelUID(getThing().getUID(), GROUP_REPEATER_MISC, BOX_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,21 +84,21 @@ public class RepeaterHandler extends HostHandler implements FreeDeviceIntf {
|
|||||||
RepeaterManager repeaterManager = getManager(RepeaterManager.class);
|
RepeaterManager repeaterManager = getManager(RepeaterManager.class);
|
||||||
|
|
||||||
Repeater repeater = repeaterManager.getDevice(getClientId());
|
Repeater repeater = repeaterManager.getDevice(getClientId());
|
||||||
updateChannelOnOff(REPEATER_MISC, LED, repeater.ledActivated());
|
updateChannelOnOff(GROUP_REPEATER_MISC, LED, repeater.ledActivated());
|
||||||
updateChannelString(REPEATER_MISC, CONNECTION_STATUS, repeater.connection());
|
updateChannelString(GROUP_REPEATER_MISC, CONNECTION_STATUS, repeater.connection());
|
||||||
|
|
||||||
List<LanHost> hosts = repeaterManager.getRepeaterHosts(getClientId());
|
List<LanHost> hosts = repeaterManager.getRepeaterHosts(getClientId());
|
||||||
updateChannelDecimal(REPEATER_MISC, HOST_COUNT, hosts.size());
|
updateChannelDecimal(GROUP_REPEATER_MISC, HOST_COUNT, hosts.size());
|
||||||
|
|
||||||
uptime = checkUptimeAndFirmware(repeater.getUptimeVal(), uptime, repeater.firmwareVersion());
|
uptime = checkUptimeAndFirmware(repeater.getUptimeVal(), uptime, repeater.firmwareVersion());
|
||||||
updateChannelQuantity(REPEATER_MISC, UPTIME, uptime, Units.SECOND);
|
updateChannelQuantity(GROUP_REPEATER_MISC, UPTIME, uptime, Units.SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean internalHandleCommand(String channelId, Command command) throws FreeboxException {
|
protected boolean internalHandleCommand(String channelId, Command command) throws FreeboxException {
|
||||||
if (ON_OFF_CLASSES.contains(command.getClass()) && LED.equals(channelId)) {
|
if (ON_OFF_CLASSES.contains(command.getClass()) && LED.equals(channelId)) {
|
||||||
getManager(RepeaterManager.class).led(getClientId(), TRUE_COMMANDS.contains(command))
|
getManager(RepeaterManager.class).led(getClientId(), TRUE_COMMANDS.contains(command))
|
||||||
.ifPresent(repeater -> updateChannelOnOff(REPEATER_MISC, LED, repeater.ledActivated()));
|
.ifPresent(repeater -> updateChannelOnOff(GROUP_REPEATER_MISC, LED, repeater.ledActivated()));
|
||||||
}
|
}
|
||||||
return super.internalHandleCommand(channelId, command);
|
return super.internalHandleCommand(channelId, command);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ package org.openhab.binding.freeboxos.internal.handler;
|
|||||||
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
import static org.openhab.binding.freeboxos.internal.FreeboxOsBindingConstants.*;
|
||||||
import static org.openhab.core.library.unit.Units.PERCENT;
|
import static org.openhab.core.library.unit.Units.PERCENT;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.openhab.binding.freeboxos.internal.api.FreeboxException;
|
import org.openhab.binding.freeboxos.internal.api.FreeboxException;
|
||||||
import org.openhab.binding.freeboxos.internal.api.rest.LcdManager;
|
import org.openhab.binding.freeboxos.internal.api.rest.LcdManager;
|
||||||
@ -66,10 +68,12 @@ public class RevolutionHandler extends ServerHandler {
|
|||||||
@Override
|
@Override
|
||||||
protected void internalPoll() throws FreeboxException {
|
protected void internalPoll() throws FreeboxException {
|
||||||
super.internalPoll();
|
super.internalPoll();
|
||||||
Config config = getManager(LcdManager.class).getConfig();
|
if (anyChannelLinked(GROUP_DISPLAY, Set.of(LCD_BRIGHTNESS, LCD_ORIENTATION, LCD_FORCED))) {
|
||||||
updateChannelQuantity(DISPLAY, LCD_BRIGHTNESS, config.brightness(), PERCENT);
|
Config config = getManager(LcdManager.class).getConfig();
|
||||||
updateChannelDecimal(DISPLAY, LCD_ORIENTATION, config.orientation());
|
updateChannelQuantity(GROUP_DISPLAY, LCD_BRIGHTNESS, config.brightness(), PERCENT);
|
||||||
updateChannelOnOff(DISPLAY, LCD_FORCED, config.orientationForced());
|
updateChannelDecimal(GROUP_DISPLAY, LCD_ORIENTATION, config.orientation());
|
||||||
|
updateChannelOnOff(GROUP_DISPLAY, LCD_FORCED, config.orientationForced());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOrientation(LcdManager manager, Config config, Command command) throws FreeboxException {
|
private void setOrientation(LcdManager manager, Config config, Command command) throws FreeboxException {
|
||||||
|
@ -68,7 +68,7 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
|
|||||||
|
|
||||||
public ServerHandler(Thing thing) {
|
public ServerHandler(Thing thing) {
|
||||||
super(thing);
|
super(thing);
|
||||||
eventChannelUID = new ChannelUID(getThing().getUID(), SYS_INFO, BOX_EVENT);
|
eventChannelUID = new ChannelUID(getThing().getUID(), GROUP_SYS_INFO, BOX_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -115,15 +115,27 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
|
|||||||
fetchConnectionStatus();
|
fetchConnectionStatus();
|
||||||
fetchSystemConfig();
|
fetchSystemConfig();
|
||||||
|
|
||||||
updateChannelOnOff(ACTIONS, WIFI_STATUS, getManager(WifiManager.class).getStatus());
|
if (anyChannelLinked(GROUP_ACTIONS, Set.of(WIFI_STATUS))) {
|
||||||
updateChannelOnOff(ACTIONS, AIRMEDIA_STATUS, getManager(AirMediaManager.class).getStatus());
|
updateChannelOnOff(GROUP_ACTIONS, WIFI_STATUS, getManager(WifiManager.class).getStatus());
|
||||||
updateChannelOnOff(ACTIONS, UPNPAV_STATUS, getManager(UPnPAVManager.class).getStatus());
|
}
|
||||||
|
if (anyChannelLinked(GROUP_ACTIONS, Set.of(AIRMEDIA_STATUS))) {
|
||||||
|
updateChannelOnOff(GROUP_ACTIONS, AIRMEDIA_STATUS, getManager(AirMediaManager.class).getStatus());
|
||||||
|
}
|
||||||
|
if (anyChannelLinked(GROUP_ACTIONS, Set.of(UPNPAV_STATUS))) {
|
||||||
|
updateChannelOnOff(GROUP_ACTIONS, UPNPAV_STATUS, getManager(UPnPAVManager.class).getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
Samba response = getManager(SambaManager.class).getConfig();
|
if (anyChannelLinked(GROUP_FILE_SHARING, Set.of(SAMBA_FILE_STATUS, SAMBA_PRINTER_STATUS))) {
|
||||||
updateChannelOnOff(FILE_SHARING, SAMBA_FILE_STATUS, response.fileShareEnabled());
|
Samba response = getManager(SambaManager.class).getConfig();
|
||||||
updateChannelOnOff(FILE_SHARING, SAMBA_PRINTER_STATUS, response.printShareEnabled());
|
updateChannelOnOff(GROUP_FILE_SHARING, SAMBA_FILE_STATUS, response.fileShareEnabled());
|
||||||
updateChannelOnOff(FILE_SHARING, FTP_STATUS, getManager(FtpManager.class).getStatus());
|
updateChannelOnOff(GROUP_FILE_SHARING, SAMBA_PRINTER_STATUS, response.printShareEnabled());
|
||||||
updateChannelOnOff(FILE_SHARING, AFP_FILE_STATUS, getManager(AfpManager.class).getStatus());
|
}
|
||||||
|
if (anyChannelLinked(GROUP_FILE_SHARING, Set.of(FTP_STATUS))) {
|
||||||
|
updateChannelOnOff(GROUP_FILE_SHARING, FTP_STATUS, getManager(FtpManager.class).getStatus());
|
||||||
|
}
|
||||||
|
if (anyChannelLinked(GROUP_FILE_SHARING, Set.of(AFP_FILE_STATUS))) {
|
||||||
|
updateChannelOnOff(GROUP_FILE_SHARING, AFP_FILE_STATUS, getManager(AfpManager.class).getStatus());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchSystemConfig() throws FreeboxException {
|
private void fetchSystemConfig() throws FreeboxException {
|
||||||
@ -133,33 +145,41 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
|
|||||||
config.fans().forEach(f -> updateChannelQuantity(GROUP_FANS, f.id(), f.value(), Units.RPM));
|
config.fans().forEach(f -> updateChannelQuantity(GROUP_FANS, f.id(), f.value(), Units.RPM));
|
||||||
|
|
||||||
uptime = checkUptimeAndFirmware(config.uptimeVal(), uptime, config.firmwareVersion());
|
uptime = checkUptimeAndFirmware(config.uptimeVal(), uptime, config.firmwareVersion());
|
||||||
updateChannelQuantity(SYS_INFO, UPTIME, uptime, Units.SECOND);
|
updateChannelQuantity(GROUP_SYS_INFO, UPTIME, uptime, Units.SECOND);
|
||||||
|
|
||||||
LanConfig lanConfig = getManager(LanManager.class).getConfig();
|
if (anyChannelLinked(GROUP_SYS_INFO, Set.of(IP_ADDRESS))) {
|
||||||
updateChannelString(SYS_INFO, IP_ADDRESS, lanConfig.ip());
|
LanConfig lanConfig = getManager(LanManager.class).getConfig();
|
||||||
|
updateChannelString(GROUP_SYS_INFO, IP_ADDRESS, lanConfig.ip());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchConnectionStatus() throws FreeboxException {
|
private void fetchConnectionStatus() throws FreeboxException {
|
||||||
Status status = getManager(ConnectionManager.class).getConfig();
|
if (anyChannelLinked(GROUP_CONNECTION_STATUS,
|
||||||
updateChannelString(CONNECTION_STATUS, LINE_STATUS, status.state());
|
Set.of(LINE_STATUS, LINE_TYPE, LINE_MEDIA, IP_ADDRESS, IPV6_ADDRESS, BYTES_UP, BYTES_DOWN, RATE + "-up",
|
||||||
updateChannelString(CONNECTION_STATUS, LINE_TYPE, status.type());
|
BW + "-up", PCT_BW + "-up", RATE + "-down", BW + "-down", PCT_BW + "-down"))) {
|
||||||
updateChannelString(CONNECTION_STATUS, LINE_MEDIA, status.media());
|
Status status = getManager(ConnectionManager.class).getConfig();
|
||||||
updateChannelString(CONNECTION_STATUS, IP_ADDRESS, status.ipv4());
|
updateChannelString(GROUP_CONNECTION_STATUS, LINE_STATUS, status.state());
|
||||||
updateChannelString(CONNECTION_STATUS, IPV6_ADDRESS, status.ipv6());
|
updateChannelString(GROUP_CONNECTION_STATUS, LINE_TYPE, status.type());
|
||||||
|
updateChannelString(GROUP_CONNECTION_STATUS, LINE_MEDIA, status.media());
|
||||||
|
updateChannelString(GROUP_CONNECTION_STATUS, IP_ADDRESS, status.ipv4());
|
||||||
|
updateChannelString(GROUP_CONNECTION_STATUS, IPV6_ADDRESS, status.ipv6());
|
||||||
|
|
||||||
updateRateBandwidth(status.rateUp(), status.bandwidthUp(), "up");
|
updateRateBandwidth(status.rateUp(), status.bandwidthUp(), "up");
|
||||||
updateRateBandwidth(status.rateDown(), status.bandwidthDown(), "down");
|
updateRateBandwidth(status.rateDown(), status.bandwidthDown(), "down");
|
||||||
|
|
||||||
updateChannelQuantity(CONNECTION_STATUS, BYTES_UP, new QuantityType<>(status.bytesUp(), OCTET), GIBIOCTET);
|
updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_UP, new QuantityType<>(status.bytesUp(), OCTET),
|
||||||
updateChannelQuantity(CONNECTION_STATUS, BYTES_DOWN, new QuantityType<>(status.bytesDown(), OCTET), GIBIOCTET);
|
GIBIOCTET);
|
||||||
|
updateChannelQuantity(GROUP_CONNECTION_STATUS, BYTES_DOWN, new QuantityType<>(status.bytesDown(), OCTET),
|
||||||
|
GIBIOCTET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRateBandwidth(long rate, long bandwidth, String orientation) {
|
private void updateRateBandwidth(long rate, long bandwidth, String orientation) {
|
||||||
QuantityType<?> rateUp = new QuantityType<>(rate * 8, Units.BIT_PER_SECOND);
|
QuantityType<?> rateUp = new QuantityType<>(rate * 8, Units.BIT_PER_SECOND);
|
||||||
QuantityType<?> bandwidthUp = new QuantityType<>(bandwidth, BIT_PER_SECOND);
|
QuantityType<?> bandwidthUp = new QuantityType<>(bandwidth, BIT_PER_SECOND);
|
||||||
updateChannelQuantity(CONNECTION_STATUS, RATE + "-" + orientation, rateUp, KILOBIT_PER_SECOND);
|
updateChannelQuantity(GROUP_CONNECTION_STATUS, RATE + "-" + orientation, rateUp, KILOBIT_PER_SECOND);
|
||||||
updateChannelQuantity(CONNECTION_STATUS, BW + "-" + orientation, bandwidthUp, KILOBIT_PER_SECOND);
|
updateChannelQuantity(GROUP_CONNECTION_STATUS, BW + "-" + orientation, bandwidthUp, KILOBIT_PER_SECOND);
|
||||||
updateChannelQuantity(CONNECTION_STATUS, PCT_BW + "-" + orientation,
|
updateChannelQuantity(GROUP_CONNECTION_STATUS, PCT_BW + "-" + orientation,
|
||||||
!bandwidthUp.equals(QuantityType.ZERO) ? rateUp.multiply(HUNDRED).divide(bandwidthUp)
|
!bandwidthUp.equals(QuantityType.ZERO) ? rateUp.multiply(HUNDRED).divide(bandwidthUp)
|
||||||
: QuantityType.ZERO,
|
: QuantityType.ZERO,
|
||||||
Units.PERCENT);
|
Units.PERCENT);
|
||||||
@ -171,27 +191,29 @@ public class ServerHandler extends ApiConsumerHandler implements FreeDeviceIntf
|
|||||||
boolean enable = TRUE_COMMANDS.contains(command);
|
boolean enable = TRUE_COMMANDS.contains(command);
|
||||||
switch (channelId) {
|
switch (channelId) {
|
||||||
case WIFI_STATUS:
|
case WIFI_STATUS:
|
||||||
updateChannelOnOff(ACTIONS, WIFI_STATUS, getManager(WifiManager.class).setStatus(enable));
|
updateChannelOnOff(GROUP_ACTIONS, WIFI_STATUS, getManager(WifiManager.class).setStatus(enable));
|
||||||
return true;
|
return true;
|
||||||
case FTP_STATUS:
|
case FTP_STATUS:
|
||||||
updateChannelOnOff(FILE_SHARING, FTP_STATUS, getManager(FtpManager.class).setStatus(enable));
|
updateChannelOnOff(GROUP_FILE_SHARING, FTP_STATUS, getManager(FtpManager.class).setStatus(enable));
|
||||||
return true;
|
return true;
|
||||||
case SAMBA_FILE_STATUS:
|
case SAMBA_FILE_STATUS:
|
||||||
updateChannelOnOff(FILE_SHARING, SAMBA_FILE_STATUS,
|
updateChannelOnOff(GROUP_FILE_SHARING, SAMBA_FILE_STATUS,
|
||||||
getManager(SambaManager.class).setFileShare(enable));
|
getManager(SambaManager.class).setFileShare(enable));
|
||||||
return true;
|
return true;
|
||||||
case SAMBA_PRINTER_STATUS:
|
case SAMBA_PRINTER_STATUS:
|
||||||
updateChannelOnOff(FILE_SHARING, SAMBA_PRINTER_STATUS,
|
updateChannelOnOff(GROUP_FILE_SHARING, SAMBA_PRINTER_STATUS,
|
||||||
getManager(SambaManager.class).setPrintShare(enable));
|
getManager(SambaManager.class).setPrintShare(enable));
|
||||||
return true;
|
return true;
|
||||||
case UPNPAV_STATUS:
|
case UPNPAV_STATUS:
|
||||||
updateChannelOnOff(ACTIONS, UPNPAV_STATUS, getManager(UPnPAVManager.class).setStatus(enable));
|
updateChannelOnOff(GROUP_ACTIONS, UPNPAV_STATUS, getManager(UPnPAVManager.class).setStatus(enable));
|
||||||
return true;
|
return true;
|
||||||
case AFP_FILE_STATUS:
|
case AFP_FILE_STATUS:
|
||||||
updateChannelOnOff(FILE_SHARING, AFP_FILE_STATUS, getManager(AfpManager.class).setStatus(enable));
|
updateChannelOnOff(GROUP_FILE_SHARING, AFP_FILE_STATUS,
|
||||||
|
getManager(AfpManager.class).setStatus(enable));
|
||||||
return true;
|
return true;
|
||||||
case AIRMEDIA_STATUS:
|
case AIRMEDIA_STATUS:
|
||||||
updateChannelOnOff(ACTIONS, AIRMEDIA_STATUS, getManager(AirMediaManager.class).setStatus(enable));
|
updateChannelOnOff(GROUP_ACTIONS, AIRMEDIA_STATUS,
|
||||||
|
getManager(AirMediaManager.class).setStatus(enable));
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -74,8 +74,8 @@ public class VmHandler extends HostHandler {
|
|||||||
|
|
||||||
public void updateVmChannels(VirtualMachine vm) {
|
public void updateVmChannels(VirtualMachine vm) {
|
||||||
boolean running = Status.RUNNING.equals(vm.status());
|
boolean running = Status.RUNNING.equals(vm.status());
|
||||||
updateChannelOnOff(VM_STATUS, STATUS, running);
|
updateChannelOnOff(GROUP_VM_STATUS, STATUS, running);
|
||||||
updateChannelOnOff(CONNECTIVITY, REACHABLE, running);
|
updateChannelOnOff(GROUP_CONNECTIVITY, REACHABLE, running);
|
||||||
if (running) {
|
if (running) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -77,7 +77,7 @@ public class WifiStationHandler extends HostHandler {
|
|||||||
Optional<Station> station = getManager(APManager.class).getStation(mac);
|
Optional<Station> station = getManager(APManager.class).getStation(mac);
|
||||||
if (station.isPresent()) {
|
if (station.isPresent()) {
|
||||||
Station data = station.get();
|
Station data = station.get();
|
||||||
updateChannelDateTimeState(CONNECTIVITY, LAST_SEEN, data.getLastSeen());
|
updateChannelDateTimeState(GROUP_CONNECTIVITY, LAST_SEEN, data.getLastSeen());
|
||||||
updateChannelString(GROUP_WIFI, WIFI_HOST, SERVER_HOST);
|
updateChannelString(GROUP_WIFI, WIFI_HOST, SERVER_HOST);
|
||||||
updateWifiStationChannels(data.signal(), data.getSsid(), data.rxRate(), data.txRate());
|
updateWifiStationChannels(data.signal(), data.getSsid(), data.rxRate(), data.txRate());
|
||||||
return;
|
return;
|
||||||
@ -86,7 +86,7 @@ public class WifiStationHandler extends HostHandler {
|
|||||||
// Search if it is hosted by a repeater
|
// Search if it is hosted by a repeater
|
||||||
Optional<LanHost> wifiHost = getManager(RepeaterManager.class).getHost(mac);
|
Optional<LanHost> wifiHost = getManager(RepeaterManager.class).getHost(mac);
|
||||||
if (wifiHost.isPresent()) {
|
if (wifiHost.isPresent()) {
|
||||||
updateChannelDateTimeState(CONNECTIVITY, LAST_SEEN, wifiHost.get().getLastSeen());
|
updateChannelDateTimeState(GROUP_CONNECTIVITY, LAST_SEEN, wifiHost.get().getLastSeen());
|
||||||
LanAccessPoint lanAp = wifiHost.get().accessPoint();
|
LanAccessPoint lanAp = wifiHost.get().accessPoint();
|
||||||
if (lanAp != null) {
|
if (lanAp != null) {
|
||||||
updateChannelString(GROUP_WIFI, WIFI_HOST, "%s-%s".formatted(lanAp.type(), lanAp.uid()));
|
updateChannelString(GROUP_WIFI, WIFI_HOST, "%s-%s".formatted(lanAp.type(), lanAp.uid()));
|
||||||
|
Loading…
Reference in New Issue
Block a user