org.eclipse.smarthome.core.thing.ChannelUID Java Examples

The following examples show how to use org.eclipse.smarthome.core.thing.ChannelUID. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DigitalIOThingHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command instanceof OnOffType) {
        Integer ioChannel = Integer.valueOf(channelUID.getId().substring(channelUID.getId().length() - 1));
        if (ioChannel != null && ioChannel < ((AbstractDigitalOwDevice) sensors.get(0)).getChannelCount()) {
            Bridge bridge = getBridge();
            if (bridge != null) {
                OwBaseBridgeHandler bridgeHandler = (OwBaseBridgeHandler) bridge.getHandler();
                if (bridgeHandler != null) {
                    if (!((AbstractDigitalOwDevice) sensors.get(0)).writeChannel(bridgeHandler, ioChannel,
                            command)) {
                        logger.debug("writing to channel {} in thing {} not permitted (input channel)", channelUID,
                                this.thing.getUID());
                    }
                } else {
                    logger.warn("bridge handler not found");
                }
            } else {
                logger.warn("bridge not found");
            }
        }
    }
    super.handleCommand(channelUID, command);
}
 
Example #2
Source File: HttpOnlyHandler.java    From IpCamera with Eclipse Public License 2.0 6 votes vote down vote up
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command.toString() == "REFRESH") {
        switch (channelUID.getId()) {
            case CHANNEL_ENABLE_AUDIO_ALARM:
                return;
        }
        return; // Return as we have handled the refresh command above and don't need to
                // continue further.
    } // end of "REFRESH"
    switch (channelUID.getId()) {
        case CHANNEL_THRESHOLD_AUDIO_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.audioAlarmEnabled = true;
            } else if ("OFF".equals(command.toString()) || "0".equals(command.toString())) {
                ipCameraHandler.audioAlarmEnabled = false;
            } else {
                ipCameraHandler.audioAlarmEnabled = true;
                ipCameraHandler.audioThreshold = Integer.valueOf(command.toString());
            }
            ipCameraHandler.setupFfmpegFormat("RTSPHELPER");
            return;
    }
}
 
Example #3
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void handleRadioStationCommand(Command command, ChannelUID channelUID) throws IOException {
    if (command instanceof RefreshType) {
        updateState(channelUID, new DecimalType(currentRadioStation));
    }
    if (command instanceof DecimalType) {
        currentRadioStation = ((DecimalType) command).intValue();
        String radioCommand = "radio:fm?contentId=" + currentRadioStation;

        for (int i = 1; i <= 4; i++) {
            String input = input_zone.get(i);
            if (input != null && input.startsWith("radio:fm")) {
                connection.setInput(radioCommand, i);
            }
        }
    }
}
 
Example #4
Source File: TradfriLightHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (active) {
        if (command instanceof RefreshType) {
            logger.debug("Refreshing channel {}", channelUID);
            coapClient.asyncGet(this);
            return;
        }

        switch (channelUID.getId()) {
            case CHANNEL_BRIGHTNESS:
                handleBrightnessCommand(command);
                break;
            case CHANNEL_COLOR_TEMPERATURE:
                handleColorTemperatureCommand(command);
                break;
            case CHANNEL_COLOR:
                handleColorCommand(command);
                break;
            default:
                logger.error("Unknown channel UID {}", channelUID);
        }
    }
}
 
Example #5
Source File: FSInternetRadioHandlerJavaTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Verify the playInfoText channel is updated.
 */
@Test
public void playInfoTextChannelUpdated() {
    String playInfoTextChannelID = FSInternetRadioBindingConstants.CHANNEL_PLAY_INFO_TEXT;
    String acceptedItemType = acceptedItemTypes.get(playInfoTextChannelID);
    createChannel(DEFAULT_THING_UID, playInfoTextChannelID, acceptedItemType);

    Thing radioThing = initializeRadioThingWithMockedHandler(DEFAULT_COMPLETE_CONFIGURATION);
    testRadioThingConsideringConfiguration(radioThing);

    turnTheRadioOn(radioThing);
    ChannelUID playInfoTextChannelUID = getChannelUID(radioThing,
            FSInternetRadioBindingConstants.CHANNEL_PLAY_INFO_TEXT);
    initializeItem(playInfoTextChannelUID, DEFAULT_TEST_ITEM_NAME, acceptedItemType);

    waitForAssert(() -> {
        verifyOnlineStatusIsSet();
    });
}
 
