Search in sources :

Example 1 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder in project smarthome by eclipse.

the class ThingLinkManagerOSGiTest method setup.

@Before
public void setup() {
    context.clear();
    registerVolatileStorageService();
    thingRegistry = getService(ThingRegistry.class);
    managedThingProvider = getService(ManagedThingProvider.class);
    itemRegistry = getService(ItemRegistry.class);
    assertNotNull(itemRegistry);
    itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    ComponentContext componentContext = mock(ComponentContext.class);
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    TestThingHandlerFactory thingHandlerFactory = new TestThingHandlerFactory();
    thingHandlerFactory.activate(componentContext);
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    StateDescription state = new StateDescription(BigDecimal.valueOf(0), BigDecimal.valueOf(100), BigDecimal.valueOf(10), "%d Peek", true, Collections.singletonList(new StateOption("SOUND", "My great sound.")));
    ChannelType channelType = ChannelTypeBuilder.state(new ChannelTypeUID("hue:alarm"), "Alarm Channel", "Number").withStateDescription(state).build();
    List<ChannelType> channelTypes = singletonList(channelType);
    ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
    when(channelTypeProvider.getChannelTypes(nullable(Locale.class))).thenReturn(channelTypes);
    when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).then(new Answer<@Nullable ChannelType>() {

        @Override
        @Nullable
        public ChannelType answer(InvocationOnMock invocation) throws Throwable {
            ChannelTypeUID uid = (ChannelTypeUID) invocation.getArgument(0);
            return channelTypes.stream().filter(t -> t.getUID().equals(uid)).findFirst().get();
        }
    });
    registerService(channelTypeProvider);
    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("hue:lamp"), "label").withChannelDefinitions(singletonList(new ChannelDefinitionBuilder("1", channelType.getUID()).build())).build();
    SimpleThingTypeProvider thingTypeProvider = new SimpleThingTypeProvider(singletonList(thingType));
    registerService(thingTypeProvider);
}
Also used : Locale(java.util.Locale) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Channel(org.eclipse.smarthome.core.thing.Channel) CoreMatchers(org.hamcrest.CoreMatchers) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) ChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder) ComponentContext(org.osgi.service.component.ComponentContext) ThingTypeBuilder(org.eclipse.smarthome.core.thing.type.ThingTypeBuilder) BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) Command(org.eclipse.smarthome.core.types.Command) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Nullable(org.eclipse.jdt.annotation.Nullable) Locale(java.util.Locale) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) After(org.junit.After) ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingLinkManager(org.eclipse.smarthome.core.thing.link.ThingLinkManager) Before(org.junit.Before) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) StateOption(org.eclipse.smarthome.core.types.StateOption) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Mockito(org.mockito.Mockito) List(java.util.List) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) StateDescription(org.eclipse.smarthome.core.types.StateDescription) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) Assert(org.junit.Assert) Collections(java.util.Collections) ThingStatus(org.eclipse.smarthome.core.thing.ThingStatus) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ComponentContext(org.osgi.service.component.ComponentContext) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) StateOption(org.eclipse.smarthome.core.types.StateOption) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ChannelTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelTypeProvider) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Nullable(org.eclipse.jdt.annotation.Nullable) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Before(org.junit.Before)

Example 2 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method registerChannelGroupTypeProvider.

