Search in sources :

Example 1 with ProfileTypeUID

use of org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID in project smarthome by eclipse.

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) {
            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;
            }
        }
        return new NoOpProfile();
    }
}
Also used : StateProfile(org.eclipse.smarthome.core.thing.profiles.StateProfile) TriggerProfile(org.eclipse.smarthome.core.thing.profiles.TriggerProfile) Profile(org.eclipse.smarthome.core.thing.profiles.Profile) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID)

Example 2 with ProfileTypeUID

use of org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID in project smarthome by eclipse.

the class CommunicationManagerTest method setup.

@Before
public void setup() {
    initMocks(this);
    safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    manager = new CommunicationManager();
    manager.setEventPublisher(eventPublisher);
    manager.setDefaultProfileFactory(new SystemProfileFactory());
    manager.setSafeCaller(safeCaller);
    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(mockProfileAdvisor).getSuggestedProfileTypeUID(isA(Channel.class), isA(String.class));
    doAnswer(invocation -> {
        switch(((ProfileTypeUID) invocation.getArguments()[0]).toString()) {
            case "test:state":
                return stateProfile;
            case "test:trigger":
                return triggerProfile;
        }
        return null;
    }).when(mockProfileFactory).createProfile(isA(ProfileTypeUID.class), isA(ProfileCallback.class), isA(ProfileContext.class));
    when(mockProfileFactory.getSupportedProfileTypeUIDs()).thenReturn(Stream.of(new ProfileTypeUID("test:state"), new ProfileTypeUID("test:trigger")).collect(Collectors.toList()));
    manager.addProfileFactory(mockProfileFactory);
    manager.addProfileAdvisor(mockProfileAdvisor);
    ItemChannelLinkRegistry iclRegistry = new ItemChannelLinkRegistry() {

        @Override
        public Stream<ItemChannelLink> stream() {
            return Arrays.asList(LINK_1_S1, LINK_1_S2, LINK_2_S2, LINK_1_T1, LINK_1_T2, LINK_2_T2).stream();
        }
    };
    manager.setItemChannelLinkRegistry(iclRegistry);
    when(itemRegistry.get(eq(ITEM_NAME_1))).thenReturn(ITEM_1);
    when(itemRegistry.get(eq(ITEM_NAME_2))).thenReturn(ITEM_2);
    manager.setItemRegistry(itemRegistry);
    THING.setHandler(mockHandler);
    when(thingRegistry.get(eq(THING_UID))).thenReturn(THING);
    manager.setThingRegistry(thingRegistry);
    manager.addItemFactory(new CoreItemFactory());
}
Also used : CoreItemFactory(org.eclipse.smarthome.core.library.CoreItemFactory) SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) SystemProfileFactory(org.eclipse.smarthome.core.thing.internal.profiles.SystemProfileFactory) ProfileCallback(org.eclipse.smarthome.core.thing.profiles.ProfileCallback) ProfileContext(org.eclipse.smarthome.core.thing.profiles.ProfileContext) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Before(org.junit.Before)

Example 3 with ProfileTypeUID

use of org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID in project smarthome by eclipse.

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.eclipse.smarthome.core.thing.Channel) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with ProfileTypeUID

use of org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID in project smarthome by eclipse.

the class ChannelTypeResourceTest method returnLinkableItemTypesForTriggerChannelType.

@SuppressWarnings("unchecked")
@Test
public void returnLinkableItemTypesForTriggerChannelType() throws IOException {
    ChannelType channelType = mockChannelType("ct");
    ChannelTypeUID uid = channelType.getUID();
    ProfileTypeUID profileTypeUID = new ProfileTypeUID("system:profileType");
    when(channelTypeRegistry.getChannelType(uid)).thenReturn(channelType);
    TriggerProfileType profileType = mock(TriggerProfileType.class);
    when(profileType.getUID()).thenReturn(profileTypeUID);
    when(profileType.getSupportedChannelTypeUIDs()).thenReturn(Collections.singletonList(uid));
    when(profileType.getSupportedItemTypes()).thenReturn(Arrays.asList("Switch", "Dimmer"));
    when(profileTypeRegistry.getProfileTypes()).thenReturn(Collections.singletonList(profileType));
    Response response = channelTypeResource.getLinkableItemTypes(uid.getAsString());
    verify(channelTypeRegistry).getChannelType(uid);
    verify(profileTypeRegistry).getProfileTypes();
    assertThat(response.getStatus(), is(200));
    assertThat((Set<String>) response.getEntity(), IsCollectionContaining.hasItems("Switch", "Dimmer"));
}
Also used : Response(javax.ws.rs.core.Response) TriggerProfileType(org.eclipse.smarthome.core.thing.profiles.TriggerProfileType) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Test(org.junit.Test)

Aggregations

ProfileTypeUID (org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID)4 Channel (org.eclipse.smarthome.core.thing.Channel)2 Response (javax.ws.rs.core.Response)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 SafeCaller (org.eclipse.smarthome.core.common.SafeCaller)1 CoreItemFactory (org.eclipse.smarthome.core.library.CoreItemFactory)1 SystemProfileFactory (org.eclipse.smarthome.core.thing.internal.profiles.SystemProfileFactory)1 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)1 ItemChannelLinkRegistry (org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry)1 Profile (org.eclipse.smarthome.core.thing.profiles.Profile)1 ProfileCallback (org.eclipse.smarthome.core.thing.profiles.ProfileCallback)1 ProfileContext (org.eclipse.smarthome.core.thing.profiles.ProfileContext)1 StateProfile (org.eclipse.smarthome.core.thing.profiles.StateProfile)1 TriggerProfile (org.eclipse.smarthome.core.thing.profiles.TriggerProfile)1 TriggerProfileType (org.eclipse.smarthome.core.thing.profiles.TriggerProfileType)1 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1 Before (org.junit.Before)1 Test (org.junit.Test)1