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);
}
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);
}
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;
}
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);
}
}
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());
}
Aggregations