Java Code Examples for org.eclipse.smarthome.core.thing.ChannelUID#getId()

The following examples show how to use org.eclipse.smarthome.core.thing.ChannelUID#getId() . 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: IpCameraGroupHandler.java    From IpCamera with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    if (!"REFRESH".equals(command.toString())) {
        switch (channelUID.getId()) {
            case CHANNEL_START_STREAM:
                if ("ON".equals(command.toString())) {
                    logger.info("Starting HLS generation for all cameras in a group.");
                    hlsTurnedOn = true;
                    for (IpCameraHandler handler : cameraOrder) {
                        String channelPrefix = "ipcamera:" + handler.getThing().getThingTypeUID() + ":"
                                + handler.getThing().getUID().getId() + ":";

                        handler.handleCommand(new ChannelUID(channelPrefix + CHANNEL_START_STREAM),
                                OnOffType.valueOf("ON"));
                    }
                } else {
                    // do we turn all off or do we remember the state before we turned them all on?
                    hlsTurnedOn = false;
                }
        }
    }
}
 
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: ColorThingHandler.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_R:
            currentValues.set(0, value);
            break;
        case CHANNEL_BRIGHTNESS_G:
            currentValues.set(1, value);
            break;
        case CHANNEL_BRIGHTNESS_B:
            currentValues.set(2, value);
            break;
        default:
            logger.debug("don't know how to handle {} in RGB type", channelUID.getId());
            return;
    }
    updateCurrentColor();
    updateState(new ChannelUID(this.thing.getUID(), CHANNEL_COLOR), currentColor);
    logger.trace("received update {} in channel {}, result is {}", value, channelUID, currentColor);
}
 
Example 4
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 5
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 6
Source File: TradfriPlugHandler.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_POWER:
                if (command instanceof OnOffType) {
                    setState(((OnOffType) command));
                } else {
                    logger.debug("Cannot handle command '{}' for channel '{}'", command, CHANNEL_POWER);
                }
                break;
            default:
                logger.error("Unknown channel UID {}", channelUID);
        }
    }
}
 
Example 7
Source File: DoorBirdHandler.java    From IpCamera with Eclipse Public License 2.0 5 votes vote down vote up
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command.toString() == "REFRESH") {
        return;
    } // end of "REFRESH"
    switch (channelUID.getId()) {
        case CHANNEL_ACTIVATE_ALARM_OUTPUT:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/bha-api/open-door.cgi");
            }
            return;
        case CHANNEL_ACTIVATE_ALARM_OUTPUT2:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/bha-api/open-door.cgi?r=2");
            }
            return;
        case CHANNEL_EXTERNAL_LIGHT:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/bha-api/light-on.cgi");
            }
            return;
        case CHANNEL_FFMPEG_MOTION_CONTROL:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.motionAlarmEnabled = true;
            } else if ("OFF".equals(command.toString()) || "0".equals(command.toString())) {
                ipCameraHandler.motionAlarmEnabled = false;
                ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
            } else {
                ipCameraHandler.motionAlarmEnabled = true;
                ipCameraHandler.motionThreshold = Double.valueOf(command.toString());
                ipCameraHandler.motionThreshold = ipCameraHandler.motionThreshold / 10000;
            }
            ipCameraHandler.setupFfmpegFormat("RTSPHELPER");
            return;
    }
}
 
Example 8
Source File: ChannelDTO.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public ChannelDTO(ChannelUID uid, String channelTypeUID, String itemType, ChannelKind kind, String label,
        String description, Map<String, String> properties, Configuration configuration, Set<String> defaultTags) {
    this.uid = uid.toString();
    this.id = uid.getId();
    this.channelTypeUID = channelTypeUID;
    this.itemType = itemType;
    this.label = label;
    this.description = description;
    this.properties = properties;
    this.configuration = toMap(configuration);
    this.defaultTags = new HashSet<>(defaultTags);
    this.kind = kind.toString();
}
 
Example 9
Source File: DmxBridgeHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    switch (channelUID.getId()) {
        case CHANNEL_MUTE:
            if (command instanceof OnOffType) {
                isMuted = ((OnOffType) command).equals(OnOffType.ON);
            } else {
                logger.debug("command {} not supported in channel {}:mute", command.getClass(),
                        this.thing.getUID());
            }
            break;
        default:
            logger.warn("Channel {} not supported in bridge {}", channelUID.getId(), this.thing.getUID());
    }
}
 
