use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class FSInternetRadioHandlerJavaTest method getChannel.
@NonNull
private static Channel getChannel(@NonNull final Thing thing, @NonNull final String channelId) {
final Channel channel = thing.getChannel(channelId);
Assert.assertNotNull(channel);
return channel;
}
use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class ChannelStateDescriptionProviderOSGiTest method setup.
@Before
public void setup() {
initMocks(this);
Mockito.when(componentContext.getBundleContext()).thenReturn(bundleContext);
registerVolatileStorageService();
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
final TestThingHandlerFactory thingHandlerFactory = new TestThingHandlerFactory();
thingHandlerFactory.activate(componentContext);
registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
final StateDescription state = new StateDescription(BigDecimal.ZERO, BigDecimal.valueOf(100), BigDecimal.TEN, "%d Peek", true, Collections.singletonList(new StateOption("SOUND", "My great sound.")));
final StateDescription state2 = new StateDescription(BigDecimal.ZERO, BigDecimal.valueOf(256), BigDecimal.valueOf(8), null, false, null);
final ChannelType channelType = new ChannelType(new ChannelTypeUID("hue:alarm"), false, "Number", " ", "", null, null, state, null);
final ChannelType channelType2 = new ChannelType(new ChannelTypeUID("hue:num"), false, "Number", " ", "", null, null, state2, null);
final ChannelType channelType3 = new ChannelType(new ChannelTypeUID("hue:info"), true, "String", " ", "", null, null, null, null);
final ChannelType channelType4 = new ChannelType(new ChannelTypeUID("hue:color"), false, "Color", "Color", "", "ColorLight", null, null, null);
final ChannelType channelType5 = new ChannelType(new ChannelTypeUID("hue:brightness"), false, "Dimmer", "Brightness", "", "DimmableLight", null, null, null);
final ChannelType channelType6 = new ChannelType(new ChannelTypeUID("hue:switch"), false, "Switch", "Switch", "", "Light", null, null, null);
final ChannelType channelType7 = new ChannelType(new ChannelTypeUID("hue:num-dynamic"), false, "Number", " ", "", "Light", null, state, null);
List<ChannelType> channelTypes = new ArrayList<>();
channelTypes.add(channelType);
channelTypes.add(channelType2);
channelTypes.add(channelType3);
channelTypes.add(channelType4);
channelTypes.add(channelType5);
channelTypes.add(channelType6);
channelTypes.add(channelType7);
registerService(new ChannelTypeProvider() {
@Override
public Collection<ChannelType> getChannelTypes(Locale locale) {
return channelTypes;
}
@Override
public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) {
for (final ChannelType channelType : channelTypes) {
if (channelType.getUID().equals(channelTypeUID)) {
return channelType;
}
}
return null;
}
@Override
public ChannelGroupType getChannelGroupType(ChannelGroupTypeUID channelGroupTypeUID, Locale locale) {
return null;
}
@Override
public Collection<ChannelGroupType> getChannelGroupTypes(Locale locale) {
return Collections.emptySet();
}
});
registerService(new DynamicStateDescriptionProvider() {
final StateDescription newState = new StateDescription(BigDecimal.valueOf(10), BigDecimal.valueOf(100), BigDecimal.valueOf(5), "VALUE %d", false, Arrays.asList(new StateOption("value0", "label0"), new StateOption("value1", "label1")));
@Override
@Nullable
public StateDescription getStateDescription(@NonNull Channel channel, @Nullable StateDescription original, @Nullable Locale locale) {
String id = channel.getUID().getIdWithoutGroup();
if ("7_1".equals(id)) {
assertEquals(channel.getChannelTypeUID(), channelType7.getUID());
return newState;
} else if ("7_2".equals(id)) {
assertEquals(channel.getChannelTypeUID(), channelType7.getUID());
StateDescription newState2 = new StateDescription(original.getMinimum().add(BigDecimal.ONE), original.getMaximum().add(BigDecimal.ONE), original.getStep().add(BigDecimal.TEN), "NEW " + original.getPattern(), true, original.getOptions());
return newState2;
}
return null;
}
});
List<ChannelDefinition> channelDefinitions = new ArrayList<>();
channelDefinitions.add(new ChannelDefinition("1", channelType.getUID()));
channelDefinitions.add(new ChannelDefinition("2", channelType2.getUID()));
channelDefinitions.add(new ChannelDefinition("3", channelType3.getUID()));
channelDefinitions.add(new ChannelDefinition("4", channelType4.getUID()));
channelDefinitions.add(new ChannelDefinition("5", channelType5.getUID()));
channelDefinitions.add(new ChannelDefinition("6", channelType6.getUID()));
channelDefinitions.add(new ChannelDefinition("7_1", channelType7.getUID()));
channelDefinitions.add(new ChannelDefinition("7_2", channelType7.getUID()));
registerService(new SimpleThingTypeProvider(Collections.singleton(ThingTypeBuilder.instance(new ThingTypeUID("hue:lamp"), "label").withChannelDefinitions(channelDefinitions).build())));
List<Item> items = new ArrayList<>();
items.add(new NumberItem("TestItem"));
items.add(new NumberItem("TestItem2"));
items.add(new StringItem("TestItem3"));
items.add(new ColorItem("TestItem4"));
items.add(new DimmerItem("TestItem5"));
items.add(new SwitchItem("TestItem6"));
items.add(new NumberItem("TestItem7_1"));
items.add(new NumberItem("TestItem7_2"));
registerService(new TestItemProvider(items));
linkRegistry = getService(ItemChannelLinkRegistry.class);
stateDescriptionProvider = getService(StateDescriptionProvider.class);
assertNotNull(stateDescriptionProvider);
}
use of org.eclipse.smarthome.core.thing.Channel 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());
}
use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class DeviceHandler method loadOutputChannel.
private void loadOutputChannel(ChannelTypeUID channelTypeUID, String acceptedItemType) {
if (channelTypeUID == null || acceptedItemType == null) {
return;
}
currentChannel = channelTypeUID.getId();
List<Channel> channelList = new LinkedList<Channel>(this.getThing().getChannels());
boolean channelIsAlreadyLoaded = false;
boolean channelListChanged = false;
if (!channelList.isEmpty()) {
Iterator<Channel> channelInter = channelList.iterator();
while (channelInter.hasNext()) {
Channel eshChannel = channelInter.next();
if (DsChannelTypeProvider.isOutputChannel(eshChannel.getUID().getId())) {
if (!eshChannel.getUID().getId().equals(currentChannel) && !(device.isShade() && eshChannel.getUID().getId().equals(DsChannelTypeProvider.SHADE))) {
channelInter.remove();
channelListChanged = true;
} else {
if (!eshChannel.getUID().getId().equals(DsChannelTypeProvider.SHADE)) {
channelIsAlreadyLoaded = true;
}
}
}
}
}
if (!channelIsAlreadyLoaded && currentChannel != null) {
Channel channel = ChannelBuilder.create(new ChannelUID(this.getThing().getUID(), channelTypeUID.getId()), acceptedItemType).withType(channelTypeUID).build();
channelList.add(channel);
channelListChanged = true;
}
if (channelListChanged) {
ThingBuilder thingBuilder = editThing();
thingBuilder.withChannels(channelList);
updateThing(thingBuilder.build());
logger.debug("load channel: {} with item: {}", channelTypeUID.getAsString(), acceptedItemType);
}
}
use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class AstroThingHandler method publishChannelIfLinked.
/**
* Publishes the channel with data if it's linked.
*/
public void publishChannelIfLinked(ChannelUID channelUID) {
if (isLinked(channelUID.getId()) && getPlanet() != null) {
final Channel channel = getThing().getChannel(channelUID.getId());
if (channel == null) {
logger.error("Cannot find channel for {}", channelUID);
return;
}
try {
AstroChannelConfig config = channel.getConfiguration().as(AstroChannelConfig.class);
updateState(channelUID, PropertyUtils.getState(channelUID, config, getPlanet()));
} catch (Exception ex) {
logger.error("Can't update state for channel {} : {}", channelUID, ex.getMessage(), ex);
}
}
}
Aggregations