Search in sources :

Example 36 with ChannelType

use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.

the class HomematicTypeGeneratorImpl method generate.

@Override
public void generate(HmDevice device) {
    if (thingTypeProvider != null) {
        ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device);
        ThingType tt = thingTypeProvider.getInternalThingType(thingTypeUID);
        if (tt == null || device.isGatewayExtras()) {
            logger.debug("Generating ThingType for device '{}' with {} datapoints", device.getType(), device.getDatapointCount());
            List<ChannelGroupType> groupTypes = new ArrayList<>();
            for (HmChannel channel : device.getChannels()) {
                List<ChannelDefinition> channelDefinitions = new ArrayList<>();
                // those will be populated dynamically during thing initialization
                if (!channel.isReconfigurable()) {
                    // generate channel
                    for (HmDatapoint dp : channel.getDatapoints()) {
                        if (!isIgnoredDatapoint(dp) && dp.getParamsetType() == HmParamsetType.VALUES) {
                            ChannelTypeUID channelTypeUID = UidUtils.generateChannelTypeUID(dp);
                            ChannelType channelType = channelTypeProvider.getInternalChannelType(channelTypeUID);
                            if (channelType == null) {
                                channelType = createChannelType(dp, channelTypeUID);
                                channelTypeProvider.addChannelType(channelType);
                            }
                            ChannelDefinition channelDef = new ChannelDefinitionBuilder(dp.getName(), channelType.getUID()).build();
                            channelDefinitions.add(channelDef);
                        }
                    }
                }
                // generate group
                ChannelGroupTypeUID groupTypeUID = UidUtils.generateChannelGroupTypeUID(channel);
                ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID);
                if (groupType == null || device.isGatewayExtras()) {
                    String groupLabel = String.format("%s", channel.getType() == null ? null : MiscUtils.capitalize(channel.getType().replace("_", " ")));
                    groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel).withChannelDefinitions(channelDefinitions).build();
                    channelGroupTypeProvider.addChannelGroupType(groupType);
                    groupTypes.add(groupType);
                }
            }
            tt = createThingType(device, groupTypes);
            thingTypeProvider.addThingType(tt);
        }
        addFirmware(device);
    }
}
Also used : ChannelDefinitionBuilder(org.openhab.core.thing.type.ChannelDefinitionBuilder) ArrayList(java.util.ArrayList) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.openhab.core.thing.type.ChannelGroupTypeUID) ThingType(org.openhab.core.thing.type.ThingType) HmDatapoint(org.openhab.binding.homematic.internal.model.HmDatapoint) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) HmChannel(org.openhab.binding.homematic.internal.model.HmChannel) ChannelType(org.openhab.core.thing.type.ChannelType)

Example 37 with ChannelType

use of org.openhab.core.thing.type.ChannelType in project openhab-addons by openhab.

the class AbstractMieleThingHandlerTest method createChannelsForThingHandler.

private List<Channel> createChannelsForThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid) {
    ChannelTypeRegistry channelTypeRegistry = getService(ChannelTypeRegistry.class, ChannelTypeRegistry.class);
    assertNotNull(channelTypeRegistry);
    ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class, ThingTypeRegistry.class);
    assertNotNull(thingTypeRegistry);
    ThingType thingType = thingTypeRegistry.getThingType(thingTypeUid);
    assertNotNull(thingType);
    List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
    assertNotNull(channelDefinitions);
    List<Channel> channels = new ArrayList<Channel>();
    for (ChannelDefinition channelDefinition : channelDefinitions) {
        ChannelTypeUID channelTypeUid = channelDefinition.getChannelTypeUID();
        assertNotNull(channelTypeUid);
        ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUid);
        assertNotNull(channelType);
        String acceptedItemType = channelType.getItemType();
        assertNotNull(acceptedItemType);
        String channelId = channelDefinition.getId();
        assertNotNull(channelId);
        ChannelUID channelUid = new ChannelUID(thingUid, channelId);
        assertNotNull(channelUid);
        Channel channel = ChannelBuilder.create(channelUid, acceptedItemType).build();
        assertNotNull(channel);
        channels.add(channel);
    }
    return channels;
}
Also used : ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingType(org.openhab.core.thing.type.ThingType) ChannelType(org.openhab.core.thing.type.ChannelType)

Example 38 with ChannelType

use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.

the class AutoUpdateManager method shouldAutoUpdate.