Example 10
Source File: HikvisionHandler.java    From IpCamera with Eclipse Public License 2.0 4 votes vote down vote up
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command.toString() == "REFRESH") {
        switch (channelUID.getId()) {
            case CHANNEL_ENABLE_AUDIO_ALARM:
                ipCameraHandler.sendHttpGET("/ISAPI/Smart/AudioDetection/channels/" + nvrChannel + "01");
                return;
            case CHANNEL_ENABLE_LINE_CROSSING_ALARM:
                ipCameraHandler.sendHttpGET("/ISAPI/Smart/LineDetection/" + nvrChannel + "01");
                return;
            case CHANNEL_ENABLE_FIELD_DETECTION_ALARM:
                ipCameraHandler.logger.debug("FieldDetection command");
                ipCameraHandler.sendHttpGET("/ISAPI/Smart/FieldDetection/" + nvrChannel + "01");
                return;
            case CHANNEL_ENABLE_MOTION_ALARM:
                ipCameraHandler
                        .sendHttpGET("/ISAPI/System/Video/inputs/channels/" + nvrChannel + "01/motionDetection");
                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_ENABLE_AUDIO_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.hikChangeSetting("/ISAPI/Smart/AudioDetection/channels/" + nvrChannel + "01",
                        "<enabled>false</enabled>", "<enabled>true</enabled>");
            } else {
                ipCameraHandler.hikChangeSetting("/ISAPI/Smart/AudioDetection/channels/" + nvrChannel + "01",
                        "<enabled>true</enabled>", "<enabled>false</enabled>");
            }
            return;
        case CHANNEL_ENABLE_LINE_CROSSING_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.hikChangeSetting("/ISAPI/Smart/LineDetection/" + nvrChannel + "01",
                        "<enabled>false</enabled>", "<enabled>true</enabled>");
            } else {
                ipCameraHandler.hikChangeSetting("/ISAPI/Smart/LineDetection/" + nvrChannel + "01",
                        "<enabled>true</enabled>", "<enabled>false</enabled>");
            }
            return;
        case CHANNEL_ENABLE_MOTION_ALARM:
            if ("ON".equals(command.toString())) {

                ipCameraHandler.hikChangeSetting(
                        "/ISAPI/System/Video/inputs/channels/" + nvrChannel + "01/motionDetection",
                        "<enabled>false</enabled>", "<enabled>true</enabled>");
            } else {
                ipCameraHandler.hikChangeSetting(
                        "/ISAPI/System/Video/inputs/channels/" + nvrChannel + "01/motionDetection",
                        "<enabled>true</enabled>", "<enabled>false</enabled>");
            }
            return;
        case CHANNEL_ENABLE_FIELD_DETECTION_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.hikChangeSetting("/ISAPI/Smart/FieldDetection/" + nvrChannel + "01",
                        "<enabled>false</enabled>", "<enabled>true</enabled>");
            } else {
                ipCameraHandler.hikChangeSetting("/ISAPI/Smart/FieldDetection/" + nvrChannel + "01",
                        "<enabled>true</enabled>", "<enabled>false</enabled>");
            }
            return;
        case CHANNEL_ACTIVATE_ALARM_OUTPUT:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.hikSendXml("/ISAPI/System/IO/outputs/" + nvrChannel + "/trigger",
                        "<IOPortData version=\"1.0\" xmlns=\"http://www.hikvision.com/ver10/XMLSchema\">\r\n    <outputState>high</outputState>\r\n</IOPortData>\r\n");
            } else {
                ipCameraHandler.hikSendXml("/ISAPI/System/IO/outputs/" + nvrChannel + "/trigger",
                        "<IOPortData version=\"1.0\" xmlns=\"http://www.hikvision.com/ver10/XMLSchema\">\r\n    <outputState>low</outputState>\r\n</IOPortData>\r\n");
            }
            return;
        case CHANNEL_FFMPEG_MOTION_CONTROL:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.motionAlarmEnabled = true;
            } else if ("OFF".equals(command.toString()) || "0".equals(command.toString())) {
                ipCameraHandler.motionAlarmEnabled = false;
                ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
            } else {
                ipCameraHandler.motionAlarmEnabled = true;
                ipCameraHandler.motionThreshold = Double.valueOf(command.toString());
                ipCameraHandler.motionThreshold = ipCameraHandler.motionThreshold / 10000;
            }
            ipCameraHandler.setupFfmpegFormat("RTSPHELPER");
            return;
    }
}
 
