use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.
the class TradfriThingHandler method initialize.
@Override
public synchronized void initialize() {
Bridge tradfriGateway = getBridge();
this.id = getConfigAs(TradfriDeviceConfig.class).id;
TradfriGatewayHandler handler = (TradfriGatewayHandler) tradfriGateway.getHandler();
String uriString = handler.getGatewayURI() + "/" + id;
try {
URI uri = new URI(uriString);
coapClient = new TradfriCoapClient(uri);
coapClient.setEndpoint(handler.getEndpoint());
} catch (URISyntaxException e) {
logger.debug("Illegal device URI `{}`: {}", uriString, e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage());
return;
}
active = true;
updateStatus(ThingStatus.UNKNOWN);
switch(tradfriGateway.getStatus()) {
case ONLINE:
scheduler.schedule(() -> {
coapClient.startObserve(this);
}, 3, TimeUnit.SECONDS);
break;
case OFFLINE:
default:
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, String.format("Gateway offline '%s'", tradfriGateway.getStatusInfo()));
break;
}
}
use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.
the class WemoLightHandler method getWemoBridgeHandler.
private synchronized WemoBridgeHandler getWemoBridgeHandler() {
if (this.wemoBridgeHandler == null) {
Bridge bridge = getBridge();
if (bridge == null) {
logger.error("Required bridge not defined for device {}.", wemoLightID);
return null;
}
ThingHandler handler = bridge.getHandler();
if (handler instanceof WemoBridgeHandler) {
this.wemoBridgeHandler = (WemoBridgeHandler) handler;
} else {
logger.debug("No available bridge handler found for {} bridge {} .", wemoLightID, bridge.getUID());
return null;
}
}
return this.wemoBridgeHandler;
}
use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.
the class ThingConsoleCommandExtension method printThings.
private void printThings(Console console, Collection<Thing> things) {
if (things.isEmpty()) {
console.println("No things found.");
}
for (Thing thing : things) {
String id = thing.getUID().toString();
String thingType = thing instanceof Bridge ? "Bridge" : "Thing";
ThingStatusInfo status = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null);
ThingUID bridgeUID = thing.getBridgeUID();
String label = thing.getLabel();
console.println(String.format("%s (Type=%s, Status=%s, Label=%s, Bridge=%s)", id, thingType, status, label, bridgeUID));
}
}
use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.
the class BaseBridgeHandler method getThingByUID.
/**
* Finds and returns a child thing for a given UID of this bridge.
*
* @param uid uid of the child thing
* @return child thing with the given uid or null if thing was not found
*/
@Nullable
public Thing getThingByUID(ThingUID uid) {
Bridge bridge = getThing();
List<Thing> things = bridge.getThings();
for (Thing thing : things) {
if (thing.getUID().equals(uid)) {
return thing;
}
}
return null;
}
use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method testChildHandlerInitialized_replacedInitializedThing.
@Test
public void testChildHandlerInitialized_replacedInitializedThing() {
Semaphore childHandlerInitializedSemaphore = new Semaphore(1);
Semaphore thingUpdatedSemapthore = new Semaphore(1);
registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
@Override
public void initialize() {
updateStatus(ThingStatus.ONLINE);
}
@Override
public void childHandlerInitialized(ThingHandler childHandler, Thing childThing) {
try {
childHandlerInitializedSemaphore.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
@Override
public void initialize() {
updateStatus(ThingStatus.ONLINE);
}
@Override
public void thingUpdated(Thing thing) {
this.thing = thing;
try {
thingUpdatedSemapthore.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
Bridge bridge = BridgeBuilder.create(BRIDGE_TYPE_UID, BRIDGE_UID).build();
managedThingProvider.add(bridge);
waitForAssert(() -> {
assertEquals(ThingStatus.ONLINE, bridge.getStatus());
});
Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).build();
managedThingProvider.add(thing);
waitForAssert(() -> {
assertEquals(ThingStatus.ONLINE, thing.getStatus());
});
assertEquals(1, childHandlerInitializedSemaphore.availablePermits());
Thing thing2 = ThingBuilder.create(THING_TYPE_UID, THING_UID).withBridge(BRIDGE_UID).build();
managedThingProvider.update(thing2);
waitForAssert(() -> {
assertEquals(ThingStatus.ONLINE, thing2.getStatus());
});
// childHandlerInitialized(...) is not be called - framework calls ThingHandler.thingUpdated(...) instead.
assertEquals(1, childHandlerInitializedSemaphore.availablePermits());
// ThingHandler.thingUpdated(...) must be called
assertEquals(0, thingUpdatedSemapthore.availablePermits());
}
Aggregations