Skip to content

Commit

Permalink
using ThingHandlerService after code review
Browse files Browse the repository at this point in the history
Signed-off-by: Massimo Valla <mvcode00@gmail.com>
  • Loading branch information
mvalla committed Nov 16, 2019
1 parent dffff69 commit 63d7d30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.binding.ConfigStatusBridgeHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.openwebnet.OpenWebNetBindingConstants;
import org.openhab.binding.openwebnet.internal.discovery.OpenWebNetDeviceDiscoveryService;
import org.openhab.binding.openwebnet.internal.discovery.ZigBeeGatewayDiscoveryService;
import org.openwebnet.OpenDeviceType;
import org.openwebnet.OpenError;
import org.openwebnet.OpenGateway;
Expand Down Expand Up @@ -568,4 +570,9 @@ public String normalizeWhere(String where) {
}
}

@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
logger.debug("############ getServices()");
return Collections.singleton(ZigBeeGatewayDiscoveryService.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import java.util.Map;
import java.util.Set;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.DiscoveryService;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerService;
import org.openhab.binding.openwebnet.OpenWebNetBindingConstants;
import org.openhab.binding.openwebnet.handler.OpenWebNetBridgeHandler;
//import org.openhab.binding.openwebnet.handler.OpenWebNetBridgeHandler;
import org.openwebnet.OpenError;
import org.openwebnet.OpenGatewayZigBee;
Expand All @@ -41,22 +45,24 @@
* @author Massimo Valla - Initial contribution
*/

@Component(service = DiscoveryService.class, configurationPid = "discovery.openwebnet")
public class ZigBeeGatewayDiscoveryService extends AbstractDiscoveryService implements OpenListener {

@Component(service = DiscoveryService.class, configurationPid = "discovery.openwebent")
public class ZigBeeGatewayDiscoveryService extends AbstractDiscoveryService
implements OpenListener, ThingHandlerService {
private final Logger logger = LoggerFactory.getLogger(ZigBeeGatewayDiscoveryService.class);

private final static int DISCOVERY_TIMEOUT = 30; // seconds

// TODO support multiple gateways at the same time
private OpenGatewayZigBee zbgateway;
private int gatewayZigBeeId = 0;
private OpenWebNetBridgeHandler bridgeHandler;

private ThingUID gatewayUID = null;

public ZigBeeGatewayDiscoveryService() {
super(OpenWebNetBindingConstants.BRIDGE_SUPPORTED_THING_TYPES, DISCOVERY_TIMEOUT, false);
logger.debug(
"\n#############################################################################################\nOWN:BridgeDiscovery== constructor()");
"\n#############################################################################################\n==OWN:ZigBeeGatewayDiscoveryService== constructor()");
}

public ZigBeeGatewayDiscoveryService(int timeout) throws IllegalArgumentException {
Expand Down Expand Up @@ -177,4 +183,22 @@ public void onMessage(OpenMessage msg) {

}

@Override
public void setThingHandler(@Nullable ThingHandler handler) {
if (handler instanceof OpenWebNetBridgeHandler) {
bridgeHandler = (OpenWebNetBridgeHandler) handler;
// gatewayUID = bridgeHandler.getUID();
}
}

@Override
public @Nullable ThingHandler getThingHandler() {
return bridgeHandler;
}

@Override
public void deactivate() {
super.deactivate();
}

}

0 comments on commit 63d7d30

Please sign in to comment.