From 589a1a7e694c4af3849f2c814a072fe1531b89c3 Mon Sep 17 00:00:00 2001 From: Brian O'Connell Date: Sat, 27 May 2017 12:16:52 -0400 Subject: [PATCH] Changed zone type from OnOff to OpenClosed. Added support for Zone Refresh. --- .../handler/OmnilinkBridgeHandler.java | 21 ++++++++++++++++ .../binding/omnilink/handler/ZoneHandler.java | 25 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/OmnilinkBridgeHandler.java b/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/OmnilinkBridgeHandler.java index dc35bc0118603..84a95c2eea061 100644 --- a/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/OmnilinkBridgeHandler.java +++ b/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/OmnilinkBridgeHandler.java @@ -441,6 +441,27 @@ public UnitStatus apply(ObjectStatus t) { }, listeningExecutor); } + public ListenableFuture getZoneStatus(final int address) { + + ListenableFuture omniCall = listeningExecutor.submit(new Callable() { + + @Override + public ObjectStatus call() throws Exception { + if (omniConnection == null) { + Thread.sleep(100); + } + return omniConnection.reqObjectStatus(Message.OBJ_TYPE_ZONE, address, address); + } + }); + return Futures.transform(omniCall, new Function() { + + @Override + public ZoneStatus apply(ObjectStatus t) { + return (ZoneStatus) t.getStatuses()[0]; + } + }, listeningExecutor); + } + public ListenableFuture getAreaStatus(final int address) { ListenableFuture omniCall = listeningExecutor.submit(new Callable() { diff --git a/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/ZoneHandler.java b/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/ZoneHandler.java index fd811c93c00cb..444fa0c5c3ae4 100644 --- a/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/ZoneHandler.java +++ b/addons/binding/org.openhab.binding.omnilink/src/main/java/org/openhab/binding/omnilink/handler/ZoneHandler.java @@ -1,16 +1,21 @@ package org.openhab.binding.omnilink.handler; -import org.eclipse.smarthome.core.library.types.OnOffType; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import org.eclipse.smarthome.core.library.types.OpenClosedType; import org.eclipse.smarthome.core.thing.ChannelUID; import org.eclipse.smarthome.core.thing.Thing; +import org.eclipse.smarthome.core.thing.UID; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.State; import org.openhab.binding.omnilink.OmnilinkBindingConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.eclipse.smarthome.core.types.RefreshType; import com.digitaldan.jomnilinkII.MessageTypes.statuses.ZoneStatus; + public class ZoneHandler extends AbstractOmnilinkHandler { private Logger logger = LoggerFactory.getLogger(ZoneHandler.class); @@ -21,10 +26,26 @@ public ZoneHandler(Thing thing) { @Override public void handleCommand(ChannelUID channelUID, Command command) { logger.debug("must handle command"); + if (command instanceof RefreshType) { + String[] channelParts = channelUID.getAsString().split(UID.SEPARATOR); + logger.debug("Zone '{}' got REFRESH command", thing.getLabel()); + Futures.addCallback(getOmnilinkBridgeHander().getZoneStatus(Integer.parseInt(channelParts[2])), + new FutureCallback() { + @Override + public void onFailure(Throwable arg0) { + logger.error("Error refreshing unit status", arg0); + } + + @Override + public void onSuccess(ZoneStatus status) { + handleZoneStatus(status); + } + }); + } } public void handleZoneStatus(ZoneStatus status) { - State newState = status.getStatus() == 1 ? OnOffType.ON : OnOffType.OFF; + State newState = status.getStatus() == 1 ? OpenClosedType.OPEN : OpenClosedType.CLOSED; logger.debug("handle Zone Status Change to: " + newState); updateState(OmnilinkBindingConstants.CHANNEL_CONTACTSENSOR, newState);