use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class LightwaveRfBindingFunctionalTest method testDimMessageSentByAndriodApp.
@Test
public void testDimMessageSentByAndriodApp() throws Exception {
String message = "030271,101,!R3D2FdP13|Living Room|Side Light 2 40%";
testReceivingACommandAndVerify(new DimmerItem("LivingRoom"), "room=3,device=2,type=DIMMER", message, new PercentType("41"));
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class LightwaveRfBindingFunctionalTest method testOutOnlyMessageReceived.
@Test
public void testOutOnlyMessageReceived() throws Exception {
String message = "030271,101,!R3D2FdP13|Living Room|Side Light 2 40%";
testReceivingACommandAndVerifyNoInteractions(new DimmerItem("LivingRoom"), ">room=3,device=2,type=DIMMER", message, new PercentType("41"));
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class OnkyoBinding method convertDeviceValueToOpenHabState.
/**
* Convert receiver value to OpenHAB state.
*
* @param itemType
* @param data
*
* @return
*/
private State convertDeviceValueToOpenHabState(Class<? extends Item> itemType, String data) {
State state = UnDefType.UNDEF;
try {
int index;
String s;
if (itemType == SwitchItem.class) {
index = Integer.parseInt(data.substring(3, 5), 16);
state = index == 0 ? OnOffType.OFF : OnOffType.ON;
} else if (itemType == NumberItem.class) {
index = Integer.parseInt(data.substring(3, 5), 16);
state = new DecimalType(index);
} else if (itemType == DimmerItem.class) {
index = Integer.parseInt(data.substring(3, 5), 16);
state = new PercentType(index);
} else if (itemType == RollershutterItem.class) {
index = Integer.parseInt(data.substring(3, 5), 16);
state = new PercentType(index);
} else if (itemType == StringItem.class) {
s = data.substring(3, data.length());
state = new StringType(s);
}
} catch (Exception e) {
logger.debug("Cannot convert value '{}' to data type {}", data, itemType);
}
return state;
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class PioneerAvrBinding method convertDeviceValueToOpenHabState.
/**
* Convert receiver value to OpenHAB state.
*
* @param itemType
* @param data
*
* @return
*/
private State convertDeviceValueToOpenHabState(Class<? extends Item> itemType, String data, IpControlCommand cmdType) {
State state = UnDefType.UNDEF;
try {
int index;
// cut off the leading response identifier to get the payload string
String payloadSubstring = data.substring(cmdType.getResponse().length());
// the selected source will then be set to "ON"
if (payloadSubstring.length() == 0) {
payloadSubstring = "1";
}
// special case for display info query: convert to human readable string
if (cmdType.getCommandRef() == IpControlCommandRef.DISPLAY_INFO_QUERY) {
IpControlDisplayInformation displayInfo = new IpControlDisplayInformation(payloadSubstring);
payloadSubstring = displayInfo.getInfoText();
logger.debug("DisplayInfo: converted value '{}' to string '{}'", data, payloadSubstring);
}
if (itemType == SwitchItem.class) {
index = Integer.parseInt(payloadSubstring);
// according to Spec: 0=ON, 1=OFF!
state = (index == 0) ? OnOffType.ON : OnOffType.OFF;
} else if (itemType == DimmerItem.class) {
if (cmdType.getCommandRef().getCommand() == IpControlCommandRef.VOLUME_QUERY.getCommand() || cmdType.getCommandRef().getCommand() == IpControlCommandRef.VOLUME_SET.getCommand()) {
index = convertVolumeToPercent(Integer.parseInt(payloadSubstring));
} else {
index = Integer.parseInt(payloadSubstring);
}
state = new PercentType(index);
} else if (itemType == NumberItem.class) {
index = Integer.parseInt(payloadSubstring);
state = new DecimalType(index);
} else if (itemType == RollershutterItem.class) {
index = Integer.parseInt(payloadSubstring);
state = new PercentType(index);
} else if (itemType == StringItem.class) {
state = new StringType(payloadSubstring);
}
} catch (Exception e) {
logger.debug("Cannot convert value '{}' to data type {}", data, itemType);
}
return state;
}
use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.
the class PlexConnector method getProgressCommand.
private String getProgressCommand(PlexBindingConfig config, Command command) {
PlexSession session = getSessionByMachineId(config.getMachineIdentifier());
String url = null;
if (session != null) {
int offset = 0;
if (command.getClass().equals(PercentType.class)) {
PercentType percent = (PercentType) command;
offset = new BigDecimal(session.getDuration()).multiply(percent.toBigDecimal().divide(new BigDecimal("100"), new MathContext(5, RoundingMode.HALF_UP))).intValue();
offset = Math.max(0, offset);
offset = Math.min(session.getDuration(), offset);
url = String.format("playback/seekTo?offset=%d", offset);
} else if (command.getClass().equals(IncreaseDecreaseType.class)) {
if (command.equals(IncreaseDecreaseType.DECREASE)) {
url = PlexProperty.STEP_BACK.getName();
} else {
url = PlexProperty.STEP_FORWARD.getName();
}
}
}
return url;
}
Aggregations