Example #6
Source File: ChannelItemProvider.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void afterRemoving(Item element) {
    if (!initialized) {
        return;
    }
    // check, if it is our own item
    for (Item item : items.values()) {
        if (item == element) {
            return;
        }
    }
    // it is from some other provider, so create one ourselves if needed
    for (ChannelUID uid : linkRegistry.getBoundChannels(element.getName())) {
        for (ItemChannelLink link : linkRegistry.getLinks(uid)) {
            if (itemRegistry.get(link.getItemName()) == null) {
                createItemForLink(link);
            }
        }
    }
}
 
Example #7
Source File: ChaserThingHandlerTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void holdInfiniteChaser() {
    initializeTestBridge();
    thingProperties.put(CONFIG_CHASER_STEPS, TEST_STEPS_INFINITE);
    initialize();

    long currentTime = System.currentTimeMillis();

    chaserThingHandler.handleCommand(new ChannelUID(chaserThing.getUID(), CHANNEL_SWITCH), OnOffType.ON);
    // step I
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(100))));
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(100))));
    // step II (holds forever)
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 1000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(200))));
    currentTime = dmxBridgeHandler.calcBuffer(currentTime, 2000);
    waitForAssert(() -> assertThat(dmxBridgeHandler.getDmxChannelValue(100), is(equalTo(200))));
}
 
Example #8
Source File: FSInternetRadioHandlerJavaTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private Item initializeItem(ChannelUID channelUID, String itemName, String acceptedItemType) {

        Item item = null;

        switch (acceptedItemType) {
            case "Number":
                item = new NumberItem(itemName);
                break;

            case "String":
                item = new StringItem(itemName);
                break;

            case "Switch":
                item = new SwitchItem(itemName);
                break;

            case "Dimmer":
                item = new DimmerItem(itemName);
                break;
        }

        return item;
    }
 
Example #9
Source File: DmxChannel.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * remove listener from channel
 *
 * @param thingChannel the channel that shall no longer receive updates
 */
public void removeListener(ChannelUID thingChannel) {
    boolean foundListener = false;
    if (onOffListeners.containsKey(thingChannel)) {
        onOffListeners.remove(thingChannel);
        foundListener = true;
        logger.debug("removing ONOFF listener {} from DMX channel {}", thingChannel, this);
    }
    if (valueListeners.containsKey(thingChannel)) {
        valueListeners.remove(thingChannel);
        foundListener = true;
        logger.debug("removing VALUE listener {} from DMX channel {}", thingChannel, this);
    }
    if (actionListener != null && actionListener.getKey().equals(thingChannel)) {
        actionListener = null;
        foundListener = true;
        logger.debug("removing ACTION listener {} from DMX channel {}", thingChannel, this);
    }
    if (!foundListener) {
        logger.trace("listener {} not found in DMX channel {}", thingChannel, this);
    }
}
 
Example #10
Source File: PropertyUtils.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns the state of the channel.
 */
public static State getState(ChannelUID channelUID, AstroChannelConfig config, Object instance) throws Exception {
    Object value = getPropertyValue(channelUID, instance);
    if (value == null) {
        return UnDefType.UNDEF;
    } else if (value instanceof State) {
        return (State) value;
    } else if (value instanceof Calendar) {
        Calendar cal = (Calendar) value;
        GregorianCalendar gregorianCal = (GregorianCalendar) DateTimeUtils.applyConfig(cal, config);
        cal.setTimeZone(TimeZone.getTimeZone(timeZoneProvider.getTimeZone()));
        ZonedDateTime zoned = gregorianCal.toZonedDateTime().withFixedOffsetZone();
        return new DateTimeType(zoned);
    } else if (value instanceof Number) {
        BigDecimal decimalValue = new BigDecimal(value.toString()).setScale(2, RoundingMode.HALF_UP);
        return new DecimalType(decimalValue);
    } else if (value instanceof String || value instanceof Enum) {
        return new StringType(value.toString());
    } else {
        throw new IllegalStateException("Unsupported value type " + value.getClass().getSimpleName());
    }
}
 
