use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.
the class BindingBaseClassesOSGiTest method registerThingTypeAndConfigDescription.
private void registerThingTypeAndConfigDescription() {
ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label").withConfigDescriptionURI(BINDING_CONFIG_URI).build();
ConfigDescription configDescription = ConfigDescriptionBuilder.create(BINDING_CONFIG_URI).withParameter(ConfigDescriptionParameterBuilder.create("parameter", ConfigDescriptionParameter.Type.TEXT).withRequired(true).build()).build();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.any(Locale.class))).thenReturn(thingType);
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(ArgumentMatchers.any(ThingTypeUID.class))).thenReturn(thingType);
registerService(thingTypeRegistry);
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(ArgumentMatchers.any(URI.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(configDescription);
registerService(configDescriptionProvider);
}
use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.
the class BindingBaseClassesOSGiTest method registerThingTypeProvider.
private void registerThingTypeProvider() {
ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label").withConfigDescriptionURI(BINDING_CONFIG_URI).build();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(thingType);
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(ArgumentMatchers.any(ThingTypeUID.class))).thenReturn(thingType);
registerService(thingTypeRegistry);
}
use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.
the class ChangeThingTypeOSGiTest method setup.
@BeforeEach
public void setup() throws URISyntaxException {
registerVolatileStorageService();
managedThingProvider = getService(ManagedThingProvider.class);
assertThat(managedThingProvider, is(notNullValue()));
configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertThat(configDescriptionRegistry, is(notNullValue()));
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
assertThat(managedItemChannelLinkProvider, is(notNullValue()));
managedItemProvider = getService(ManagedItemProvider.class);
assertThat(managedItemProvider, is(notNullValue()));
ComponentContext componentContext = mock(ComponentContext.class);
when(componentContext.getBundleContext()).thenReturn(bundleContext);
thingHandlerFactory = new SampleThingHandlerFactory();
thingHandlerFactory.activate(componentContext);
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
Map<String, String> thingTypeGenericProperties = Map.ofEntries(entry(PROPERTY_ON_GENERIC_THING_TYPE, GENERIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, GENERIC_VALUE));
Map<String, String> thingTypeSpecificProperties = Map.ofEntries(entry(PROPERTY_ON_SPECIFIC_THING_TYPE, SPECIFIC_VALUE), entry(PROPERTY_ON_GENERIC_AND_SPECIFIC_THING_TYPE, SPECIFIC_VALUE));
thingTypeGeneric = registerThingTypeAndConfigDescription(THING_TYPE_GENERIC_UID, thingTypeGenericProperties);
thingTypeSpecific = registerThingTypeAndConfigDescription(THING_TYPE_SPECIFIC_UID, thingTypeSpecificProperties);
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(any(), any())).thenAnswer(invocation -> thingTypes.get(invocation.getArgument(0)));
registerService(thingTypeRegistry);
ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class);
when(configDescriptionProvider.getConfigDescription(any(), any())).thenAnswer(invocation -> configDescriptions.get(invocation.getArgument(0)));
registerService(configDescriptionProvider);
ChannelTypeProvider channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelTypes(any())).thenReturn(channelTypes.values());
when(channelTypeProvider.getChannelType(any(), any())).thenAnswer(invocation -> channelTypes.get(invocation.getArgument(0)));
registerService(channelTypeProvider);
ChannelGroupTypeProvider channelGroupTypeProvider = mock(ChannelGroupTypeProvider.class);
when(channelGroupTypeProvider.getChannelGroupTypes(any())).thenReturn(channelGroupTypes.values());
when(channelGroupTypeProvider.getChannelGroupType(any(), any())).thenAnswer(invocation -> channelGroupTypes.get(invocation.getArgument(0)));
registerService(channelGroupTypeProvider);
managedItemProvider.add(new StringItem(ITEM_GENERIC));
managedItemProvider.add(new StringItem(ITEM_SPECIFIC));
managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_GENERIC);
managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK_SPECIFIC);
}
use of org.openhab.core.thing.type.ThingTypeRegistry in project openhab-core by openhab.
the class InboxOSGiTest method assertThatApproveAddsPropertiesOfDiscoveryResultWhichAreConfigDescriptionParametersAsThingConfigurationPropertiesAndPropertiesWhichAreNoConfigDescriptionParametersAsThingProperties.
@Test
@SuppressWarnings("null")
public void assertThatApproveAddsPropertiesOfDiscoveryResultWhichAreConfigDescriptionParametersAsThingConfigurationPropertiesAndPropertiesWhichAreNoConfigDescriptionParametersAsThingProperties() {
final List<Object> services = new LinkedList<>();
inbox.add(testDiscoveryResult);
final ThingTypeProvider thingTypeProvider = new ThingTypeProvider() {
@Override
public Collection<ThingType> getThingTypes(@Nullable Locale locale) {
return Set.of(testThingType);
}
@Override
@Nullable
public ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale) {
return thingTypeUID.equals(testThingType.getUID()) ? testThingType : null;
}
};
services.add(registerService(thingTypeProvider));
final ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class);
assertNotNull(thingTypeRegistry);
waitForAssert(() -> assertNotNull(thingTypeRegistry.getThingType(testThingType.getUID())));
final ConfigDescriptionProvider configDescriptionProvider = new ConfigDescriptionProvider() {
@Override
public Collection<ConfigDescription> getConfigDescriptions(@Nullable Locale locale) {
return Set.of(testConfigDescription);
}
@Override
@Nullable
public ConfigDescription getConfigDescription(URI uri, @Nullable Locale locale) {
return uri.equals(testConfigDescription.getUID()) ? testConfigDescription : null;
}
};
services.add(registerService(configDescriptionProvider));
final ConfigDescriptionRegistry configDescriptionRegistry = getService(ConfigDescriptionRegistry.class);
assertNotNull(configDescriptionRegistry);
waitForAssert(() -> assertNotNull(configDescriptionRegistry.getConfigDescription(testConfigDescription.getUID())));
Thing approvedThing = inbox.approve(testThing.getUID(), testThingLabel, null);
Thing addedThing = registry.get(testThing.getUID());
assertTrue(approvedThing.equals(addedThing));
assertFalse(addedThing == null);
for (String key : keysInConfigDescription) {
Object thingConfItem = addedThing.getConfiguration().get(key);
Object descResultParam = discoveryResultProperties.get(key);
if (descResultParam instanceof Number) {
descResultParam = new BigDecimal(descResultParam.toString());
}
assertFalse(thingConfItem == null);
assertFalse(descResultParam == null);
assertTrue(thingConfItem.equals(descResultParam));
}
for (String key : keysNotInConfigDescription) {
String thingProperty = addedThing.getProperties().get(key);
String descResultParam = String.valueOf(discoveryResultProperties.get(key));
assertFalse(thingProperty == null);
assertFalse(descResultParam == null);
assertTrue(thingProperty.equals(descResultParam));
}
services.forEach(this::unregisterService);
}
use of org.openhab.core.thing.type.ThingTypeRegistry 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;
}
Aggregations