use of org.openhab.core.thing.dto.ChannelTypeDTO in project openhab-core by openhab.
the class ChannelTypeResource method getAll.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getChannelTypes", summary = "Gets all available channel types.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ChannelTypeDTO.class), uniqueItems = true))) })
public Response getAll(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language, @QueryParam("prefixes") @Parameter(description = "filter UIDs by prefix (multiple comma-separated prefixes allowed, for example: 'system,mqtt')") @Nullable String prefixes) {
Locale locale = localeService.getLocale(language);
Stream<ChannelTypeDTO> channelStream = channelTypeRegistry.getChannelTypes(locale).stream().map(c -> convertToChannelTypeDTO(c, locale));
if (prefixes != null) {
Predicate<ChannelTypeDTO> filter = ct -> false;
for (String prefix : prefixes.split(",")) {
filter = filter.or(ct -> ct.UID.startsWith(prefix + ":"));
}
channelStream = channelStream.filter(filter);
}
return Response.ok(new Stream2JSONInputStream(channelStream)).build();
}
use of org.openhab.core.thing.dto.ChannelTypeDTO in project openhab-core by openhab.
the class ChannelTypeResource method convertToChannelTypeDTO.
private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) {
final URI descURI = channelType.getConfigDescriptionURI();
final ConfigDescription configDescription = descURI == null ? null : configDescriptionRegistry.getConfigDescription(descURI, locale);
final ConfigDescriptionDTO configDescriptionDTO = configDescription == null ? null : ConfigDescriptionDTOMapper.map(configDescription);
final List<ConfigDescriptionParameterDTO> parameters = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameters;
final List<ConfigDescriptionParameterGroupDTO> parameterGroups = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameterGroups;
return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced(), channelType.getCommandDescription());
}
Aggregations