Example 11
Source File: InstarHandler.java    From IpCamera with Eclipse Public License 2.0 4 votes vote down vote up
public void handleCommand(ChannelUID channelUID, Command command) {
    if (command.toString() == "REFRESH") {
        switch (channelUID.getId()) {
            case CHANNEL_MOTION_ALARM:
                if (ipCameraHandler.serverPort > 0) {
                    ipCameraHandler.logger.info("Setting up the Alarm Server settings in the camera now");
                    ipCameraHandler.sendHttpGET(
                            "/param.cgi?cmd=setmdalarm&-aname=server2&-switch=on&-interval=2&cmd=setalarmserverattr&-as_index=3&-as_server="
                                    + ipCameraHandler.hostIp + "&-as_port=" + ipCameraHandler.serverPort
                                    + "&-as_path=/instar&-as_queryattr1=&-as_queryval1=&-as_queryattr2=&-as_queryval2=&-as_queryattr3=&-as_queryval3=&-as_activequery=1&-as_auth=0&-as_query1=0&-as_query2=0&-as_query3=0");
                    return;
                }
        }
        return;
    } // end of "REFRESH"
    switch (channelUID.getId()) {
        case CHANNEL_THRESHOLD_AUDIO_ALARM:
            int value = Math.round(Float.valueOf(command.toString()));
            if (value == 0) {
                ipCameraHandler.sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=0");
            } else {
                ipCameraHandler.sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=1");
                ipCameraHandler
                        .sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=1&-aa_value="
                                + command.toString());
            }
            return;
        case CHANNEL_ENABLE_AUDIO_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=1");
            } else {
                ipCameraHandler.sendHttpGET("/cgi-bin/hi3510/param.cgi?cmd=setaudioalarmattr&-aa_enable=0");
            }
            return;
        case CHANNEL_ENABLE_MOTION_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET(
                        "/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=1&-name=1&cmd=setmdattr&-enable=1&-name=2&cmd=setmdattr&-enable=1&-name=3&cmd=setmdattr&-enable=1&-name=4");
            } else {
                ipCameraHandler.sendHttpGET(
                        "/cgi-bin/hi3510/param.cgi?cmd=setmdattr&-enable=0&-name=1&cmd=setmdattr&-enable=0&-name=2&cmd=setmdattr&-enable=0&-name=3&cmd=setmdattr&-enable=0&-name=4");
            }
            return;
        case CHANNEL_TEXT_OVERLAY:
            String text = encodeSpecialChars(command.toString());
            if ("".contentEquals(text)) {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setoverlayattr&-region=1&-show=0");
            } else {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setoverlayattr&-region=1&-show=1&-name=" + text);
            }
            return;
        case CHANNEL_AUTO_LED:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setinfrared&-infraredstat=auto");
            } else {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setinfrared&-infraredstat=close");
            }
            return;
        case CHANNEL_ENABLE_PIR_ALARM:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setpirattr&-pir_enable=1");
            } else {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setpirattr&-pir_enable=0");
            }
            return;
        case CHANNEL_ENABLE_EXTERNAL_ALARM_INPUT:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setioattr&-io_enable=1");
            } else {
                ipCameraHandler.sendHttpGET("/param.cgi?cmd=setioattr&-io_enable=0");
            }
            return;
        case CHANNEL_FFMPEG_MOTION_CONTROL:
            if ("ON".equals(command.toString())) {
                ipCameraHandler.motionAlarmEnabled = true;
            } else if ("OFF".equals(command.toString()) || "0".equals(command.toString())) {
                ipCameraHandler.motionAlarmEnabled = false;
                ipCameraHandler.noMotionDetected(CHANNEL_MOTION_ALARM);
            } else {
                ipCameraHandler.motionAlarmEnabled = true;
                ipCameraHandler.motionThreshold = Double.valueOf(command.toString());
                ipCameraHandler.motionThreshold = ipCameraHandler.motionThreshold / 10000;
            }
            ipCameraHandler.setupFfmpegFormat("RTSPHELPER");
            return;
    }
}
 
