mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[OmniLink] Minor restructuring of binding code (#10280)
* Minor restructuring of binding code Signed-off-by: Ethan Dye <mrtops03@gmail.com> * Ensure that SystemType is present before switch Signed-off-by: Ethan Dye <mrtops03@gmail.com> * Log on invalid System Type Signed-off-by: Ethan Dye <mrtops03@gmail.com>
This commit is contained in:
parent
63450a32c3
commit
df4a22ba9b
@ -13,6 +13,7 @@
|
||||
package org.openhab.binding.omnilink.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
@ -34,8 +35,7 @@ public enum SystemType {
|
||||
this.modelNumbers = Set.of(modelNumbers);
|
||||
}
|
||||
|
||||
public static SystemType getType(int modelNumber) {
|
||||
return Arrays.stream(values()).filter(s -> s.modelNumbers.contains(modelNumber)).findFirst()
|
||||
.orElseThrow(IllegalArgumentException::new);
|
||||
public static Optional<SystemType> getType(int modelNumber) {
|
||||
return Arrays.stream(values()).filter(s -> s.modelNumbers.contains(modelNumber)).findFirst();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.omnilink.internal.handler;
|
||||
package org.openhab.binding.omnilink.internal;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
@ -17,7 +17,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.omnilink.internal.handler.BridgeOfflineException;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.binding.omnilink.internal.handler.OmnilinkBridgeHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -21,11 +21,12 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.SystemType;
|
||||
import org.openhab.binding.omnilink.internal.handler.BridgeOfflineException;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.binding.omnilink.internal.handler.OmnilinkBridgeHandler;
|
||||
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
||||
import org.openhab.core.config.discovery.DiscoveryResult;
|
||||
@ -62,7 +63,7 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
|
||||
private final Logger logger = LoggerFactory.getLogger(OmnilinkDiscoveryService.class);
|
||||
private static final int DISCOVER_TIMEOUT_SECONDS = 30;
|
||||
private @Nullable OmnilinkBridgeHandler bridgeHandler;
|
||||
private @Nullable SystemType systemType;
|
||||
private Optional<SystemType> systemType = Optional.empty();
|
||||
private @Nullable List<AreaProperties> areas;
|
||||
|
||||
/**
|
||||
@ -389,7 +390,6 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
|
||||
int thingNumber = areaProperties.getNumber();
|
||||
String thingName = areaProperties.getName();
|
||||
String thingID = Integer.toString(thingNumber);
|
||||
ThingUID thingUID = null;
|
||||
|
||||
/*
|
||||
* It seems that for simple OmniLink Controller configurations there
|
||||
@ -405,27 +405,24 @@ public class OmnilinkDiscoveryService extends AbstractDiscoveryService
|
||||
|
||||
Map<String, Object> properties = Map.of(THING_PROPERTIES_NAME, thingName);
|
||||
|
||||
final SystemType systemType = this.systemType;
|
||||
if (systemType != null) {
|
||||
switch (systemType) {
|
||||
final String name = thingName;
|
||||
systemType.ifPresentOrElse(t -> {
|
||||
ThingUID thingUID = null;
|
||||
switch (t) {
|
||||
case LUMINA:
|
||||
thingUID = new ThingUID(THING_TYPE_LUMINA_AREA, bridgeUID, thingID);
|
||||
break;
|
||||
case OMNI:
|
||||
thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown System Type");
|
||||
thingUID = new ThingUID(THING_TYPE_OMNI_AREA, bridgeUID, thingID);
|
||||
}
|
||||
}
|
||||
|
||||
if (thingUID != null) {
|
||||
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties)
|
||||
.withProperty(THING_PROPERTIES_NUMBER, thingID)
|
||||
.withRepresentationProperty(THING_PROPERTIES_NUMBER).withBridge(bridgeUID)
|
||||
.withLabel(thingName).build();
|
||||
.withRepresentationProperty(THING_PROPERTIES_NUMBER).withBridge(bridgeUID).withLabel(name)
|
||||
.build();
|
||||
thingDiscovered(discoveryResult);
|
||||
}
|
||||
}, () -> {
|
||||
logger.warn("Unknown System Type");
|
||||
});
|
||||
|
||||
areas.add(areaProperties);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.binding.omnilink.internal.handler;
|
||||
package org.openhab.binding.omnilink.internal.exceptions;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
@ -21,9 +21,8 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
* @author Craig Hamilton - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
@SuppressWarnings("serial")
|
||||
public class BridgeOfflineException extends Exception {
|
||||
private static final long serialVersionUID = -9081729691518514097L;
|
||||
|
||||
public BridgeOfflineException(Exception e) {
|
||||
super(e);
|
||||
}
|
@ -22,6 +22,7 @@ import java.util.Optional;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.binding.omnilink.internal.AreaAlarm;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
|
@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
import org.openhab.core.thing.Thing;
|
||||
import org.openhab.core.thing.binding.BaseThingHandler;
|
||||
|
@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
|
@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.AudioPlayer;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.NextPreviousType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
|
@ -22,8 +22,10 @@ import javax.measure.quantity.Dimensionless;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.TemperatureFormat;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.unit.Units;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
|
@ -21,6 +21,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.thing.ChannelUID;
|
||||
import org.openhab.core.thing.Thing;
|
||||
|
@ -28,8 +28,10 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.AudioPlayer;
|
||||
import org.openhab.binding.omnilink.internal.SystemType;
|
||||
import org.openhab.binding.omnilink.internal.TemperatureFormat;
|
||||
import org.openhab.binding.omnilink.internal.config.OmnilinkBridgeConfig;
|
||||
import org.openhab.binding.omnilink.internal.discovery.OmnilinkDiscoveryService;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
@ -93,7 +95,7 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
|
||||
private @Nullable ScheduledFuture<?> eventPollingJob;
|
||||
private final int autoReconnectPeriod = 60;
|
||||
private Optional<AudioPlayer> audioPlayer = Optional.empty();
|
||||
private @Nullable SystemType systemType = null;
|
||||
private Optional<SystemType> systemType = Optional.empty();
|
||||
private final Gson gson = new Gson();
|
||||
private int eventLogNumber = 0;
|
||||
|
||||
@ -306,28 +308,23 @@ public class OmnilinkBridgeHandler extends BaseBridgeHandler implements Notifica
|
||||
theThing.map(Thing::getHandler)
|
||||
.ifPresent(theHandler -> ((ZoneHandler) theHandler).handleStatus(zoneStatus));
|
||||
} else if (status instanceof ExtendedAreaStatus) {
|
||||
final SystemType systemType = this.systemType;
|
||||
ExtendedAreaStatus areaStatus = (ExtendedAreaStatus) status;
|
||||
int areaNumber = areaStatus.getNumber();
|
||||
|
||||
if (systemType != null) {
|
||||
logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus);
|
||||
Optional<Thing> theThing;
|
||||
switch (systemType) {
|
||||
case OMNI:
|
||||
theThing = getChildThing(THING_TYPE_OMNI_AREA, areaNumber);
|
||||
break;
|
||||
logger.debug("Received status update for Area: {}, status: {}", areaNumber, areaStatus);
|
||||
systemType.ifPresent(t -> {
|
||||
Optional<Thing> theThing = Optional.empty();
|
||||
switch (t) {
|
||||
case LUMINA:
|
||||
theThing = getChildThing(THING_TYPE_LUMINA_AREA, areaNumber);
|
||||
break;
|
||||
default:
|
||||
theThing = Optional.empty();
|
||||
case OMNI:
|
||||
theThing = getChildThing(THING_TYPE_OMNI_AREA, areaNumber);
|
||||
break;
|
||||
}
|
||||
theThing.map(Thing::getHandler)
|
||||
.ifPresent(theHandler -> ((AbstractAreaHandler) theHandler).handleStatus(areaStatus));
|
||||
} else {
|
||||
logger.debug("Received null System Type!");
|
||||
}
|
||||
});
|
||||
} else if (status instanceof ExtendedAccessControlReaderLockStatus) {
|
||||
ExtendedAccessControlReaderLockStatus lockStatus = (ExtendedAccessControlReaderLockStatus) status;
|
||||
int lockNumber = lockStatus.getNumber();
|
||||
|
@ -22,8 +22,10 @@ import javax.measure.quantity.Temperature;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.TemperatureFormat;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.unit.ImperialUnits;
|
||||
import org.openhab.core.library.unit.SIUnits;
|
||||
|
@ -24,8 +24,10 @@ import javax.measure.quantity.Temperature;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.TemperatureFormat;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
|
@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
|
@ -23,6 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequest;
|
||||
import org.openhab.binding.omnilink.internal.discovery.ObjectPropertyRequests;
|
||||
import org.openhab.binding.omnilink.internal.exceptions.BridgeOfflineException;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
|
Loading…
Reference in New Issue
Block a user