use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ThingConsoleCommandExtension method execute.
@Override
public void execute(String[] args, Console console) {
Collection<Thing> things = thingRegistry.getAll();
if (args.length > 0) {
String subCommand = args[0];
switch(subCommand) {
case SUBCMD_LIST:
printThings(console, things);
return;
case SUBCMD_CLEAR:
removeAllThings(console, things);
return;
case SUBCMD_REMOVE:
if (args.length > 1) {
ThingUID thingUID = new ThingUID(args[1]);
removeThing(console, things, thingUID);
} else {
console.println("Specify thing id to remove: things remove <thingUID> (e.g. \"hue:light:1\")");
}
return;
case SUBCMD_TRIGGER:
if (args.length == 3) {
triggerChannel(console, args[1], args[2]);
} else if (args.length == 2) {
triggerChannel(console, args[1], null);
} else {
console.println("Command '" + subCommand + "' needs arguments <channelUID> [<event>]");
}
break;
default:
break;
}
} else {
printUsage(console);
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class FirmwareUpdateService method receive.
@Override
public void receive(Event event) {
if (event instanceof ThingStatusInfoChangedEvent) {
ThingStatusInfoChangedEvent changedEvent = (ThingStatusInfoChangedEvent) event;
if (changedEvent.getStatusInfo().getStatus() != ThingStatus.ONLINE) {
return;
}
ThingUID thingUID = changedEvent.getThingUID();
FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler != null && !firmwareStatusInfoMap.containsKey(thingUID)) {
initializeFirmwareStatus(firmwareUpdateHandler);
}
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class FirmwareUpdateService method cancelFirmwareUpdate.
/**
* Cancels the firmware update of the thing having the given thing UID by invoking the operation
* {@link FirmwareUpdateHandler#cancel()} of the thingĀ“s firmware update handler.
*
* @param thingUID the thing UID (must not be null)
*/
public void cancelFirmwareUpdate(final ThingUID thingUID) {
Objects.requireNonNull(thingUID, "Thing UID must not be null.");
final FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID);
if (firmwareUpdateHandler == null) {
throw new IllegalArgumentException(String.format("There is no firmware update handler for thing with UID %s.", thingUID));
}
final ProgressCallbackImpl progressCallback = getProgressCallback(thingUID);
logger.debug("Cancelling firmware update for thing with UID {}.", thingUID);
safeCaller.create(firmwareUpdateHandler, FirmwareUpdateHandler.class).withTimeout(timeout).withAsync().onTimeout(() -> {
logger.error("Timeout occurred while cancelling firmware update of thing with UID {}.", thingUID);
progressCallback.failedInternal("timeout-error-during-cancel");
}).onException(e -> {
logger.error("Unexpected exception occurred while cancelling firmware update of thing with UID {}.", thingUID, e.getCause());
progressCallback.failedInternal("unexpected-handler-error-during-cancel");
}).withIdentifier(new Object()).build().cancel();
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class InboxResource method approve.
@POST
@Path("/{thingUID}/approve")
@Consumes(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Approves the discovery result by adding the thing to the registry.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Thing not found in the inbox."), @ApiResponse(code = 409, message = "No binding found that supports this thing.") })
public Response approve(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thingUID", required = true) String thingUID, @ApiParam(value = "thing label") String label) {
ThingUID thingUIDObject = new ThingUID(thingUID);
String notEmptyLabel = label != null && !label.isEmpty() ? label : null;
Thing thing = null;
try {
thing = inbox.approve(thingUIDObject, notEmptyLabel);
} catch (IllegalArgumentException e) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Thing not found in inbox");
}
// inbox.approve returns null if no handler is found that supports this thing
if (thing == null) {
return JSONResponse.createErrorResponse(Status.CONFLICT, "No binding found that can create the thing");
}
return Response.ok(null, MediaType.TEXT_PLAIN).build();
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ThingResource method getByUID.
@GET
@RolesAllowed({ Role.ADMIN })
@Path("/{thingUID}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets thing by UID.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ThingDTO.class), @ApiResponse(code = 404, message = "Thing not found.") })
public Response getByUID(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thingUID") String thingUID) {
final Locale locale = LocaleUtil.getLocale(language);
Thing thing = thingRegistry.get((new ThingUID(thingUID)));
// return Thing data if it does exist
if (thing != null) {
return getThingResponse(Status.OK, thing, locale, null);
} else {
return getThingNotFoundResponse(thingUID);
}
}
Aggregations