Search in sources :

Example 1 with MochadX10Command

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

the class MochadX10CommandParser method parse.

/**
     * Parse the received message and create a corresponding MochadX10Command for it.
     * 
     * @param msg The message received from the Mochad X10 host
     * @return A MochadX10Command if parsing was successful, otherwise null
     */
public MochadX10Command parse(String msg) {
    String command = null;
    Matcher huc_matcher = HOUSEUNIT_COMMAND.matcher(msg);
    if (huc_matcher.matches()) {
        previousHouseCode = huc_matcher.group("houseCode").toLowerCase();
        previousUnitCode = huc_matcher.group("unitCode");
        try {
            command = huc_matcher.group("command");
        } catch (IllegalArgumentException e) {
        }
        if (command != null) {
            return parseCommand(new MochadX10Address(previousHouseCode, previousUnitCode), command);
        } else {
            return null;
        }
    }
    Matcher hc_matcher = HOUSE_COMMAND.matcher(msg);
    if (hc_matcher.matches()) {
        String houseCode = hc_matcher.group("houseCode").toLowerCase();
        if (houseCode.equals(previousHouseCode)) {
            return parseCommand(new MochadX10Address(previousHouseCode, previousUnitCode), hc_matcher.group("command"));
        }
    }
    return null;
}
Also used : Matcher(java.util.regex.Matcher) MochadX10Address(org.openhab.binding.mochadx10.commands.MochadX10Address)

Example 2 with MochadX10Command

use of org.openhab.binding.mochadx10.commands.MochadX10Command 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)2 MochadX10Address (org.openhab.binding.mochadx10.commands.MochadX10Address)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