use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class IRtransGenericBindingProvider method getQualifiedCommands.
/**
* {@inheritDoc}
*/
@Override
public List<Command> getQualifiedCommands(String itemName, Command command) {
List<Command> commands = new ArrayList<Command>();
IRtransBindingConfig aConfig = (IRtransBindingConfig) bindingConfigs.get(itemName);
for (Command aCommand : aConfig.keySet()) {
if (aCommand == command) {
commands.add(aCommand);
} else {
if (aCommand instanceof DecimalType) {
commands.add(aCommand);
}
}
}
return commands;
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class JointSpaceBinding method updateItemState.
/**
* Polls the TV for the values specified in @see tvCommand and posts state
* update for @see itemName Currently only the following commands are
* available - "ambilight[...]" returning a HSBType state for the given
* ambilight pixel specified in [...] - "volume" returning a DecimalType -
* "volume.mute" returning 'On' or 'Off' - "source" returning a String with
* selected source (e.g. "hdmi1", "tv", etc)
*
* @param itemName
* @param tvCommand
*/
private void updateItemState(String itemName, String tvCommand) {
if (tvCommand.contains("ambilight")) {
String[] layer = command2LayerString(tvCommand);
HSBType state = new HSBType(getAmbilightColor(ip + ":" + port, layer));
eventPublisher.postUpdate(itemName, state);
} else if (tvCommand.contains("volume")) {
if (tvCommand.contains("mute")) {
eventPublisher.postUpdate(itemName, getTVVolume(ip + ":" + port).mute ? OnOffType.ON : OnOffType.OFF);
} else {
eventPublisher.postUpdate(itemName, new DecimalType(getTVVolume(ip + ":" + port).volume));
}
} else if (tvCommand.contains("source")) {
eventPublisher.postUpdate(itemName, new StringType(getSource(ip + ":" + port)));
} else {
logger.error("Could not parse item state\"" + tvCommand + "\" for polling");
return;
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class JointSpaceBinding method internalReceiveCommand.
/**
* @{inheritDoc Processes the commands and maps them to jointspace commands
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
if (itemName != null && !this.providers.isEmpty()) {
JointSpaceBindingProvider provider = this.providers.iterator().next();
if (provider == null) {
logger.warn("Doesn't find matching binding provider [itemName={}, command={}]", itemName, command);
return;
}
logger.debug("Received command (item='{}', state='{}', class='{}')", new Object[] { itemName, command.toString(), command.getClass().toString() });
String tvCommandString = null;
// first check if we can translate the command directly
tvCommandString = provider.getTVCommand(itemName, command.toString());
// if not try some special notations
if (tvCommandString == null) {
if (command instanceof HSBType) {
tvCommandString = provider.getTVCommand(itemName, "HSB");
} else if (command instanceof DecimalType) {
tvCommandString = provider.getTVCommand(itemName, "DEC");
}
if (tvCommandString == null) {
tvCommandString = provider.getTVCommand(itemName, "*");
}
}
if (tvCommandString == null) {
logger.warn("Unrecognized command \"{}\"", command.toString());
return;
}
if (tvCommandString.contains("key")) {
logger.debug("Found a Key command: " + tvCommandString);
String[] commandlist = tvCommandString.split("\\.");
if (commandlist.length != 2) {
logger.warn("wrong number of arguments for key command \"{}\". Should be key.X", tvCommandString);
return;
}
String key = commandlist[1];
sendTVCommand(key, ip + ":" + port);
} else if (tvCommandString.contains("ambilight")) {
logger.debug("Found an ambilight command: {}", tvCommandString);
String[] commandlist = tvCommandString.split("\\.");
String[] layer = command2LayerString(tvCommandString);
if (commandlist.length < 2) {
logger.warn("wrong number of arguments for ambilight command \"{}\". Should be at least ambilight.color, ambilight.mode.X, etc...", tvCommandString);
return;
}
if (commandlist[1].contains("color")) {
setAmbilightColor(ip + ":" + port, command, layer);
} else if (commandlist[1].contains("mode")) {
if (commandlist.length != 3) {
logger.warn("wrong number of arguments for ambilight.mode command \"{}\". Should be ambilight.mode.internal, ambilight.mode.manual, ambilight.mode.expert", tvCommandString);
return;
}
setAmbilightMode(commandlist[2], ip + ":" + port);
}
} else if (tvCommandString.contains("volume")) {
logger.debug("Found a Volume command: {}", tvCommandString);
sendVolume(ip + ":" + port, command);
} else if (tvCommandString.contains("source")) {
logger.debug("Found a Source command: {}", tvCommandString);
String[] commandlist = tvCommandString.split("\\.");
if (commandlist.length < 2) {
logger.warn("wrong number of arguments for source command \"{}\". Should be at least mode.X...", tvCommandString);
return;
}
sendSource(ip + ":" + port, commandlist[1]);
} else {
logger.warn("Unrecognized tv command \"{}\". Only key.X or ambilight[].X is supported", tvCommandString);
return;
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class SerialDevice method serialEvent.
@Override
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
// we get here if data has been received
StringBuilder sb = new StringBuilder();
byte[] readBuffer = new byte[20];
try {
do {
// read data from serial device
while (inputStream.available() > 0) {
int bytes = inputStream.read(readBuffer);
sb.append(new String(readBuffer, 0, bytes));
}
try {
// add wait states around reading the stream, so that interrupted transmissions are merged
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore interruption
}
} while (inputStream.available() > 0);
// sent data
String result = sb.toString();
// send data to the bus
logger.debug("Received message '{}' on serial port {}", new String[] { result, port });
if (eventPublisher != null) {
if (configMap != null && !configMap.isEmpty()) {
for (Entry<String, ItemType> entry : configMap.entrySet()) {
// use pattern
if (entry.getValue().pattern != null) {
if (transformationService == null) {
logger.error("No transformation service available!");
} else {
try {
String value = transformationService.transform(entry.getValue().pattern, result);
if (entry.getValue().type.equals(NumberItem.class)) {
try {
eventPublisher.postUpdate(entry.getKey(), new DecimalType(value));
} catch (NumberFormatException e) {
logger.warn("Unable to convert regex result '{}' for item {} to number", new String[] { result, entry.getKey() });
}
} else {
eventPublisher.postUpdate(entry.getKey(), new StringType(value));
}
} catch (TransformationException e) {
logger.error("Unable to transform!", e);
}
}
} else if (entry.getValue().type == StringItem.class) {
if (entry.getValue().base64) {
result = Base64.encodeBase64String(result.getBytes());
}
eventPublisher.postUpdate(entry.getKey(), new StringType(result));
} else if (entry.getValue().type == SwitchItem.class && result.trim().isEmpty()) {
eventPublisher.postUpdate(entry.getKey(), OnOffType.ON);
eventPublisher.postUpdate(entry.getKey(), OnOffType.OFF);
}
}
}
}
} catch (IOException e) {
logger.debug("Error receiving data on serial port {}: {}", new String[] { port, e.getMessage() });
}
break;
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class TestSHCMessage method testWeatherTempHumMinMax2.
/**
* test data is: weather temperature & humidity: 0 (0x000) temperatur: 32767
* (0x7FFF)
*/
@Test
public void testWeatherTempHumMinMax2() {
String message = " PKT:SID=10;PC=17531;MT=8;MGID=10;MID=2;MD=001FFFC00000;785c34de";
SHCMessage shcMessage = new SHCMessage(message, packet);
List<Type> values = shcMessage.getData().getOpenHABTypes();
assertEquals(0, ((DecimalType) values.get(0)).intValue());
assertEquals(32767, ((DecimalType) values.get(1)).intValue());
}
Aggregations