use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class InboxConsoleCommandExtension method execute.
@Override
public void execute(String[] args, Console console) {
if (args.length > 0) {
final String subCommand = args[0];
switch(subCommand) {
case SUBCMD_APPROVE:
if (args.length > 2) {
String label = args[2];
try {
ThingUID thingUID = new ThingUID(args[1]);
List<DiscoveryResult> results = inbox.stream().filter(forThingUID(thingUID)).collect(Collectors.toList());
if (results.isEmpty()) {
console.println("No matching inbox entry could be found.");
return;
}
inbox.approve(thingUID, label);
} catch (Exception e) {
console.println(e.getMessage());
}
} else {
console.println("Specify thing id to approve: inbox approve <thingUID> <label>");
}
break;
case SUBCMD_IGNORE:
if (args.length > 1) {
try {
ThingUID thingUID = new ThingUID(args[1]);
PersistentInbox persistentInbox = (PersistentInbox) inbox;
persistentInbox.setFlag(thingUID, DiscoveryResultFlag.IGNORED);
} catch (IllegalArgumentException e) {
console.println("'" + args[1] + "' is no valid thing UID.");
}
} else {
console.println("Cannot approve thing as managed thing provider is missing.");
}
break;
case SUBCMD_LIST_IGNORED:
printInboxEntries(console, inbox.stream().filter(withFlag((DiscoveryResultFlag.IGNORED))).collect(Collectors.toList()));
break;
case SUBCMD_CLEAR:
clearInboxEntries(console, inbox.getAll());
break;
default:
break;
}
} else {
printInboxEntries(console, inbox.stream().filter(withFlag((DiscoveryResultFlag.NEW))).collect(Collectors.toList()));
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class DiscoveryResultDTOMapper method map.
/**
* Maps discovery result data transfer object into discovery result.
*
* @param discoveryResultDTO the discovery result data transfer object
* @return the discovery result
*/
public static DiscoveryResult map(DiscoveryResultDTO discoveryResultDTO) {
final ThingUID thingUID = new ThingUID(discoveryResultDTO.thingUID);
final String dtoThingTypeUID = discoveryResultDTO.thingTypeUID;
final ThingTypeUID thingTypeUID = dtoThingTypeUID != null ? new ThingTypeUID(dtoThingTypeUID) : null;
final String dtoBridgeUID = discoveryResultDTO.bridgeUID;
final ThingUID bridgeUID = dtoBridgeUID != null ? new ThingUID(dtoBridgeUID) : null;
return DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withBridge(bridgeUID).withLabel(discoveryResultDTO.label).withRepresentationProperty(discoveryResultDTO.representationProperty).withProperties(discoveryResultDTO.properties).build();
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ThingResource method create.
/**
* create a new Thing
*
* @param thingBean
* @return Response holding the newly created Thing or error information
*/
@POST
@RolesAllowed({ Role.ADMIN })
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates a new thing and adds it to the registry.")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Created", response = String.class), @ApiResponse(code = 400, message = "A uid must be provided, if no binding can create a thing of this type."), @ApiResponse(code = 409, message = "A thing with the same uid already exists.") })
public Response create(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @ApiParam(value = "thing data", required = true) ThingDTO thingBean) {
final Locale locale = LocaleUtil.getLocale(language);
ThingUID thingUID = thingBean.UID == null ? null : new ThingUID(thingBean.UID);
ThingTypeUID thingTypeUID = new ThingTypeUID(thingBean.thingTypeUID);
if (thingUID != null) {
// check if a thing with this UID already exists
Thing thing = thingRegistry.get(thingUID);
if (thing != null) {
// report a conflict
return getThingResponse(Status.CONFLICT, thing, locale, "Thing " + thingUID.toString() + " already exists!");
}
}
ThingUID bridgeUID = null;
if (thingBean.bridgeUID != null) {
bridgeUID = new ThingUID(thingBean.bridgeUID);
}
// turn the ThingDTO's configuration into a Configuration
Configuration configuration = new Configuration(normalizeConfiguration(thingBean.configuration, thingTypeUID, thingUID));
normalizeChannels(thingBean, thingUID);
Thing thing = thingRegistry.createThingOfType(thingTypeUID, thingUID, bridgeUID, thingBean.label, configuration);
if (thing != null) {
if (thingBean.properties != null) {
for (Entry<String, String> entry : thingBean.properties.entrySet()) {
thing.setProperty(entry.getKey(), entry.getValue());
}
}
if (thingBean.channels != null) {
List<Channel> channels = new ArrayList<>();
for (ChannelDTO channelDTO : thingBean.channels) {
channels.add(ChannelDTOMapper.map(channelDTO));
}
ThingHelper.addChannelsToThing(thing, channels);
}
if (thingBean.location != null) {
thing.setLocation(thingBean.location);
}
} else if (thingUID != null) {
// if there wasn't any ThingFactory capable of creating the thing,
// we create the Thing exactly the way we received it, i.e. we
// cannot take its thing type into account for automatically
// populating channels and properties.
thing = ThingDTOMapper.map(thingBean);
} else {
return getThingResponse(Status.BAD_REQUEST, thing, locale, "A UID must be provided, since no binding can create the thing!");
}
thingRegistry.add(thing);
return getThingResponse(Status.CREATED, thing, locale, null);
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ThingResource method getConfigStatus.
@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/{thingUID}/config/status")
@ApiOperation(value = "Gets thing's config status.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class), @ApiResponse(code = 404, message = "Thing not found.") })
public Response getConfigStatus(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID) throws IOException {
ThingUID thingUIDObject = new ThingUID(thingUID);
// Check if the Thing exists, 404 if not
Thing thing = thingRegistry.get(thingUIDObject);
if (null == thing) {
logger.info("Received HTTP GET request for thing config status at '{}' for the unknown thing '{}'.", uriInfo.getPath(), thingUID);
return getThingNotFoundResponse(thingUID);
}
ConfigStatusInfo info = configStatusService.getConfigStatus(thingUID, LocaleUtil.getLocale(language));
if (info != null) {
return Response.ok(null, MediaType.TEXT_PLAIN).entity(info.getConfigStatusMessages()).build();
}
return Response.ok(null, MediaType.TEXT_PLAIN).entity(Collections.EMPTY_SET).build();
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class ThingResource method getFirmwareStatus.
@GET
@Path("/{thingUID}/firmware/status")
@ApiOperation(value = "Gets thing's firmware status.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 204, message = "No firmware status provided by this Thing.") })
public Response getFirmwareStatus(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID) throws IOException {
ThingUID thingUIDObject = new ThingUID(thingUID);
FirmwareStatusInfo info = firmwareUpdateService.getFirmwareStatusInfo(thingUIDObject);
if (info == null) {
return Response.status(Status.NO_CONTENT).build();
}
return Response.ok(null, MediaType.TEXT_PLAIN).entity(buildFirmwareStatusDTO(info)).build();
}
Aggregations