use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.
the class PilightBinding method createUpdateCommand.
private Action createUpdateCommand(Command command, PilightBindingConfig config) {
Action action = new Action(Action.ACTION_CONTROL);
Code code = new Code();
code.setDevice(config.getDevice());
if (command instanceof OnOffType) {
setOnOffValue((OnOffType) command, code);
} else if (command instanceof PercentType) {
setDimmerValue((PercentType) command, code);
} else {
logger.error("Only OnOffType and PercentType can be changed by the pilight binding");
return null;
}
action.setCode(code);
return action;
}
use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.
the class ZWaveIndicatorConverter method receiveCommand.
/**
* {@inheritDoc}
*
* The node's indicator status can change at any time, and without the knowledge of the Z-Wave binding so
* before any changes are made to the indicator we need to get its actual value from the device.
* Hence the receiveCommand method adds the desired command to a "pending" list, and issues an INDICATOR_GET
* it does not change the actual device Indicator value.
*
* When the node responds with the INDICATOR_REPORT pending commands are applied to the indicator value
* and the result is then sent to the node. This is performed in the handleEvent() method.
*
* Pending changes are stored in a hash of hashes with the following keys "ItemName" and "bit" value is 1
* for turn bit ON, -1 to turn the bound bit OFF, 0 no change.
*
* HashMap<ItemName, HashMap<bit, pendingOperationCode>>
*/
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node, ZWaveIndicatorCommandClass commandClass, int endpointId, Map<String, String> arguments) {
ZWaveCommandConverter<?, ?> converter = this.getCommandConverter(command.getClass());
if (converter == null) {
logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
return;
}
if (!arguments.containsKey("bit")) {
logger.error("NODE {}: You must specify an Indicator bit for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
return;
}
int bit = Integer.parseInt(arguments.get("bit"));
if (!(command instanceof OnOffType)) {
return;
}
if (command == OnOffType.ON) {
HashMap<Integer, Integer> h = new HashMap<Integer, Integer>();
h.put(bit, PENDING_ON);
pending.put(item.getName(), h);
logger.warn(String.format("NODE %d: Item %s Set bit = %d to ON - PENDING", node.getNodeId(), item.getName(), bit));
} else {
logger.warn(String.format("NODE %d: Item %s Set bit = %d to OFF - PENDING", node.getNodeId(), item.getName(), bit));
HashMap<Integer, Integer> h = new HashMap<Integer, Integer>();
h.put(bit, PENDING_OFF);
pending.put(item.getName(), h);
}
// Issue a INDICATOR_GET message to the node to get the updated indicator value
SerialMessage serialMessage = node.encapsulate(commandClass.getValueMessage(), commandClass, endpointId);
if (serialMessage == null) {
logger.warn("NODE {}: Generating message failed for command class = {}, endpoint = {}", node.getNodeId(), commandClass.getCommandClass().getLabel(), endpointId);
return;
}
this.getController().sendData(serialMessage);
logger.warn(String.format("NODE %d: Item %s bit = %d Get current Indicator State", node.getNodeId(), item.getName(), bit));
if (command instanceof State) {
this.getEventPublisher().postUpdate(item.getName(), (State) command);
}
}
use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.
the class ZWaveMultiLevelSwitchConverter method receiveCommand.
/**
* {@inheritDoc}
*/
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node, ZWaveMultiLevelSwitchCommandClass commandClass, int endpointId, Map<String, String> arguments) {
SerialMessage serialMessage = null;
String restoreLastValue = null;
if (command instanceof StopMoveType && (StopMoveType) command == StopMoveType.STOP) {
// special handling for the STOP command
serialMessage = commandClass.stopLevelChangeMessage();
} else {
ZWaveCommandConverter<?, ?> converter = null;
if (command instanceof OnOffType) {
restoreLastValue = arguments.get("restore_last_value");
if ("true".equalsIgnoreCase(restoreLastValue)) {
converter = this.restoreValueOnOffConverter;
} else {
converter = this.normalOnOffConverter;
}
} else {
converter = this.getCommandConverter(command.getClass());
}
if (converter == null) {
logger.warn("NODE {}: No converter found for item = {}, endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId);
return;
}
// Allow inversion of roller shutter UP/DOWN
if (converter instanceof MultiLevelUpDownCommandConverter) {
logger.debug("Multilevel Switch MultiLevelUpDownCommandConverter");
if ("true".equalsIgnoreCase(arguments.get("invert_state"))) {
logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - invert");
if (command == UpDownType.UP) {
command = UpDownType.DOWN;
} else {
command = UpDownType.UP;
}
logger.trace("Multilevel Switch MultiLevelUpDownCommandConverter - inverted: {}", command);
}
}
// Allow inversion of roller shutter PERCENT value
if (converter instanceof MultiLevelPercentCommandConverter) {
logger.debug("Multilevel Switch MultiLevelPercentCommandConverter");
if ("true".equalsIgnoreCase(arguments.get("invert_percent"))) {
logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - invert");
command = new PercentType(100 - ((DecimalType) command).intValue());
logger.trace("Multilevel Switch MultiLevelPercentCommandConverter - inverted: {}", command);
}
}
Integer value = (Integer) converter.convertFromCommandToValue(item, command);
logger.trace("NODE {}: Converted command '{}' to value {} for item = {}, endpoint = {}.", node.getNodeId(), command.toString(), value, item.getName(), endpointId);
serialMessage = commandClass.setValueMessage(value);
}
// encapsulate the message in case this is a multi-instance node
serialMessage = node.encapsulate(serialMessage, commandClass, endpointId);
if (serialMessage == null) {
logger.warn("Generating message failed for command class = {}, node = {}, endpoint = {}", commandClass.getCommandClass().getLabel(), node.getNodeId(), endpointId);
return;
}
this.getController().sendData(serialMessage);
// update the bus in case of normal dimming. schedule refresh in case of restore to last value dimming.
if (!"true".equalsIgnoreCase(restoreLastValue) && command instanceof OnOffType && (OnOffType) command == OnOffType.ON) {
executeRefresh(node, commandClass, endpointId, arguments);
} else if (command instanceof State) {
this.getEventPublisher().postUpdate(item.getName(), (State) command);
}
}
use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.
the class XplBinding method handleXPLMessage.
@Override
public void handleXPLMessage(xPL_MessageI theMessage) {
for (XplBindingProvider provider : providers) {
List<String> matchingItems = provider.hasMessage(theMessage);
for (String itemName : matchingItems) {
XplBindingConfig config = provider.getConfig(itemName);
if (config == null) {
continue;
}
String current = theMessage.getNamedValue(config.NamedParameter);
Item item = provider.getItem(itemName);
if (item != null) {
if (item instanceof SwitchItem) {
OnOffType status = (current.equalsIgnoreCase("on") || current.equalsIgnoreCase("true") || current.equalsIgnoreCase("1") || current.equalsIgnoreCase("open") || current.equalsIgnoreCase("high")) ? OnOffType.ON : OnOffType.OFF;
synchronized (item) {
if (!item.getState().equals(status)) {
eventPublisher.postUpdate(itemName, status);
((SwitchItem) item).setState(status);
}
}
} else if (item instanceof ContactItem) {
OpenClosedType status = (current.equalsIgnoreCase("on") || current.equalsIgnoreCase("true") || current.equalsIgnoreCase("1") || current.equalsIgnoreCase("open") || current.equalsIgnoreCase("high")) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
synchronized (item) {
if (!item.getState().equals(status)) {
eventPublisher.postUpdate(itemName, status);
((ContactItem) item).setState(status);
}
}
} else if (item instanceof NumberItem) {
DecimalType value = new DecimalType(current);
synchronized (item) {
if (!item.getState().equals(value)) {
eventPublisher.postUpdate(itemName, value);
((NumberItem) item).setState(value);
}
}
} else if (item instanceof StringItem) {
StringType value = new StringType(current);
synchronized (item) {
if (!item.getState().equals(value)) {
eventPublisher.postUpdate(itemName, value);
((StringItem) item).setState(value);
}
}
}
}
}
}
}
use of org.openhab.core.library.types.OnOffType in project openhab1-addons by openhab.
the class DSCAlarmActiveBinding method internalReceiveCommand.
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
DSCAlarmBindingConfig dscAlarmBindingConfig = null;
for (DSCAlarmBindingProvider prov : providers) {
dscAlarmBindingConfig = prov.getDSCAlarmBindingConfig(itemName);
if (dscAlarmBindingConfig != null) {
DSCAlarmDeviceType dscAlarmDeviceType = dscAlarmBindingConfig.getDeviceType();
int partitionId;
int zoneId;
int cmd;
logger.debug("internalReceiveCommand(): Item Name: {} Command: {} Item Device Type: {}", itemName, command, dscAlarmDeviceType);
if (connected) {
switch(dscAlarmDeviceType) {
case PANEL:
switch(dscAlarmBindingConfig.getDSCAlarmItemType()) {
case PANEL_CONNECTION:
if (command.toString().equals("0")) {
closeConnection();
if (!connected) {
dscAlarmItemUpdate.setConnected(false);
}
}
break;
case PANEL_COMMAND:
cmd = Integer.parseInt(command.toString());
switch(cmd) {
case 0:
api.sendCommand(APICode.Poll);
break;
case 1:
api.sendCommand(APICode.StatusReport);
break;
case 2:
api.sendCommand(APICode.LabelsRequest);
break;
case 8:
api.sendCommand(APICode.DumpZoneTimers);
break;
case 10:
api.sendCommand(APICode.SetTimeDate);
break;
case 200:
api.sendCommand(APICode.CodeSend);
break;
default:
break;
}
itemName = getItemName(DSCAlarmItemType.PANEL_COMMAND, 0, 0);
if (StringUtils.isNotEmpty(itemName)) {
updateItem(itemName, -1, "");
}
break;
case PANEL_TIME_STAMP:
if (command instanceof OnOffType) {
cmd = command == OnOffType.ON ? 1 : 0;
api.sendCommand(APICode.TimeStampControl, String.valueOf(cmd));
updateItem(itemName, cmd, "");
}
break;
case PANEL_TIME_BROADCAST:
if (command instanceof OnOffType) {
cmd = command == OnOffType.ON ? 1 : 0;
api.sendCommand(APICode.TimeDateBroadcastControl, String.valueOf(cmd));
updateItem(itemName, cmd, "");
}
break;
default:
break;
}
break;
case PARTITION:
partitionId = dscAlarmBindingConfig.getPartitionId();
switch(dscAlarmBindingConfig.getDSCAlarmItemType()) {
case PARTITION_ARM_MODE:
if (command.toString().equals("0")) {
api.sendCommand(APICode.PartitionDisarmControl, String.valueOf(partitionId));
} else if (command.toString().equals("1")) {
api.sendCommand(APICode.PartitionArmControlAway, String.valueOf(partitionId));
} else if (command.toString().equals("2")) {
api.sendCommand(APICode.PartitionArmControlStay, String.valueOf(partitionId));
} else if (command.toString().equals("3")) {
api.sendCommand(APICode.PartitionArmControlZeroEntryDelay, String.valueOf(partitionId));
} else if (command.toString().equals("4")) {
api.sendCommand(APICode.PartitionArmControlWithUserCode, String.valueOf(partitionId));
}
break;
default:
break;
}
break;
case ZONE:
partitionId = dscAlarmBindingConfig.getPartitionId();
zoneId = dscAlarmBindingConfig.getZoneId();
switch(dscAlarmBindingConfig.getDSCAlarmItemType()) {
case ZONE_BYPASS_MODE:
if (command.toString().equals("0")) {
String data = String.valueOf(partitionId) + "*1" + String.format("%02d", zoneId) + "#";
api.sendCommand(APICode.KeySequence, data);
} else if (command.toString().equals("1")) {
String data = String.valueOf(partitionId) + "*1" + String.format("%02d", zoneId) + "#";
api.sendCommand(APICode.KeySequence, data);
}
break;
default:
break;
}
break;
default:
logger.debug("internalReceiveCommand(): No Command Sent.");
break;
}
} else {
if (dscAlarmDeviceType == DSCAlarmDeviceType.PANEL) {
if (dscAlarmBindingConfig.getDSCAlarmItemType() == DSCAlarmItemType.PANEL_CONNECTION) {
if (command.toString().equals("1")) {
if (api != null) {
openConnection();
if (connected) {
dscAlarmItemUpdate.setConnected(true);
}
}
}
}
}
}
}
}
}
Aggregations