use of org.openhab.binding.insteonhub.internal.InsteonHubBindingConfig.BindingType in project openhab1-addons by openhab.
the class InsteonHubBinding method internalReceiveCommand.
@Override
protected void internalReceiveCommand(String itemName, Command command) {
// get configuration for this item
InsteonHubBindingConfig config = InsteonHubBindingConfigUtil.getConfigForItem(providers, itemName);
if (config == null) {
logger.error(BINDING_NAME + " received command for unknown item '" + itemName + "'");
return;
}
// parse info from config
BindingType type = config.getBindingType();
String hubId = config.getDeviceInfo().getHubId();
String deviceId = config.getDeviceInfo().getDeviceId();
// lookup proxy from this configuration
InsteonHubProxy proxy = proxies.get(hubId);
if (proxy == null) {
logger.error(BINDING_NAME + " received command for unknown hub id '" + hubId + "'");
return;
}
if (logger.isDebugEnabled()) {
logger.debug(BINDING_NAME + " processing command '" + command + "' of type '" + command.getClass().getSimpleName() + "' for item '" + itemName + "'");
}
try {
// process according to type
if (type == BindingType.SWITCH) {
// set value on or off
if (command instanceof OnOffType) {
proxy.setDevicePower(deviceId, command == OnOffType.ON);
}
} else if (type == BindingType.DIMMER) {
// INSTEON Dimmer supports Dimmer and RollerShutter types
if (command instanceof OnOffType) {
// ON or OFF => Set level to 255 or 0
int level = command == OnOffType.ON ? 255 : 0;
proxy.setDeviceLevel(deviceId, level);
} else if (command instanceof IncreaseDecreaseType) {
// Increase/Decrease => Incremental Brighten/Dim
InsteonHubAdjustmentType adjustmentType;
if (command == IncreaseDecreaseType.INCREASE) {
adjustmentType = InsteonHubAdjustmentType.BRIGHTEN;
} else {
adjustmentType = InsteonHubAdjustmentType.DIM;
}
if (setDimTimeout(itemName)) {
proxy.startDeviceAdjustment(deviceId, adjustmentType);
}
} else if (command instanceof UpDownType) {
// Up/Down => Start Brighten/Dim
InsteonHubAdjustmentType adjustmentType;
if (command == UpDownType.UP) {
adjustmentType = InsteonHubAdjustmentType.BRIGHTEN;
} else {
adjustmentType = InsteonHubAdjustmentType.DIM;
}
proxy.startDeviceAdjustment(deviceId, adjustmentType);
} else if (command instanceof StopMoveType) {
// Stop => Stop Brighten/Dim
if (command == StopMoveType.STOP) {
proxy.stopDeviceAdjustment(deviceId);
}
} else {
// set level from 0 to 100 percent value
byte percentByte = Byte.parseByte(command.toString());
float percent = percentByte * .01f;
int level = (int) (255 * percent);
proxy.setDeviceLevel(deviceId, level);
}
}
} catch (Throwable t) {
logger.error("Error processing command '" + command + "' for item '" + itemName + "'", t);
}
}
Aggregations