Example 12
Source File: FSInternetRadioHandler.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void handleCommand(final ChannelUID channelUID, final Command command) {
    if (!radio.isLoggedIn()) {
        // connection to radio is not initialized, log ignored command and set status, if it is not already offline
        logger.debug("Ignoring command {} = {} because device is offline.", channelUID.getId(), command);
        if (ThingStatus.ONLINE.equals(getThing().getStatus())) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
        }
        return;
    }
    try {
        switch (channelUID.getId()) {
            case CHANNEL_POWER:
                if (OnOffType.ON.equals(command)) {
                    radio.setPower(true);
                } else if (OnOffType.OFF.equals(command)) {
                    radio.setPower(false);
                }
                // now all items should be updated! (wait some seconds so that text items are up-to-date)
                scheduler.schedule(updateRunnable, 4, SECONDS);
                break;
            case CHANNEL_VOLUME_PERCENT:
                if (IncreaseDecreaseType.INCREASE.equals(command) || UpDownType.UP.equals(command)) {
                    radio.increaseVolumeAbsolute();
                } else if (IncreaseDecreaseType.DECREASE.equals(command) || UpDownType.DOWN.equals(command)) {
                    radio.decreaseVolumeAbsolute();
                } else if (command instanceof PercentType) {
                    radio.setVolumePercent(((PercentType) command).intValue());
                }
                // absolute value should also be updated now, so let's update all items
                scheduler.schedule(updateRunnable, 1, SECONDS);
                break;
            case CHANNEL_VOLUME_ABSOLUTE:
                if (IncreaseDecreaseType.INCREASE.equals(command) || UpDownType.UP.equals(command)) {
                    radio.increaseVolumeAbsolute();
                } else if (IncreaseDecreaseType.DECREASE.equals(command) || UpDownType.DOWN.equals(command)) {
                    radio.decreaseVolumeAbsolute();
                } else if (command instanceof DecimalType) {
                    radio.setVolumeAbsolute(((DecimalType) command).intValue());
                }
                // percent value should also be updated now, so let's update all items
                scheduler.schedule(updateRunnable, 1, SECONDS);
                break;
            case CHANNEL_MODE:
                if (command instanceof DecimalType) {
                    radio.setMode(((DecimalType) command).intValue());
                }
                break;
            case CHANNEL_PRESET:
                if (command instanceof DecimalType) {
                    radio.setPreset(((DecimalType) command).intValue());
                }
                break;
            case CHANNEL_MUTE:
                if (command instanceof OnOffType) {
                    radio.setMuted(OnOffType.ON.equals(command));
                }
                break;
            default:
                logger.warn("Ignoring unknown command: {}", command);
        }
        // make sure that device state is online
        updateStatus(ThingStatus.ONLINE);
    } catch (Exception e) {
        // set device state to offline
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
    }
}
 
Example 13
Source File: DimmerThingHandler.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
    logger.trace("received command {} in channel {}", command, channelUID);
    ValueSet targetValueSet = new ValueSet(fadeTime, -1);
    switch (channelUID.getId()) {
        case CHANNEL_BRIGHTNESS: {
            if (command instanceof PercentType || command instanceof DecimalType) {
                PercentType brightness = (command instanceof PercentType) ? (PercentType) command
                        : Util.toPercentValue(((DecimalType) command).intValue());
                logger.trace("adding fade to channels in thing {}", this.thing.getUID());
                targetValueSet.addValue(brightness);
            } else if (command instanceof OnOffType) {
                logger.trace("adding {} fade to channels in thing {}", command, this.thing.getUID());
                if (((OnOffType) command) == OnOffType.ON) {
                    targetValueSet = turnOnValue;
                } else {
                    if (dynamicTurnOnValue) {
                        turnOnValue.clear();
                        for (DmxChannel channel : channels) {
                            turnOnValue.addValue(channel.getValue());
                        }
                        logger.trace("stored channel values fort next turn-on");
                    }
                    targetValueSet = turnOffValue;
                }
            } else if (command instanceof IncreaseDecreaseType) {
                if (isDimming && ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)) {
                    logger.trace("stopping fade in thing {}", this.thing.getUID());
                    channels.forEach(DmxChannel::clearAction);
                    isDimming = false;
                    return;
                } else {
                    logger.trace("starting {} fade in thing {}", command, this.thing.getUID());
                    targetValueSet = ((IncreaseDecreaseType) command).equals(IncreaseDecreaseType.INCREASE)
                            ? turnOnValue
                            : turnOffValue;
                    targetValueSet.setFadeTime(dimTime);
                    isDimming = true;
                }
            } else if (command instanceof RefreshType) {
                logger.trace("sending update on refresh to channel {}:brightness", this.thing.getUID());
                currentBrightness = Util.toPercentValue(channels.get(0).getValue());
                updateState(channelUID, currentBrightness);
                return;
            } else {
                logger.debug("command {} not supported in channel {}:brightness", command.getClass(),
                        this.thing.getUID());
                return;
            }
            break;
        }
        default:
            logger.debug("channel {} not supported in thing {}", channelUID.getId(), this.thing.getUID());
            return;
    }
    final ValueSet valueSet = targetValueSet;
    IntStream.range(0, channels.size()).forEach(i -> {
        channels.get(i).setChannelAction(new FadeAction(valueSet.getFadeTime(), channels.get(i).getValue(),
                valueSet.getValue(i), valueSet.getHoldTime()));
    });
}