Search in sources :

Example 6 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class SunPhaseJob method run.

@Override
public void run() {
    AstroThingHandler astroHandler = AstroHandlerFactory.getHandler(getThingUID());
    if (checkNull(astroHandler, "AstroThingHandler is null")) {
        return;
    }
    Channel phaseNameChannel = astroHandler.getThing().getChannel(CHANNEL_ID_SUN_PHASE_NAME);
    if (checkNull(phaseNameChannel, "Phase Name Channel is null")) {
        return;
    }
    Planet planet = astroHandler.getPlanet();
    if (planet != null && planet instanceof Sun) {
        final Sun typedSun = (Sun) planet;
        typedSun.getPhase().setName(sunPhaseName);
        astroHandler.publishChannelIfLinked(phaseNameChannel.getUID());
    }
}
Also used : AstroThingHandler(org.eclipse.smarthome.binding.astro.handler.AstroThingHandler) Channel(org.eclipse.smarthome.core.thing.Channel) Planet(org.eclipse.smarthome.binding.astro.internal.model.Planet) Sun(org.eclipse.smarthome.binding.astro.internal.model.Sun)

Example 7 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class ThingManagerOSGiJavaTest method testCreateChannelBuilder.

@Test
public void testCreateChannelBuilder() throws Exception {
    registerThingTypeProvider();
    registerChannelTypeProvider();
    AtomicReference<ThingHandlerCallback> thc = new AtomicReference<>();
    ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {

        @Override
        public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
            return true;
        }

        @Override
        @Nullable
        protected ThingHandler createHandler(@NonNull Thing thing) {
            ThingHandler mockHandler = mock(ThingHandler.class);
            doAnswer(a -> {
                thc.set((ThingHandlerCallback) a.getArguments()[0]);
                return null;
            }).when(mockHandler).setCallback(any(ThingHandlerCallback.class));
            when(mockHandler.getThing()).thenReturn(THING);
            return mockHandler;
        }
    };
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    new Thread((Runnable) () -> managedThingProvider.add(THING)).start();
    waitForAssert(() -> {
        assertNotNull(thc.get());
    });
    ChannelBuilder channelBuilder = thc.get().createChannelBuilder(new ChannelUID(THING_UID, "test"), CHANNEL_TYPE_UID);
    Channel channel = channelBuilder.build();
    assertThat(channel.getLabel(), is("Test Label"));
    assertThat(channel.getDescription(), is("Test Description"));
    assertThat(channel.getAcceptedItemType(), is("Switch"));
    assertThat(channel.getDefaultTags().size(), is(1));
    assertThat(channel.getDefaultTags().iterator().next(), is("Test Tag"));
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) ThingHandlerCallback(org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback) AtomicReference(java.util.concurrent.atomic.AtomicReference) BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) BaseThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) NonNull(org.eclipse.jdt.annotation.NonNull) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ChannelBuilder(org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 8 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class SystemProfileFactoryTest method testGetSuggestedProfileTypeUID_nullChannelType2.

@Test
public void testGetSuggestedProfileTypeUID_nullChannelType2() {
    Channel channel = ChannelBuilder.create(new ChannelUID("test:test:test:test"), CoreItemFactory.SWITCH).build();
    assertThat(factory.getSuggestedProfileTypeUID(channel, CoreItemFactory.SWITCH), is(SystemProfiles.DEFAULT));
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) Test(org.junit.Test)

Example 9 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class DeviceHandler method checkSensorChannel.

private void checkSensorChannel() {
    List<Channel> channelList = new LinkedList<Channel>(this.getThing().getChannels());
    boolean channelListChanged = false;
    // if sensor channels with priority never are loaded delete these channels
    if (!channelList.isEmpty()) {
        Iterator<Channel> channelInter = channelList.iterator();
        while (channelInter.hasNext()) {
            Channel channel = channelInter.next();
            String channelID = channel.getUID().getId();
            if (channelID.startsWith(DsChannelTypeProvider.BINARY_INPUT_PRE)) {
                DeviceBinarayInputEnum devBinInput = getBinaryInput(channelID);
                if (device.getBinaryInput(devBinInput) != null) {
                    addLoadedSensorChannel(channelID);
                } else {
                    logger.debug("remove {} binary input channel", channelID);
                    channelInter.remove();
                    channelListChanged = removeLoadedSensorChannel(channelID);
                }
            } else {
                SensorEnum sensorType = getSensorEnum(channelID);
                if (sensorType != null) {
                    if (SensorEnum.isPowerSensor(sensorType)) {
                        if (device.checkPowerSensorRefreshPriorityNever(sensorType)) {
                            logger.debug("remove {} sensor channel", channelID);
                            channelInter.remove();
                            channelListChanged = removeLoadedSensorChannel(channelID);
                        } else {
                            addLoadedSensorChannel(channelID);
                        }
                    } else {
                        if (device.supportsSensorType(sensorType)) {
                            addLoadedSensorChannel(channelID);
                        } else {
                            logger.debug("remove {} sensor channel", channelID);
                            channelInter.remove();
                            removeLoadedSensorChannel(channelID);
                            channelListChanged = true;
                        }
                    }
                }
            }
        }
    }
    for (SensorEnum sensorType : device.getPowerSensorTypes()) {
        if (!device.checkPowerSensorRefreshPriorityNever(sensorType) && !isSensorChannelLoaded(getSensorChannelID(sensorType))) {
            logger.debug("create {} sensor channel", sensorType.toString());
            channelList.add(getSensorChannel(sensorType));
            channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
        }
    }
    if (device.hasClimateSensors()) {
        for (SensorEnum sensorType : device.getClimateSensorTypes()) {
            if (!isSensorChannelLoaded(getSensorChannelID(sensorType))) {
                logger.debug("create {} sensor channel", sensorType.toString());
                channelList.add(getSensorChannel(sensorType));
                channelListChanged = addLoadedSensorChannel(getSensorChannelID(sensorType));
            }
        }
    }
    if (device.isBinaryInputDevice()) {
        for (DeviceBinaryInput binInput : device.getBinaryInputs()) {
            DeviceBinarayInputEnum binInputType = DeviceBinarayInputEnum.getdeviceBinarayInput(binInput.getInputType());
            if (binInputType != null && !isSensorChannelLoaded(getBinaryInputChannelID(binInputType))) {
                logger.debug("create {} sensor channel", binInputType.toString());
                channelList.add(getBinaryChannel(binInputType));
                channelListChanged = addLoadedSensorChannel(getBinaryInputChannelID(binInputType));
            }
        }
    }
    if (channelListChanged) {
        logger.debug("load new channel list");
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withChannels(channelList);
        updateThing(thingBuilder.build());
    }
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) DeviceBinaryInput(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceBinaryInput) SensorEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum) DeviceBinarayInputEnum(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.DeviceBinarayInputEnum) Channel(org.eclipse.smarthome.core.thing.Channel) LinkedList(java.util.LinkedList)

