Search in sources :

Example 1 with MochadX10DimCommand

use of org.openhab.binding.mochadx10.commands.MochadX10DimCommand in project openhab1-addons by openhab.

the class MochadX10CommandParser method parseCommand.

/**
     * Parse the command part of the received message.
     * 
     * @param address The X10 address of the command
     * @param commandString The string containing the X10 command
     * @return A MochadX10Command if parsing was successful, otherwise null
     */
private MochadX10Command parseCommand(MochadX10Address address, String commandString) {
    if (commandString != null) {
        String command = commandString.toLowerCase();
        Matcher matcher;
        if (command.equals("on")) {
            return new MochadX10OnCommand(eventPublisher, address);
        } else if (command.equals("off")) {
            return new MochadX10OffCommand(eventPublisher, address);
        } else if (command.contains("dim")) {
            matcher = DIM_PATTERN.matcher(command);
            if (matcher.matches()) {
                int level = matcher.group("value") == null ? -1 : Integer.parseInt(matcher.group("value"));
                return new MochadX10DimCommand(eventPublisher, address, level);
            }
        } else if (command.contains("bright")) {
            matcher = BRIGHT_PATTERN.matcher(command);
            if (matcher.matches()) {
                int level = matcher.group("value") == null ? -1 : Integer.parseInt(matcher.group("value"));
                return new MochadX10BrightCommand(eventPublisher, address, level);
            }
        }
    }
    return null;
}
Also used : MochadX10BrightCommand(org.openhab.binding.mochadx10.commands.MochadX10BrightCommand) MochadX10OffCommand(org.openhab.binding.mochadx10.commands.MochadX10OffCommand) Matcher(java.util.regex.Matcher) MochadX10DimCommand(org.openhab.binding.mochadx10.commands.MochadX10DimCommand) MochadX10OnCommand(org.openhab.binding.mochadx10.commands.MochadX10OnCommand)

Aggregations

Matcher (java.util.regex.Matcher)1 MochadX10BrightCommand (org.openhab.binding.mochadx10.commands.MochadX10BrightCommand)1 MochadX10DimCommand (org.openhab.binding.mochadx10.commands.MochadX10DimCommand)1 MochadX10OffCommand (org.openhab.binding.mochadx10.commands.MochadX10OffCommand)1 MochadX10OnCommand (org.openhab.binding.mochadx10.commands.MochadX10OnCommand)1