use of org.openhab.core.thing.binding.ThingTypeProvider 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(obj -> unregisterService(obj));
}
use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.
the class DynamicThingUpdateOSGiTest method setUp.
@BeforeEach
public void setUp() {
registerVolatileStorageService();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(THING_TYPE);
registerService(thingTypeProvider);
inbox = getService(Inbox.class);
managedThingProvider = getService(ManagedThingProvider.class);
assertEquals(0, inbox.getAll().size());
ThingHandlerFactory thingHandlerFactory = createThingHandlerFactory();
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
}
use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.
the class ThingManagerOSGiJavaTest method registerThingTypeProvider.
private void registerThingTypeProvider() throws Exception {
ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "label").withConfigDescriptionURI(configDescriptionThing).withChannelDefinitions(List.of(new ChannelDefinitionBuilder(CHANNEL_ID, CHANNEL_TYPE_UID).build())).build();
ThingTypeProvider mockThingTypeProvider = mock(ThingTypeProvider.class);
when(mockThingTypeProvider.getThingType(eq(THING_TYPE_UID), any())).thenReturn(thingType);
registerService(mockThingTypeProvider);
}
use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.
the class ThingManagerOSGiTest method registerThingTypeProvider.
private void registerThingTypeProvider() {
ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("binding", "type"), "label").withConfigDescriptionURI(THING_CONFIG_URI).build();
ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class);
when(thingTypeProvider.getThingType(any(ThingTypeUID.class), nullable(Locale.class))).thenReturn(thingType);
registerService(thingTypeProvider);
ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class);
when(thingTypeRegistry.getThingType(any(ThingTypeUID.class))).thenReturn(thingType);
registerService(thingTypeRegistry);
}
use of org.openhab.core.thing.binding.ThingTypeProvider in project openhab-core by openhab.
the class SystemWideChannelTypesTest method setUp.
@BeforeEach
public void setUp() {
thingTypeProvider = getService(ThingTypeProvider.class);
assertThat(thingTypeProvider, is(notNullValue()));
channelTypeRegistry = getService(ChannelTypeRegistry.class);
assertThat(channelTypeRegistry, is(notNullValue()));
ChannelTypeProvider provider = getService(ChannelTypeProvider.class, DefaultSystemChannelTypeProvider.class);
assertTrue(provider instanceof DefaultSystemChannelTypeProvider);
systemChannelTypeProvider = provider;
}
Aggregations