private void registerChannelGroupTypeProvider() throws Exception {
    ChannelGroupType channelGroupType = ChannelGroupTypeBuilder.instance(CHANNEL_GROUP_TYPE_UID, "Test Group Label").withDescription("Test Group Description").withCategory("Test Group Category").withChannelDefinitions(Collections.singletonList(new ChannelDefinitionBuilder(CHANNEL_ID, CHANNEL_TYPE_UID).build())).build();
    ChannelGroupTypeProvider mockChannelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
    when(mockChannelGroupTypeProvider.getChannelGroupType(eq(CHANNEL_GROUP_TYPE_UID), any())).thenReturn(channelGroupType);
    registerService(mockChannelGroupTypeProvider);
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeProvider(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeProvider)

Example 3 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder in project smarthome by eclipse.

the class DsDeviceThingTypeProvider method getThingType.

@Override
public ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale) {
    try {
        SupportedThingTypes supportedThingType = SupportedThingTypes.valueOf(thingTypeUID.getId());
        ThingTypeBuilder thingTypeBuilder = ThingTypeBuilder.instance(thingTypeUID, getLabelText(thingTypeUID.getId(), locale)).withSupportedBridgeTypeUIDs(Arrays.asList(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE.getAsString())).withDescription(getDescText(thingTypeUID.getId(), locale));
        try {
            if (supportedThingType.havePowerSensors) {
                thingTypeBuilder.withConfigDescriptionURI(new URI(DEVICE_WITH_POWER_SENSORS));
            } else {
                thingTypeBuilder.withConfigDescriptionURI(new URI(DEVICE_WITHOUT_POWER_SENSORS));
            }
        } catch (URISyntaxException e) {
            logger.debug("An URISyntaxException occurred: ", e);
        }
        if (SupportedThingTypes.GR.equals(supportedThingType)) {
            thingTypeBuilder.withChannelDefinitions(Arrays.asList(new ChannelDefinitionBuilder(DsChannelTypeProvider.SHADE, new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.SHADE)).build()));
        }
        if (SupportedThingTypes.circuit.equals(supportedThingType)) {
            List<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>(3);
            for (MeteringTypeEnum meteringType : MeteringTypeEnum.values()) {
                channelDefinitions.add(new ChannelDefinitionBuilder(DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false), new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false))).build());
            }
            thingTypeBuilder.withChannelDefinitions(channelDefinitions);
        }
        return thingTypeBuilder.build();
    } catch (IllegalArgumentException e) {
    // ignore
    }
    return null;
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ThingTypeBuilder(org.eclipse.smarthome.core.thing.type.ThingTypeBuilder) MeteringTypeEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 4 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder in project smarthome by eclipse.

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<ChannelGroupType>();
            for (HmChannel channel : device.getChannels()) {
                List<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>();
                // 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", WordUtils.capitalizeFully(StringUtils.replace(channel.getType(), "_", " ")));
                    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.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupTypeUID(org.eclipse.smarthome.core.thing.type.ChannelGroupTypeUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType)

Example 5 with ChannelDefinitionBuilder

use of org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder in project smarthome by eclipse.

the class ThingFactoryTest method getChannelDefinitions.

private List<ChannelDefinition> getChannelDefinitions() throws Exception {
    ChannelType channelType1 = ChannelTypeBuilder.state(new ChannelTypeUID("bindingId:cd1"), "channelLabel", "itemType").withConfigDescriptionURI(new URI("scheme", "channelType:cd1", null)).build();
    ChannelType channelType2 = ChannelTypeBuilder.state(new ChannelTypeUID("bindingId:cd2"), "channelLabel2", "itemType2").withConfigDescriptionURI(new URI("scheme", "channelType:cd2", null)).build();
    registerChannelTypes(Stream.of(channelType1, channelType2).collect(toSet()), emptyList());
    ChannelDefinition cd1 = new ChannelDefinitionBuilder("channel1", channelType1.getUID()).build();
    ChannelDefinition cd2 = new ChannelDefinitionBuilder("channel2", channelType2.getUID()).build();
    return Stream.of(cd1, cd2).collect(toList());
}
Also used : ChannelDefinitionBuilder(org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) URI(java.net.URI)

Aggregations

ChannelDefinitionBuilder (org.eclipse.smarthome.core.thing.type.ChannelDefinitionBuilder)12 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)10 ChannelDefinition (org.eclipse.smarthome.core.thing.type.ChannelDefinition)8 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)8 ArrayList (java.util.ArrayList)5 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)5 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)5 URI (java.net.URI)3 Configuration (org.eclipse.smarthome.config.core.Configuration)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)3 ChannelGroupType (org.eclipse.smarthome.core.thing.type.ChannelGroupType)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 Locale (java.util.Locale)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ItemRegistry (org.eclipse.smarthome.core.items.ItemRegistry)2 Channel (org.eclipse.smarthome.core.thing.Channel)2 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)2 ThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory)2