Example #11
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
public void handleMuteCommand(Command command, ChannelUID channelUID, int zone) throws IOException {
    if (command instanceof RefreshType) {
        try {
            logger.debug("handleMuteCommand RefreshType {}", zone);
            SonyAudioConnection.SonyAudioVolume result = volumeCache[zone].getValue();
            if (result != null) {
                updateState(channelUID, result.mute ? OnOffType.ON : OnOffType.OFF);
            }
        } catch (CompletionException ex) {
            throw new IOException(ex.getCause());
        }
    }
    if (command instanceof OnOffType) {
        logger.debug("handleMuteCommand set {} {}", zone, command);
        connection.setMute(((OnOffType) command) == OnOffType.ON, zone);
    }
}
 
Example #12
Source File: ConnectedBluetoothHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
protected void activateChannel(@Nullable BluetoothCharacteristic characteristic, ChannelTypeUID channelTypeUID,
        @Nullable String name) {
    if (characteristic != null) {
        String channelId = name != null ? name : characteristic.getGattCharacteristic().name();
        if (channelId == null) {
            // use the type id as a fallback
            channelId = channelTypeUID.getId();
        }
        if (getThing().getChannel(channelId) == null) {
            // the channel does not exist yet, so let's add it
            ThingBuilder updatedThing = editThing();
            Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), channelId), "Number")
                    .withType(channelTypeUID).build();
            updatedThing.withChannel(channel);
            updateThing(updatedThing.build());
            logger.debug("Added channel '{}' to Thing '{}'", channelId, getThing().getUID());
        }
        deviceCharacteristics.add(characteristic);
        device.enableNotifications(characteristic);
        if (isLinked(channelId)) {
            device.readCharacteristic(characteristic);
        }
    } else {
        logger.debug("Characteristic is null - not activating any channel.");
    }
}
 
Example #13
Source File: TunableWhiteThingHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void updateChannelValue(ChannelUID channelUID, int value) {
    updateState(channelUID, Util.toPercentValue(value));
    switch (channelUID.getId()) {
        case CHANNEL_BRIGHTNESS_CW:
            currentValues.set(0, value);
            break;
        case CHANNEL_BRIGHTNESS_WW:
            currentValues.set(1, value);
            break;
        default:
            logger.debug("don't know how to handle {} in tunable white type", channelUID.getId());
            return;
    }

    updateCurrentBrightnessAndTemperature();
    updateState(new ChannelUID(this.thing.getUID(), CHANNEL_BRIGHTNESS), currentBrightness);
    updateState(new ChannelUID(this.thing.getUID(), CHANNEL_COLOR_TEMPERATURE), currentColorTemperature);
    logger.trace("received update {} for channel {}, resulting in b={}, ct={}", value, channelUID,
            currentBrightness, currentColorTemperature);
}
 
Example #14
Source File: GenericWemoLightOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType,
        WemoHttpCall wemoHttpCaller) {
    Configuration configuration = new Configuration();
    configuration.put(WemoBindingConstants.DEVICE_ID, WEMO_LIGHT_ID);

    ThingUID thingUID = new ThingUID(thingTypeUID, TEST_THING_ID);

    ChannelUID channelUID = new ChannelUID(thingUID, channelID);
    Channel channel = ChannelBuilder.create(channelUID, itemAcceptedType).withType(DEFAULT_CHANNEL_TYPE_UID)
            .withKind(ChannelKind.STATE).withLabel("label").build();
    ThingUID bridgeUID = new ThingUID(BRIDGE_TYPE_UID, WEMO_BRIDGE_ID);

    thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(configuration).withChannel(channel)
            .withBridge(bridgeUID).build();

    managedThingProvider.add(thing);

    ThingHandler handler = thing.getHandler();
    if (handler != null) {
        AbstractWemoHandler h = (AbstractWemoHandler) handler;
        h.setWemoHttpCaller(wemoHttpCaller);
    }

    return thing;
}
 
Example #15
Source File: BindingBaseClassesOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void initialize() {
    ThingBuilder thingBuilder = editThing();
    thingBuilder
            .withChannel(ChannelBuilder.create(new ChannelUID("bindingId:type:thingId:1"), "String").build());
    updateThing(thingBuilder.build());
    updateStatus(ThingStatus.ONLINE);
}
 
Example #16
Source File: BaseThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns whether at least one item is linked for the given UID of the channel.
 *
 * @param channelUID UID of the channel (must not be null)
 * @return true if at least one item is linked, false otherwise
 */