private Recommendation shouldAutoUpdate(Item item) {
    String itemName = item.getName();
    Recommendation ret = Recommendation.REQUIRED;
    // check if the item is a group item
    if (item instanceof GroupItem) {
        return Recommendation.DONT;
    }
    List<ChannelUID> linkedChannelUIDs = new ArrayList<>();
    for (ItemChannelLink link : itemChannelLinkRegistry.getLinks(itemName)) {
        linkedChannelUIDs.add(link.getLinkedUID());
    }
    // check if there is any channel ONLINE
    List<ChannelUID> onlineChannelUIDs = new ArrayList<>();
    for (ChannelUID channelUID : linkedChannelUIDs) {
        Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (// 
        thing == null || // 
        thing.getChannel(channelUID.getId()) == null || // 
        thing.getHandler() == null || // 
        !ThingStatus.ONLINE.equals(thing.getStatus())) {
            continue;
        }
        onlineChannelUIDs.add(channelUID);
    }
    if (!linkedChannelUIDs.isEmpty() && onlineChannelUIDs.isEmpty()) {
        // none of the linked channels is able to process the command
        return Recommendation.REVERT;
    }
    for (ChannelUID channelUID : onlineChannelUIDs) {
        Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing == null) {
            continue;
        }
        AutoUpdatePolicy policy = AutoUpdatePolicy.DEFAULT;
        Channel channel = thing.getChannel(channelUID.getId());
        if (channel != null) {
            AutoUpdatePolicy channelpolicy = channel.getAutoUpdatePolicy();
            if (channelpolicy != null) {
                policy = channelpolicy;
            } else {
                ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
                if (channelType != null && channelType.getAutoUpdatePolicy() != null) {
                    policy = channelType.getAutoUpdatePolicy();
                }
            }
        }
        switch(policy) {
            case VETO:
                ret = Recommendation.DONT;
                break;
            case DEFAULT:
                if (ret == Recommendation.REQUIRED || ret == Recommendation.RECOMMENDED) {
                    ret = Recommendation.OPTIMISTIC;
                }
                break;
            case RECOMMEND:
                if (ret == Recommendation.REQUIRED) {
                    ret = Recommendation.RECOMMENDED;
                }
                break;
        }
    }
    return ret;
}
Also used : AutoUpdatePolicy(org.openhab.core.thing.type.AutoUpdatePolicy) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) GroupItem(org.openhab.core.items.GroupItem) ChannelType(org.openhab.core.thing.type.ChannelType) Thing(org.openhab.core.thing.Thing)

Example 39 with ChannelType

use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.

the class ChannelCommandDescriptionProvider method getCommandDescription.

@Override
@Nullable
public CommandDescription getCommandDescription(String itemName, @Nullable Locale locale) {
    Set<ChannelUID> boundChannels = itemChannelLinkRegistry.getBoundChannels(itemName);
    if (!boundChannels.isEmpty()) {
        ChannelUID channelUID = boundChannels.iterator().next();
        Channel channel = thingRegistry.getChannel(channelUID);
        if (channel != null) {
            CommandDescription commandDescription = null;
            ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale);
            if (channelType != null) {
                commandDescription = channelType.getCommandDescription();
            }
            CommandDescription dynamicCommandDescription = getDynamicCommandDescription(channel, commandDescription, locale);
            if (dynamicCommandDescription != null) {
                return dynamicCommandDescription;
            }
            return commandDescription;
        }
    }
    return null;
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) CommandDescription(org.openhab.core.types.CommandDescription) Channel(org.openhab.core.thing.Channel) ChannelType(org.openhab.core.thing.type.ChannelType) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 40 with ChannelType

use of org.openhab.core.thing.type.ChannelType in project openhab-core by openhab.

the class ThingTypeXmlProvider method addingFinished.

@Override
public synchronized void addingFinished() {
    // create channel types
    for (ChannelTypeXmlResult type : channelTypeRefs) {
        ChannelType channelType = type.toChannelType();
        try {
            channelTypeProvider.add(bundle, channelType);
        } catch (RuntimeException e) {
            logger.error("Could not register ChannelType: {}", channelType.getUID(), e);
        }
    }
    // create channel group types
    for (ChannelGroupTypeXmlResult type : channelGroupTypeRefs) {
        try {
            channelGroupTypeProvider.add(bundle, type.toChannelGroupType());
        } catch (RuntimeException e) {
            logger.error("Could not register ChannelGroupType: {}", type.getUID(), e);
        }
    }
    // create thing and bridge types
    for (ThingTypeXmlResult type : thingTypeRefs) {
        try {
            thingTypeProvider.add(bundle, type.toThingType());
        } catch (RuntimeException e) {
            logger.error("Could not register ThingType: {}", type.getUID(), e);
        }
    }
    // release temporary cache
    thingTypeRefs.clear();
    channelGroupTypeRefs.clear();
    channelTypeRefs.clear();
}
Also used : ChannelType(org.openhab.core.thing.type.ChannelType)

Aggregations

ChannelType (org.openhab.core.thing.type.ChannelType)57 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)27 Channel (org.openhab.core.thing.Channel)21 ArrayList (java.util.ArrayList)20 Nullable (org.eclipse.jdt.annotation.Nullable)17 ChannelUID (org.openhab.core.thing.ChannelUID)16 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)14 Test (org.junit.jupiter.api.Test)11 URI (java.net.URI)10 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)10 Thing (org.openhab.core.thing.Thing)9 ThingType (org.openhab.core.thing.type.ThingType)9 StateOption (org.openhab.core.types.StateOption)9 BigDecimal (java.math.BigDecimal)8 Collection (java.util.Collection)8 ChannelDefinitionBuilder (org.openhab.core.thing.type.ChannelDefinitionBuilder)8 ChannelTypeProvider (org.openhab.core.thing.type.ChannelTypeProvider)8 Locale (java.util.Locale)7 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)7 Configuration (org.openhab.core.config.core.Configuration)7