package org.openhab.binding.omnilink.internal;
import java.util.Arrays;
+import java.util.Optional;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault;
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();
}
}
--- /dev/null
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.omnilink.internal;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+import com.digitaldan.jomnilinkII.MessageUtils;
+
+/**
+ * The {@link TemperatureFormat} defines some methods that are used to
+ * convert OmniLink temperature values into Fahrenheit or Celsius.
+ *
+ * @author Craig Hamilton - Initial contribution
+ * @author Ethan Dye - openHAB3 rewrite
+ */
+@NonNullByDefault
+public enum TemperatureFormat {
+ // Don't convert zero - it appears that is what omni returns when there is no value.
+ CELSIUS(2) {
+ @Override
+ public float omniToFormat(int omniNumber) {
+ return MessageUtils.omniToC(omniNumber);
+ }
+
+ @Override
+ public int formatToOmni(float celsius) {
+ return MessageUtils.CToOmni(celsius);
+ }
+ },
+ FAHRENHEIT(1) {
+ @Override
+ public float omniToFormat(int omniNumber) {
+ return MessageUtils.omniToF(omniNumber);
+ }
+
+ @Override
+ public int formatToOmni(float fahrenheit) {
+ return MessageUtils.FtoOmni(fahrenheit);
+ }
+ };
+
+ private final int formatNumber;
+
+ private TemperatureFormat(int formatNumber) {
+ this.formatNumber = formatNumber;
+ }
+
+ /**
+ * Convert a number represented by the omni to the format.
+ *
+ * @param omniNumber Number to convert
+ * @return Number converted to appropriate format.
+ */
+ public abstract float omniToFormat(int omniNumber);
+
+ /**
+ * Convert a number from this format into an omni number.
+ *
+ * @param format Number in the current format.
+ * @return Omni formatted number.
+ */
+ public abstract int formatToOmni(float format);
+
+ /**
+ * Get the number which identifies this format as defined by the omniprotocol.
+ *
+ * @return Number which identifies this temperature format.
+ */
+ public int getFormatNumber() {
+ return formatNumber;
+ }
+
+ public static TemperatureFormat valueOf(int tempFormat) {
+ if (tempFormat == CELSIUS.formatNumber) {
+ return CELSIUS;
+ } else if (tempFormat == FAHRENHEIT.formatNumber) {
+ return FAHRENHEIT;
+ } else {
+ throw new IllegalArgumentException("Invalid temperature format!");
+ }
+ }
+}
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;
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;
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;
/**
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
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);
}
--- /dev/null
+/**
+ * Copyright (c) 2010-2021 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.omnilink.internal.exceptions;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * The {@link BridgeOfflineException} defines an exception for when the OmniLink
+ * Bridge is offline or unavailable.
+ *
+ * @author Craig Hamilton - Initial contribution
+ */
+@NonNullByDefault
+@SuppressWarnings("serial")
+public class BridgeOfflineException extends Exception {
+ public BridgeOfflineException(Exception e) {
+ super(e);
+ }
+}
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;
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;
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;
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;
+++ /dev/null
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.omnilink.internal.handler;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * The {@link BridgeOfflineException} defines an exception for when the OmniLink
- * Bridge is offline or unavailable.
- *
- * @author Craig Hamilton - Initial contribution
- */
-@NonNullByDefault
-public class BridgeOfflineException extends Exception {
- private static final long serialVersionUID = -9081729691518514097L;
-
- public BridgeOfflineException(Exception e) {
- super(e);
- }
-}
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;
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;
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;
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;
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();
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;
+++ /dev/null
-/**
- * Copyright (c) 2010-2021 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.omnilink.internal.handler;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-import com.digitaldan.jomnilinkII.MessageUtils;
-
-/**
- * The {@link TemperatureFormat} defines some methods that are used to
- * convert OmniLink temperature values into Fahrenheit or Celsius.
- *
- * @author Craig Hamilton - Initial contribution
- * @author Ethan Dye - openHAB3 rewrite
- */
-@NonNullByDefault
-public enum TemperatureFormat {
- // Don't convert zero - it appears that is what omni returns when there is no value.
- CELSIUS(2) {
- @Override
- public float omniToFormat(int omniNumber) {
- return MessageUtils.omniToC(omniNumber);
- }
-
- @Override
- public int formatToOmni(float celsius) {
- return MessageUtils.CToOmni(celsius);
- }
- },
- FAHRENHEIT(1) {
- @Override
- public float omniToFormat(int omniNumber) {
- return MessageUtils.omniToF(omniNumber);
- }
-
- @Override
- public int formatToOmni(float fahrenheit) {
- return MessageUtils.FtoOmni(fahrenheit);
- }
- };
-
- private final int formatNumber;
-
- private TemperatureFormat(int formatNumber) {
- this.formatNumber = formatNumber;
- }
-
- /**
- * Convert a number represented by the omni to the format.
- *
- * @param omniNumber Number to convert
- * @return Number converted to appropriate format.
- */
- public abstract float omniToFormat(int omniNumber);
-
- /**
- * Convert a number from this format into an omni number.
- *
- * @param format Number in the current format.
- * @return Omni formatted number.
- */
- public abstract int formatToOmni(float format);
-
- /**
- * Get the number which identifies this format as defined by the omniprotocol.
- *
- * @return Number which identifies this temperature format.
- */
- public int getFormatNumber() {
- return formatNumber;
- }
-
- public static TemperatureFormat valueOf(int tempFormat) {
- if (tempFormat == CELSIUS.formatNumber) {
- return CELSIUS;
- } else if (tempFormat == FAHRENHEIT.formatNumber) {
- return FAHRENHEIT;
- } else {
- throw new IllegalArgumentException("Invalid temperature format!");
- }
- }
-}
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;
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;
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;