Search in sources :

Example 1 with ChannelGroupDefinition

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) URI(java.net.URI) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint)

Example 2 with ChannelGroupDefinition

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);
    }
}
Also used : AbstractComponent(org.openhab.binding.mqtt.homeassistant.internal.component.AbstractComponent) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) List(java.util.List) ThingType(org.openhab.core.thing.type.ThingType) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition)

Example 3 with ChannelGroupDefinition

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;
}
Also used : ThingTypeBuilder(org.openhab.core.thing.type.ThingTypeBuilder) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition)

Example 4 with ChannelGroupDefinition

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;
}
Also used : ChannelDefinitionDTO(org.openhab.core.thing.dto.ChannelDefinitionDTO) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelGroupDefinitionDTO(org.openhab.core.thing.dto.ChannelGroupDefinitionDTO) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition)

Example 5 with ChannelGroupDefinition

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;
}
Also used : ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition)

Aggregations

ChannelGroupDefinition (org.openhab.core.thing.type.ChannelGroupDefinition)13 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)9 ChannelGroupType (org.openhab.core.thing.type.ChannelGroupType)8 ThingType (org.openhab.core.thing.type.ThingType)6 ArrayList (java.util.ArrayList)5 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)5 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)5 Test (org.junit.jupiter.api.Test)4 List (java.util.List)3 Channel (org.openhab.core.thing.Channel)3 ChannelGroupTypeUID (org.openhab.core.thing.type.ChannelGroupTypeUID)3 ChannelType (org.openhab.core.thing.type.ChannelType)3 HashMap (java.util.HashMap)2 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)2 CoreMatchers (org.hamcrest.CoreMatchers)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Configuration (org.openhab.core.config.core.Configuration)2 Thing (org.openhab.core.thing.Thing)2 ThingUID (org.openhab.core.thing.ThingUID)2