use of org.openhab.core.thing.type.ChannelGroupDefinition in project openhab-addons by openhab.
the class HomematicTypeGeneratorImpl method createThingType.
/**
* Creates the ThingType for the given device.
*/
private ThingType createThingType(HmDevice device, List<ChannelGroupType> groupTypes) {
String label = MetadataUtils.getDeviceName(device);
String description = String.format("%s (%s)", label, device.getType());
List<String> supportedBridgeTypeUids = new ArrayList<>();
supportedBridgeTypeUids.add(THING_TYPE_BRIDGE.toString());
ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);
Map<String, String> properties = new HashMap<>();
properties.put(Thing.PROPERTY_VENDOR, PROPERTY_VENDOR_NAME);
properties.put(Thing.PROPERTY_MODEL_ID, device.getType());
URI configDescriptionURI = getConfigDescriptionURI(device);
if (configDescriptionProvider.getInternalConfigDescription(configDescriptionURI) == null) {
generateConfigDescription(device, configDescriptionURI);
}
List<ChannelGroupDefinition> groupDefinitions = new ArrayList<>();
for (ChannelGroupType groupType : groupTypes) {
int usPos = groupType.getUID().getId().lastIndexOf("_");
String id = usPos == -1 ? groupType.getUID().getId() : groupType.getUID().getId().substring(usPos + 1);
groupDefinitions.add(new ChannelGroupDefinition(id, groupType.getUID()));
}
return ThingTypeBuilder.instance(thingTypeUID, label).withSupportedBridgeTypeUIDs(supportedBridgeTypeUids).withDescription(description).withChannelGroupDefinitions(groupDefinitions).withProperties(properties).withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).withConfigDescriptionURI(configDescriptionURI).build();
}
use of org.openhab.core.thing.type.ChannelGroupDefinition in project openhab-addons by openhab.
the class HomeAssistantThingHandler method updateThingType.
private void updateThingType() {
// if this is a dynamic type, then we update the type
ThingTypeUID typeID = thing.getThingTypeUID();
if (!MqttBindingConstants.HOMEASSISTANT_MQTT_THING.equals(typeID)) {
List<ChannelGroupDefinition> groupDefs;
List<ChannelDefinition> channelDefs;
synchronized (haComponents) {
// sync whenever discoverComponents is started
groupDefs = haComponents.values().stream().map(AbstractComponent::getGroupDefinition).collect(Collectors.toList());
channelDefs = haComponents.values().stream().map(AbstractComponent::getType).map(ChannelGroupType::getChannelDefinitions).flatMap(List::stream).collect(Collectors.toList());
}
ThingType thingType = channelTypeProvider.derive(typeID, MqttBindingConstants.HOMEASSISTANT_MQTT_THING).withChannelDefinitions(channelDefs).withChannelGroupDefinitions(groupDefs).build();
channelTypeProvider.setThingType(typeID, thingType);
}
}
use of org.openhab.core.thing.type.ChannelGroupDefinition in project openhab-core by openhab.
the class ThingTypeXmlResult method getBuilder.
ThingTypeBuilder getBuilder() {
ThingTypeBuilder builder = //
ThingTypeBuilder.instance(thingTypeUID, label).isListed(//
listed).withConfigDescriptionURI(configDescriptionURI);
List<String> supportedBridgeTypeUIDs = this.supportedBridgeTypeUIDs;
if (supportedBridgeTypeUIDs != null) {
builder.withSupportedBridgeTypeUIDs(supportedBridgeTypeUIDs);
}
String description = this.description;
if (description != null) {
builder.withDescription(description);
}
String category = this.category;
if (category != null) {
builder.withCategory(category);
}
String representationProperty = this.representationProperty;
if (representationProperty != null) {
builder.withRepresentationProperty(representationProperty);
}
List<ChannelDefinition> channelDefinitions = toChannelDefinitions(channelTypeReferences);
if (channelDefinitions != null) {
builder.withChannelDefinitions(channelDefinitions);
}
List<ChannelGroupDefinition> channelGroupDefinitions = toChannelGroupDefinitions(channelGroupTypeReferences);
if (channelGroupDefinitions != null) {
builder.withChannelGroupDefinitions(channelGroupDefinitions);
}
Map<String, String> properties = toPropertiesMap();
if (properties != null) {
builder.withProperties(properties);
}
List<String> extensibleChannelTypeIds = this.extensibleChannelTypeIds;
if (extensibleChannelTypeIds != null) {
builder.withExtensibleChannelTypeIds(extensibleChannelTypeIds);
}
return builder;
}
use of org.openhab.core.thing.type.ChannelGroupDefinition in project openhab-core by openhab.
the class ThingTypeResource method convertToChannelGroupDefinitionDTOs.
private List<ChannelGroupDefinitionDTO> convertToChannelGroupDefinitionDTOs(List<ChannelGroupDefinition> channelGroupDefinitions, Locale locale) {
List<ChannelGroupDefinitionDTO> channelGroupDefinitionDTOs = new ArrayList<>();
for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
String id = channelGroupDefinition.getId();
ChannelGroupType channelGroupType = channelGroupTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
// Default to the channelGroupDefinition label/description to override the channelGroupType
String label = channelGroupDefinition.getLabel();
String description = channelGroupDefinition.getDescription();
List<ChannelDefinition> channelDefinitions = Collections.emptyList();
if (channelGroupType == null) {
logger.warn("Cannot find channel group type: {}", channelGroupDefinition.getTypeUID());
} else {
if (label == null) {
label = channelGroupType.getLabel();
}
if (description == null) {
description = channelGroupType.getDescription();
}
channelDefinitions = channelGroupType.getChannelDefinitions();
}
List<ChannelDefinitionDTO> channelDefinitionDTOs = convertToChannelDefinitionDTOs(channelDefinitions, locale);
channelGroupDefinitionDTOs.add(new ChannelGroupDefinitionDTO(id, label, description, channelDefinitionDTOs));
}
return channelGroupDefinitionDTOs;
}
use of org.openhab.core.thing.type.ChannelGroupDefinition in project openhab-core by openhab.
the class ThingFactoryHelper method createChannels.
/**
* Create {@link Channel} instances for the given Thing.
*
* @param thingType the type of the Thing (must not be null)
* @param thingUID the Thing's UID (must not be null)
* @param configDescriptionRegistry {@link ConfigDescriptionRegistry} that will be used to initialize the
* {@link Channel}s with their corresponding default values, if given.
* @return a list of {@link Channel}s
*/
public static List<Channel> createChannels(ThingType thingType, ThingUID thingUID, ConfigDescriptionRegistry configDescriptionRegistry) {
List<Channel> channels = new ArrayList<>();
List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
for (ChannelDefinition channelDefinition : channelDefinitions) {
Channel channel = createChannel(channelDefinition, thingUID, null, configDescriptionRegistry);
if (channel != null) {
channels.add(channel);
}
}
List<ChannelGroupDefinition> channelGroupDefinitions = thingType.getChannelGroupDefinitions();
withChannelGroupTypeRegistry(channelGroupTypeRegistry -> {
for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
ChannelGroupType channelGroupType = null;
if (channelGroupTypeRegistry != null) {
channelGroupType = channelGroupTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID());
}
if (channelGroupType != null) {
List<ChannelDefinition> channelGroupChannelDefinitions = channelGroupType.getChannelDefinitions();
for (ChannelDefinition channelDefinition : channelGroupChannelDefinitions) {
Channel channel = createChannel(channelDefinition, thingUID, channelGroupDefinition.getId(), configDescriptionRegistry);
if (channel != null) {
channels.add(channel);
}
}
} else {
logger.warn("Could not create channels for channel group '{}' for thing type '{}', because channel group type '{}' could not be found.", channelGroupDefinition.getId(), thingUID, channelGroupDefinition.getTypeUID());
}
}
return null;
});
return channels;
}
Aggregations