protected boolean isLinked(ChannelUID channelUID) {
    if (callback != null) {
        return callback.isChannelLinked(channelUID);
    } else {
        logger.warn(
                "Handler {} of thing {} tried checking if channel {} is linked although the handler was already disposed.",
                this.getClass().getSimpleName(), channelUID.getThingUID(), channelUID.getId());
        return false;
    }
}
 
Example #17
Source File: BoseSoundTouchHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private List<Channel> getAllChannels() {
    List<Channel> allChannels = new ArrayList<>();
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_POWER), new ChannelTypeUID(BINDING_ID, CHANNEL_POWER)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_VOLUME), new ChannelTypeUID(BINDING_ID, CHANNEL_VOLUME)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_MUTE), new ChannelTypeUID(BINDING_ID, CHANNEL_MUTE)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_OPERATIONMODE), new ChannelTypeUID(BINDING_ID, "operationMode_BST_10_20_30")).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_PLAYER_CONTROL), new ChannelTypeUID(BINDING_ID, CHANNEL_PLAYER_CONTROL)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_PRESET), new ChannelTypeUID(BINDING_ID, CHANNEL_PRESET)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_BASS), new ChannelTypeUID(BINDING_ID, CHANNEL_BASS)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_RATEENABLED), new ChannelTypeUID(BINDING_ID, CHANNEL_RATEENABLED)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_SKIPENABLED), new ChannelTypeUID(BINDING_ID, CHANNEL_SKIPENABLED)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_SKIPPREVIOUSENABLED), new ChannelTypeUID(BINDING_ID, CHANNEL_SKIPPREVIOUSENABLED)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_SAVE_AS_PRESET), new ChannelTypeUID(BINDING_ID, CHANNEL_SAVE_AS_PRESET)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_KEY_CODE), new ChannelTypeUID(BINDING_ID, CHANNEL_KEY_CODE)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_ALBUM), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_ALBUM)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_ARTWORK), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_ARTWORK)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_ARTIST), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_ARTIST)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_DESCRIPTION), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_DESCRIPTION)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_GENRE), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_GENRE)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_ITEMNAME), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_ITEMNAME)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_STATIONLOCATION), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_STATIONLOCATION)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_STATIONNAME), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_STATIONNAME)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOWPLAYING_TRACK), new ChannelTypeUID(BINDING_ID, CHANNEL_NOWPLAYING_TRACK)).build());
    allChannels.add(getCallback().createChannelBuilder(new ChannelUID(getThing().getUID(), CHANNEL_NOTIFICATION_SOUND), new ChannelTypeUID(BINDING_ID, CHANNEL_NOTIFICATION_SOUND)).build());
    
    return allChannels;
}
 
Example #18
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelTypeUID channelTypeUID) {
    ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID);
    if (channelType == null) {
        throw new IllegalArgumentException(String.format("Channel type '%s' is not known", channelTypeUID));
    }
    return ThingFactoryHelper.createChannelBuilder(channelUID, channelType, configDescriptionRegistry);
}
 
Example #19
Source File: AbstractOpenWeatherMapHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates all channels of this handler from the latest OpenWeatherMap data retrieved.
 */
private void updateChannels() {
    for (Channel channel : getThing().getChannels()) {
        ChannelUID channelUID = channel.getUID();
        if (ChannelKind.STATE.equals(channel.getKind()) && channelUID.isInGroup() && channelUID.getGroupId() != null
                && isLinked(channelUID)) {
            updateChannel(channelUID);
        }
    }
}
 
Example #20
Source File: BaseThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void channelLinked(ChannelUID channelUID) {
    // can be overridden by subclasses
    // standard behavior is to refresh the linked channel,
    // so the newly linked items will receive a state update.
    handleCommand(channelUID, RefreshType.REFRESH);
}
 
Example #21
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void removed(Item element) {
    for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
        final Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing != null) {
            final Channel channel = thing.getChannel(channelUID.getId());
            if (channel != null) {
                ThingLinkManager.this.informHandlerAboutUnlinkedChannel(thing, channel);
            }
        }
    }
}
 
Example #22
Source File: AbstractMQTTThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (connection == null) {
        return;
    }

    final @Nullable ChannelState data = getChannelState(channelUID);

    if (data == null) {
        logger.warn("Channel {} not supported", channelUID.getId());
        if (command instanceof RefreshType) {
            updateState(channelUID.getId(), UnDefType.UNDEF);
        }
        return;
    }

    if (command instanceof RefreshType || data.isReadOnly()) {
        updateState(channelUID.getId(), data.getCache().getChannelState());
        return;
    }

    final CompletableFuture<@Nullable Void> future = data.publishValue(command);
    future.exceptionally(e -> {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getLocalizedMessage());
        return null;
    }).thenRun(() -> logger.debug("Successfully published value {} to topic {}", command, data.getStateTopic()));
}
 
