Search in sources :

Example 1 with ProfileTypeUID

use of org.openhab.core.thing.profiles.ProfileTypeUID in project addons by smarthomej.

the class MathTransformationProfileFactoryTest method systemProfileTypesAndUidsShouldBeAvailable.

@Test
public void systemProfileTypesAndUidsShouldBeAvailable() {
    Collection<ProfileTypeUID> supportedProfileTypeUIDs = profileFactory.getSupportedProfileTypeUIDs();
    assertThat(supportedProfileTypeUIDs, hasSize(NUMBER_OF_PROFILES));
    Collection<ProfileType> supportedProfileTypes = profileFactory.getProfileTypes(null);
    assertThat(supportedProfileTypeUIDs, hasSize(NUMBER_OF_PROFILES));
    for (ProfileType profileType : supportedProfileTypes) {
        assertTrue(supportedProfileTypeUIDs.contains(profileType.getUID()));
    }
}
Also used : ProfileType(org.openhab.core.thing.profiles.ProfileType) ProfileTypeUID(org.openhab.core.thing.profiles.ProfileTypeUID) Test(org.junit.jupiter.api.Test)

Example 2 with ProfileTypeUID

use of org.openhab.core.thing.profiles.ProfileTypeUID in project openhab-core by openhab.

the class CommunicationManagerOSGiTest method beforeEach.

