use of org.openhab.binding.mochadx10.commands.MochadX10Address in project openhab1-addons by openhab.
the class MochadX10Binding method initializeBinding.
/**
* Initialize the binding. Connection to the Mochad X10 host is established and after that
* the receive thread is started.
*/
private void initializeBinding() {
previousX10Address = new MochadX10Address("a1");
connectToMochadX10Server();
receiveThread = new ReceiveThread(this);
receiveThread.start();
}
use of org.openhab.binding.mochadx10.commands.MochadX10Address 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;
}
use of org.openhab.binding.mochadx10.commands.MochadX10Address 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;
}
Aggregations