Skip to content

Commit

Permalink
Merge pull request #4 from boc-tothefuture/omnilink-binding
Browse files Browse the repository at this point in the history
Update Zones type and add zone refresh.
  • Loading branch information
craigham authored May 27, 2017
2 parents 7c8fadf + 589a1a7 commit 8b3cad9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,27 @@ public UnitStatus apply(ObjectStatus t) {
}, listeningExecutor);
}

public ListenableFuture<ZoneStatus> getZoneStatus(final int address) {

ListenableFuture<ObjectStatus> omniCall = listeningExecutor.submit(new Callable<ObjectStatus>() {

@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<ObjectStatus, ZoneStatus>() {

@Override
public ZoneStatus apply(ObjectStatus t) {
return (ZoneStatus) t.getStatuses()[0];
}
}, listeningExecutor);
}

public ListenableFuture<AreaStatus> getAreaStatus(final int address) {

ListenableFuture<ObjectStatus> omniCall = listeningExecutor.submit(new Callable<ObjectStatus>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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<ZoneStatus>() {
@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);

Expand Down

0 comments on commit 8b3cad9

Please sign in to comment.