Example 10 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class ZoneTemperatureControlHandler method loadChannel.

private synchronized void loadChannel() {
    List<Channel> newChannelList = new ArrayList<Channel>(1);
    if (currentChannelID != null) {
        newChannelList.add(ChannelBuilder.create(new ChannelUID(this.getThing().getUID(), currentChannelID), DsChannelTypeProvider.getItemType(currentChannelID)).withType(new ChannelTypeUID(BINDING_ID, currentChannelID)).build());
    }
    ThingBuilder thingBuilder = editThing();
    thingBuilder.withChannels(newChannelList);
    updateThing(thingBuilder.build());
    logger.debug("load channel: {} with item: {}", currentChannelID, DsChannelTypeProvider.getItemType(currentChannelID));
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList)

Aggregations

Channel (org.eclipse.smarthome.core.thing.Channel)36 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)16 ArrayList (java.util.ArrayList)8 Thing (org.eclipse.smarthome.core.thing.Thing)7 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)6 Nullable (org.eclipse.jdt.annotation.Nullable)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Item (org.eclipse.smarthome.core.items.Item)4 ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)4 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)4 List (java.util.List)3 Locale (java.util.Locale)3 NonNull (org.eclipse.jdt.annotation.NonNull)3 AstroChannelConfig (org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig)3 ItemChannelLinkRegistry (org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry)3 ProfileTypeUID (org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID)3 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2