import org.openhab.binding.unifi.internal.api.dto.UnfiPortOverrideJsonElement;
import org.openhab.binding.unifi.internal.api.dto.UniFiClient;
import org.openhab.binding.unifi.internal.api.dto.UniFiDevice;
+import org.openhab.binding.unifi.internal.api.dto.UniFiPortTable;
import org.openhab.binding.unifi.internal.api.dto.UniFiPortTuple;
import org.openhab.binding.unifi.internal.api.dto.UniFiSite;
import org.openhab.binding.unifi.internal.api.dto.UniFiWlan;
devicesCache.putAll(devices);
if (devices != null) {
Stream.of(devices).filter(Objects::nonNull).forEach(d -> {
- Stream.ofNullable(d.getPortTable()).filter(ptl -> ptl.length > 0 && ptl[0].isPortPoe()).forEach(pt -> {
- final Map<Integer, UniFiPortTuple> tupleTable = devicesToPortTables.computeIfAbsent(d.getMac(),
- p -> new HashMap<>());
-
- Stream.of(pt).forEach(p -> {
- final UniFiPortTuple tuple = tupleTable.computeIfAbsent(p.getPortIdx(),
- t -> new UniFiPortTuple());
-
- tuple.setDevice(d);
- tuple.setTable(p);
- });
- });
- Stream.ofNullable(d.getPortOverrides()).filter(ptl -> ptl.length > 0).forEach(po -> {
+ Stream.ofNullable(d.getPortTable()).flatMap(pt -> Stream.of(pt)).filter(UniFiPortTable::isPortPoe)
+ .forEach(p -> {
+ final Map<Integer, UniFiPortTuple> tupleTable = devicesToPortTables
+ .computeIfAbsent(d.getMac(), tt -> new HashMap<>());
+ final UniFiPortTuple tuple = tupleTable.computeIfAbsent(p.getPortIdx(),
+ t -> new UniFiPortTuple());
+
+ tuple.setDevice(d);
+ tuple.setTable(p);
+ });
+ Stream.ofNullable(d.getPortOverrides()).forEach(po -> {
final Map<Integer, UniFiPortTuple> tupleTable = devicesToPortTables.get(d.getMac());
if (tupleTable != null) {
Stream.of(po).filter(pof -> !pof.getAsJsonObject().entrySet().isEmpty())
- .map(UnfiPortOverrideJsonElement::new)
- .forEach(p -> tupleTable.get(p.getPortIdx()).setJsonElement(p));
+ .map(UnfiPortOverrideJsonElement::new).forEach(p -> tupleTable
+ .computeIfAbsent(p.getPortIdx(), t -> new UniFiPortTuple()).setJsonElement(p));
}
});
});
@Override
protected State getChannelState(final Map<Integer, UniFiPortTuple> ports, final String channelId) {
- final UniFiPortTable port = getPort(ports).getTable();
+ final UniFiPortTuple portTuple = getPort(ports);
+
+ if (portTuple == null) {
+ return setOfflineOnNoPoEPortData();
+ }
+ final UniFiPortTable port = portTuple.getTable();
if (port == null) {
- logger.debug("No PoE port for thing '{}' could be found in the data. Refresh ignored.",
- getThing().getUID());
- return UnDefType.NULL;
+ return setOfflineOnNoPoEPortData();
}
final State state;
return state;
}
+ private State setOfflineOnNoPoEPortData() {
+ if (getThing().getStatus() != ThingStatus.OFFLINE) {
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+ "@text/error.thing.poe.offline.nodata_error");
+ }
+ return UnDefType.NULL;
+ }
+
private @Nullable UniFiPortTuple getPort(final Map<Integer, UniFiPortTuple> ports) {
return ports.get(config.getPortNumber());
}
error.thing.offline.bridge_offline = The UniFi Controller is currently offline.
error.thing.offline.configuration_error = You must choose a UniFi Controller for this thing.
error.thing.poe.offline.configuration_error = The configuration parameter macAddress must be set and not be empty.
+error.thing.poe.offline.nodata_error = No data for the PoE port could be found in the UniFi API data. See TRACE log for actual API data.
error.thing.site.offline.configuration_error = The configuration parameter sid must be set and not be empty.