Example #23
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void added(Item element) {
    for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
        final Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing != null) {
            final Channel channel = thing.getChannel(channelUID.getId());
            if (channel != null) {
                ThingLinkManager.this.informHandlerAboutLinkedChannel(thing, channel);
            }
        }
    }
}
 
Example #24
Source File: MagicDelayedOnlineHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (channelUID.getId().equals("number")) {
        if (command instanceof DecimalType) {
            DecimalType cmd = (DecimalType) command;
            int cmdInt = cmd.intValue();
            ThingStatus status = cmdInt > 0 ? ThingStatus.ONLINE : ThingStatus.OFFLINE;
            int waitTime = Math.abs(cmd.intValue());
            scheduler.schedule(() -> updateStatus(status), waitTime, TimeUnit.SECONDS);
        }
    }
}
 
Example #25
Source File: HomematicThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Checks whether the given list includes a channel with the given UID
 */
private static boolean containsChannel(List<Channel> channels, ChannelUID channelUID) {
    for (Channel channel : channels) {
        ChannelUID uid = channel.getUID();
        if (StringUtils.equals(channelUID.getGroupId(), uid.getGroupId())
                && StringUtils.equals(channelUID.getId(), uid.getId())) {
            return true;
        }
    }
    return false;
}
 
Example #26
Source File: SonyAudioHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public void handleSoundSettings(Command command, ChannelUID channelUID) throws IOException {
    if (command instanceof RefreshType) {
        logger.debug("handleSoundSettings RefreshType");
        Map<String, String> result = soundSettingsCache.getValue();
        if (result != null) {
            updateState(channelUID, new StringType(result.get("soundField")));
        }
    }
    if (command instanceof StringType) {
        logger.debug("handleSoundSettings set {} {}", command);
        connection.setSoundSettings("soundField", ((StringType) command).toString());
    }
}
 
Example #27
Source File: ThingRegistryImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Channel getChannel(ChannelUID channelUID) {
    ThingUID thingUID = channelUID.getThingUID();
    Thing thing = get(thingUID);
    if (thing != null) {
        return thing.getChannel(channelUID.getId());
    }
    return null;
}
 
Example #28
Source File: BaseThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Emits an event for the given channel.
 *
 * @param channelUID UID of the channel over which the event will be emitted
 * @param event Event to emit
 */
protected void triggerChannel(ChannelUID channelUID, String event) {
    synchronized (this) {
        if (this.callback != null) {
            this.callback.channelTriggered(this.getThing(), channelUID, event);
        } else {
            logger.warn(
                    "Handler {} of thing {} tried triggering channel {} although the handler was already disposed.",
                    this.getClass().getSimpleName(), channelUID.getThingUID(), channelUID.getId());
        }
    }
}
 
Example #29
Source File: OwBaseThingHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * add a channel during initialization
 *
 * @param thingBuilder ThingBuilder of the edited thing
 * @param channelId id of the channel
 * @param channelTypeUID ChannelTypeUID of the channel
 * @param configuration Configuration for the channel
 * @return existing or created channel
 */
protected Channel addChannelIfMissing(ThingBuilder thingBuilder, String channelId, ChannelTypeUID channelTypeUID,
        Configuration configuration) {
    Channel channel = thing.getChannel(channelId);
    if (channel == null) {
        channel = ChannelBuilder
                .create(new ChannelUID(thing.getUID(), channelId), ACCEPTED_ITEM_TYPES_MAP.get(channelId))
                .withType(channelTypeUID).withConfiguration(configuration).build();
        thingBuilder.withChannel(channel);
    }
    return channel;
}
 
Example #30
Source File: ItemChannelLinkOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatGetBoundChannelsReturnsChannel() {
    managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK);
    Set<ChannelUID> boundChannels = itemChannelLinkRegistry.getBoundChannels(ITEM);
    assertEquals(1, boundChannels.size());
    assertTrue(boundChannels.contains(ITEM_CHANNEL_LINK.getLinkedUID()));
}