@BeforeEach
public void beforeEach() {
    safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    SystemProfileFactory profileFactory = getService(ProfileTypeProvider.class, SystemProfileFactory.class);
    assertNotNull(profileFactory);
    if (profileFactory == null) {
        throw new IllegalStateException("thing is null");
    }
    manager = new CommunicationManager(autoUpdateManagerMock, channelTypeRegistryMock, profileFactory, iclRegistry, itemRegistryMock, itemStateConverterMock, eventPublisherMock, safeCaller, thingRegistryMock);
    doAnswer(invocation -> {
        switch(((Channel) invocation.getArguments()[0]).getKind()) {
            case STATE:
                return new ProfileTypeUID("test:state");
            case TRIGGER:
                return new ProfileTypeUID("test:trigger");
        }
        return null;
    }).when(profileAdvisorMock).getSuggestedProfileTypeUID(isA(Channel.class), isA(String.class));
    doAnswer(invocation -> {
        switch(((ProfileTypeUID) invocation.getArguments()[0]).toString()) {
            case "test:state":
                return stateProfileMock;
            case "test:trigger":
                return triggerProfileMock;
        }
        return null;
    }).when(profileFactoryMock).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class), isA(ProfileContext.class));
    when(profileFactoryMock.getSupportedProfileTypeUIDs()).thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList()));
    manager.addProfileFactory(profileFactoryMock);
    manager.addProfileAdvisor(profileAdvisorMock);
    iclRegistry.addProvider(new ItemChannelLinkProvider() {

        @Override
        public void addProviderChangeListener(ProviderChangeListener<ItemChannelLink> listener) {
        }

        @Override
        public void removeProviderChangeListener(ProviderChangeListener<ItemChannelLink> listener) {
        }

        @Override
        public Collection<ItemChannelLink> getAll() {
            return List.of(LINK_1_S1, LINK_1_S2, LINK_2_S2, LINK_1_T1, LINK_1_T2, LINK_2_T2, LINK_3_S3, LINK_4_S4);
        }
    });
    when(itemRegistryMock.get(eq(ITEM_NAME_1))).thenReturn(ITEM_1);
    when(itemRegistryMock.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
    when(itemRegistryMock.get(eq(ITEM_NAME_3))).thenReturn(ITEM_3);
    when(itemRegistryMock.get(eq(ITEM_NAME_4))).thenReturn(ITEM_4);
    ChannelType channelType4 = mock(ChannelType.class);
    when(channelType4.getItemType()).thenReturn("Number:Temperature");
    when(channelTypeRegistryMock.getChannelType(CHANNEL_TYPE_UID_4)).thenReturn(channelType4);
    THING.setHandler(thingHandlerMock);
    when(thingRegistryMock.get(eq(THING_UID))).thenReturn(THING);
    manager.addItemFactory(new CoreItemFactory());
    UnitProvider unitProvider = mock(UnitProvider.class);
    when(unitProvider.getUnit(Temperature.class)).thenReturn(SIUnits.CELSIUS);
    ITEM_3.setUnitProvider(unitProvider);
    ITEM_4.setUnitProvider(unitProvider);
}
Also used : ProfileCallback(org.openhab.core.thing.profiles.ProfileCallback) Channel(org.openhab.core.thing.Channel) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ProfileTypeUID(org.openhab.core.thing.profiles.ProfileTypeUID) CoreItemFactory(org.openhab.core.library.CoreItemFactory) SafeCaller(org.openhab.core.common.SafeCaller) SystemProfileFactory(org.openhab.core.thing.internal.profiles.SystemProfileFactory) ProfileContext(org.openhab.core.thing.profiles.ProfileContext) UnitProvider(org.openhab.core.i18n.UnitProvider) Collection(java.util.Collection) ChannelType(org.openhab.core.thing.type.ChannelType) ItemChannelLinkProvider(org.openhab.core.thing.link.ItemChannelLinkProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ProfileTypeUID

use of org.openhab.core.thing.profiles.ProfileTypeUID in project addons by smarthomej.

the class BasicProfilesFactoryTest method systemProfileTypesAndUidsShouldBeAvailable.

@Test
public void systemProfileTypesAndUidsShouldBeAvailable() {
    Collection<ProfileTypeUID> supportedProfileTypeUIDs = profileFactory.getSupportedProfileTypeUIDs();
    assertThat(supportedProfileTypeUIDs, hasSize(NUMBER_OF_PROFILES));
    Collection<ProfileType> supportedProfileTypes = profileFactory.getProfileTypes(null);
    assertThat(supportedProfileTypeUIDs, hasSize(NUMBER_OF_PROFILES));
    for (ProfileType profileType : supportedProfileTypes) {
        assertTrue(supportedProfileTypeUIDs.contains(profileType.getUID()));
    }
}
Also used : ProfileType(org.openhab.core.thing.profiles.ProfileType) ProfileTypeUID(org.openhab.core.thing.profiles.ProfileTypeUID) Test(org.junit.jupiter.api.Test)

Example 4 with ProfileTypeUID

use of org.openhab.core.thing.profiles.ProfileTypeUID in project openhab-core by openhab.

the class CommunicationManager method getProfile.

private Profile getProfile(ItemChannelLink link, Item item, @Nullable Thing thing) {
    synchronized (profiles) {
        Profile profile = profiles.get(link.getUID());
        if (profile != null) {
            logger.trace("Using profile '{}' from cache for link '{}'", profile.getProfileTypeUID(), link);
            return profile;
        }
        ProfileTypeUID profileTypeUID = determineProfileTypeUID(link, item, thing);
        if (profileTypeUID != null) {
            profile = getProfileFromFactories(profileTypeUID, link, createCallback(link));
            if (profile != null) {
                profiles.put(link.getUID(), profile);
                return profile;
            }
        }
        logger.trace("No Profile found for link '{}', using NoOpProfile", link);
        return NO_OP_PROFILE;
    }
}
Also used : TriggerProfile(org.openhab.core.thing.profiles.TriggerProfile) StateProfile(org.openhab.core.thing.profiles.StateProfile) Profile(org.openhab.core.thing.profiles.Profile) ProfileTypeUID(org.openhab.core.thing.profiles.ProfileTypeUID)

Example 5 with ProfileTypeUID

use of org.openhab.core.thing.profiles.ProfileTypeUID in project openhab-core by openhab.

the class CommunicationManager method determineProfileTypeUID.

@Nullable
private ProfileTypeUID determineProfileTypeUID(ItemChannelLink link, Item item, @Nullable Thing thing) {
    ProfileTypeUID profileTypeUID = getConfiguredProfileTypeUID(link);
    Channel channel = null;
    if (profileTypeUID == null) {
        if (thing == null) {
            return null;
        }
        channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }
        // ask advisors
        profileTypeUID = getAdvice(link, item, channel);
        if (profileTypeUID == null) {
            // ask default advisor
            logger.trace("No profile advisor found for link '{}', falling back to the defaults", link);
            profileTypeUID = defaultProfileFactory.getSuggestedProfileTypeUID(channel, item.getType());
        }
    }
    return profileTypeUID;
}
Also used : Channel(org.openhab.core.thing.Channel) ProfileTypeUID(org.openhab.core.thing.profiles.ProfileTypeUID) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ProfileTypeUID (org.openhab.core.thing.profiles.ProfileTypeUID)6 Test (org.junit.jupiter.api.Test)2 Channel (org.openhab.core.thing.Channel)2 ProfileType (org.openhab.core.thing.profiles.ProfileType)2 Collection (java.util.Collection)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 SafeCaller (org.openhab.core.common.SafeCaller)1 UnitProvider (org.openhab.core.i18n.UnitProvider)1 CoreItemFactory (org.openhab.core.library.CoreItemFactory)1 SystemProfileFactory (org.openhab.core.thing.internal.profiles.SystemProfileFactory)1 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)1 ItemChannelLinkProvider (org.openhab.core.thing.link.ItemChannelLinkProvider)1 Profile (org.openhab.core.thing.profiles.Profile)1 ProfileCallback (org.openhab.core.thing.profiles.ProfileCallback)1 ProfileContext (org.openhab.core.thing.profiles.ProfileContext)1 StateProfile (org.openhab.core.thing.profiles.StateProfile)1 StateProfileType (org.openhab.core.thing.profiles.StateProfileType)1 TriggerProfile (org.openhab.core.thing.profiles.TriggerProfile)1 TriggerProfileType (org.openhab.core.thing.profiles.TriggerProfileType)1