use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProviderTest method testProcessBindingConfig_FileCount01.
/*
* "DirFiles" tests
*/
@Test
public /* Verify a simple file count configuration: "DirFiles:60000:." */
void testProcessBindingConfig_FileCount01() throws BindingConfigParseException {
NumberItem testItem = new NumberItem("DirFiles01");
String simpleConfig = "DirFiles:60000:.";
provider.processBindingConfiguration("systeminfo", testItem, simpleConfig);
Assert.assertNull(provider.getCommandType(null));
Assert.assertNull(provider.getCommandType(""));
Assert.assertEquals("DirFiles", provider.getCommandType("DirFiles01").toString());
Assert.assertNull(provider.getItemType(null));
Assert.assertNull(provider.getItemType(""));
Assert.assertNull(provider.getItemType("DirFiles01"));
Assert.assertEquals(0, provider.getRefreshInterval(null));
Assert.assertEquals(0, provider.getRefreshInterval(""));
Assert.assertEquals(60000, provider.getRefreshInterval("DirFiles01"));
Assert.assertNull(provider.getTarget(null));
Assert.assertNull(provider.getTarget(""));
Assert.assertEquals(".", provider.getTarget("DirFiles01"));
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class KM200Comm method sendVirtualState.
/**
* This function sets the state of a virtual service
*
*/
public String sendVirtualState(KM200CommObject object, Class<? extends Item> itemType, String service, Command command) {
String dataToSend = null;
String type = null;
logger.debug("Check virtual state of: {} type: {} item: {}", service, type, itemType.getName());
object = device.serviceMap.get(service);
KM200CommObject parObject = device.serviceMap.get(object.getParent());
type = object.getServiceType();
/* Binding is a StringItem */
if (itemType.isAssignableFrom(StringItem.class)) {
String val = ((StringType) command).toString();
switch(type) {
case "switchProgram":
KM200SwitchProgramService sPService = ((KM200SwitchProgramService) parObject.getValueParameter());
String[] servicePath = service.split("/");
String virtService = servicePath[servicePath.length - 1];
if (virtService.equals("weekday")) {
/* Only parameter changing without communication to device */
sPService.setActiveDay(val);
}
break;
}
/* Binding is a NumberItem */
} else if (itemType.isAssignableFrom(NumberItem.class)) {
Integer val = ((DecimalType) command).intValue();
switch(type) {
case "switchProgram":
KM200SwitchProgramService sPService = ((KM200SwitchProgramService) parObject.getValueParameter());
String[] servicePath = service.split("/");
String virtService = servicePath[servicePath.length - 1];
if (virtService.equals("cycle")) {
/* Only parameter changing without communication to device */
sPService.setActiveCycle(val);
} else if (virtService.equals(sPService.getPositiveSwitch())) {
sPService.setActivePositiveSwitch(val);
/* Create a JSON Array from current switch configuration */
dataToSend = sPService.getUpdatedJSONData(parObject);
} else if (virtService.equals(sPService.getNegativeSwitch())) {
sPService.setActiveNegativeSwitch(val);
/* Create a JSON Array from current switch configuration */
dataToSend = sPService.getUpdatedJSONData(parObject);
}
break;
case "errorList":
KM200ErrorService eService = ((KM200ErrorService) device.serviceMap.get(object.getParent()).getValueParameter());
String[] nServicePath = service.split("/");
String nVirtService = nServicePath[nServicePath.length - 1];
if (nVirtService.equals("error")) {
/* Only parameter changing without communication to device */
eService.setActiveError(val);
}
break;
}
} else if (itemType.isAssignableFrom(DateTimeItem.class)) {
Calendar cal = ((DateTimeType) command).getCalendar();
KM200SwitchProgramService sPService = ((KM200SwitchProgramService) parObject.getValueParameter());
String[] servicePath = service.split("/");
String virtService = servicePath[servicePath.length - 1];
Integer minutes;
if (virtService.equals(sPService.getPositiveSwitch())) {
minutes = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
minutes = (minutes % sPService.getSwitchPointTimeRaster()) * sPService.getSwitchPointTimeRaster();
sPService.setActivePositiveSwitch(minutes);
/* Create a JSON Array from current switch configuration */
dataToSend = sPService.getUpdatedJSONData(parObject);
}
if (virtService.equals(sPService.getNegativeSwitch())) {
minutes = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE);
minutes = (minutes % sPService.getSwitchPointTimeRaster()) * sPService.getSwitchPointTimeRaster();
sPService.setActiveNegativeSwitch(minutes);
/* Create a JSON Array from current switch configuration */
dataToSend = sPService.getUpdatedJSONData(parObject);
}
}
return dataToSend;
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SappBinding method executeSappCommand.
/**
* executes the real command on pnmas device
*/
private void executeSappCommand(String itemName, Command command) {
SappBindingProvider provider = findFirstMatchingBindingProvider(itemName);
if (provider == null) {
logger.error("cannot find a provider, skipping command");
}
try {
Item item = itemRegistry.getItem(itemName);
logger.debug("found item {}", item);
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
SappBindingConfigSwitchItem sappBindingConfigSwitchItem = (SappBindingConfigSwitchItem) provider.getBindingConfig(itemName);
logger.debug("found binding {}", sappBindingConfigSwitchItem);
if (sappBindingConfigSwitchItem.isPollerSuspender()) {
if (pollingEnabled) {
// turning off polling
pollingEnabled = false;
// force updates of polling switches because polling is
updatePollingSwitchesState(provider);
// off
} else {
// turning on polling
provider.getSappUpdatePendingRequests().replaceAllPendingUpdateRequests(ALL_UPDATE_REQUEST_KEY);
pollingEnabled = true;
}
} else {
SappAddressOnOffControl controlAddress = sappBindingConfigSwitchItem.getControl();
if (!provider.getPnmasMap().containsKey(controlAddress.getPnmasId())) {
logger.error("bad pnmas id ({}) in binding ({}) ... skipping", controlAddress.getPnmasId(), sappBindingConfigSwitchItem);
return;
}
try {
if (command instanceof OnOffType) {
switch(controlAddress.getAddressType()) {
case VIRTUAL:
{
// mask bits on previous value
int previousValue = getVirtualValue(provider, controlAddress.getPnmasId(), controlAddress.getAddress(), controlAddress.getSubAddress(), false);
int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(controlAddress.getSubAddress(), command.equals(OnOffType.ON) ? controlAddress.getOnValue() : controlAddress.getOffValue(), previousValue);
// update pnmas
SappPnmas pnmas = provider.getPnmasMap().get(controlAddress.getPnmasId());
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), controlAddress.getAddress(), newValue);
break;
}
default:
logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), controlAddress.getAddressType());
break;
}
} else {
logger.error("command {} not applicable", command.getClass().getSimpleName());
}
} catch (SappException e) {
logger.error("could not run sappcommand", e);
}
}
} else if (item instanceof NumberItem) {
SappBindingConfigNumberItem sappBindingConfigNumberItem = (SappBindingConfigNumberItem) provider.getBindingConfig(itemName);
logger.debug("found binding {}", sappBindingConfigNumberItem);
SappAddressDecimal address = sappBindingConfigNumberItem.getStatus();
if (!provider.getPnmasMap().containsKey(address.getPnmasId())) {
logger.error("bad pnmas id ({}) in binding ({}) ... skipping", address.getPnmasId(), sappBindingConfigNumberItem);
return;
}
try {
if (command instanceof DecimalType) {
switch(address.getAddressType()) {
case VIRTUAL:
{
// mask bits on previous value
int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), address.backScaledValue(((DecimalType) command).toBigDecimal()), previousValue);
// update pnmas
SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
break;
}
default:
logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
break;
}
} else {
logger.error("command {} not applicable", command.getClass().getSimpleName());
}
} catch (SappException e) {
logger.error("could not run sappcommand", e);
}
} else if (item instanceof RollershutterItem) {
SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = (SappBindingConfigRollershutterItem) provider.getBindingConfig(itemName);
logger.debug("found binding {}", sappBindingConfigRollershutterItem);
SappAddressRollershutterControl controlAddress = null;
if (command instanceof UpDownType && ((UpDownType) command) == UpDownType.UP) {
controlAddress = sappBindingConfigRollershutterItem.getUpControl();
} else if (command instanceof UpDownType && ((UpDownType) command) == UpDownType.DOWN) {
controlAddress = sappBindingConfigRollershutterItem.getDownControl();
} else if (command instanceof StopMoveType && ((StopMoveType) command) == StopMoveType.STOP) {
controlAddress = sappBindingConfigRollershutterItem.getStopControl();
}
if (controlAddress != null) {
if (!provider.getPnmasMap().containsKey(controlAddress.getPnmasId())) {
logger.error("bad pnmas id ({}) in binding ({}) ... skipping", controlAddress.getPnmasId(), sappBindingConfigRollershutterItem);
return;
}
try {
switch(controlAddress.getAddressType()) {
case VIRTUAL:
{
// mask bits on previous value
int previousValue = getVirtualValue(provider, controlAddress.getPnmasId(), controlAddress.getAddress(), controlAddress.getSubAddress(), false);
int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(controlAddress.getSubAddress(), controlAddress.getActivateValue(), previousValue);
// update pnmas
SappPnmas pnmas = provider.getPnmasMap().get(controlAddress.getPnmasId());
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), controlAddress.getAddress(), newValue);
break;
}
default:
logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), controlAddress.getAddressType());
break;
}
} catch (SappException e) {
logger.error("could not run sappcommand", e);
}
} else {
logger.error("command {} not applicable", command.getClass().getSimpleName());
}
} else if (item instanceof DimmerItem) {
SappBindingConfigDimmerItem sappBindingConfigDimmerItem = (SappBindingConfigDimmerItem) provider.getBindingConfig(itemName);
logger.debug("found binding {}", sappBindingConfigDimmerItem);
SappAddressDimmer address = sappBindingConfigDimmerItem.getStatus();
if (!provider.getPnmasMap().containsKey(address.getPnmasId())) {
logger.error("bad pnmas id ({}) in binding ({}) ... skipping", address.getPnmasId(), sappBindingConfigDimmerItem);
return;
}
try {
if (command instanceof OnOffType) {
switch(address.getAddressType()) {
case VIRTUAL:
{
// mask bits on previous value
int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), ((OnOffType) command) == OnOffType.ON ? address.getOriginalMaxScale() : address.getOriginalMinScale(), previousValue);
// update pnmas
SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
break;
}
default:
logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
break;
}
} else if (command instanceof IncreaseDecreaseType) {
switch(address.getAddressType()) {
case VIRTUAL:
{
// mask bits on previous value
int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), ((IncreaseDecreaseType) command) == IncreaseDecreaseType.INCREASE ? Math.min(previousValue + address.getIncrement(), address.getOriginalMaxScale()) : Math.max(previousValue - address.getIncrement(), address.getOriginalMinScale()), previousValue);
// update pnmas
SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
break;
}
default:
logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
break;
}
} else if (command instanceof PercentType) {
switch(address.getAddressType()) {
case VIRTUAL:
{
// mask bits on previous value
int previousValue = getVirtualValue(provider, address.getPnmasId(), address.getAddress(), address.getSubAddress(), false);
int newValue = SappBindingConfigUtils.maskWithSubAddressAndSet(address.getSubAddress(), address.backScaledValue(((PercentType) command).toBigDecimal()), previousValue);
// update pnmas
SappPnmas pnmas = provider.getPnmasMap().get(address.getPnmasId());
SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
sappCentralExecuter.executeSapp7DCommand(pnmas.getIp(), pnmas.getPort(), address.getAddress(), newValue);
break;
}
default:
logger.error("cannot run {} on type {}", command.getClass().getSimpleName(), address.getAddressType());
break;
}
} else {
logger.error("command {} not applicable", command.getClass().getSimpleName());
}
} catch (SappException e) {
logger.error("could not run sappcommand", e);
}
} else {
logger.error("unimplemented item type: {}", item.getClass().getSimpleName());
}
} catch (ItemNotFoundException e) {
logger.error("Item {} not found", itemName);
}
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class SappGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
logger.debug("processing binding configuration for context {}", context);
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
SappBindingConfigSwitchItem sappBindingConfigSwitchItem = new SappBindingConfigSwitchItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigSwitchItem);
} else if (item instanceof ContactItem) {
SappBindingConfigContactItem sappBindingConfigContactItem = new SappBindingConfigContactItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigContactItem);
} else if (item instanceof NumberItem) {
SappBindingConfigNumberItem sappBindingConfigNumberItem = new SappBindingConfigNumberItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigNumberItem);
} else if (item instanceof RollershutterItem) {
SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = new SappBindingConfigRollershutterItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigRollershutterItem);
} else if (item instanceof DimmerItem) {
SappBindingConfigDimmerItem sappBindingConfigDimmerItem = new SappBindingConfigDimmerItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigDimmerItem);
} else {
throw new BindingConfigParseException("item '" + item.getName() + "' is of type '" + item.getClass().getSimpleName() + " - not yet implemented, please check your *.items configuration");
}
} else {
logger.warn("bindingConfig is NULL (item={}) -> processing bindingConfig aborted!", item);
}
}
use of org.openhab.core.library.items.NumberItem in project openhab1-addons by openhab.
the class IntegraStateBindingConfig method convertEventToState.
/**
* {@inheritDoc}
*/
@Override
public State convertEventToState(Item item, SatelEvent event) {
if (!(event instanceof IntegraStateEvent) || hasOptionEnabled(Options.COMMANDS_ONLY)) {
return null;
}
IntegraStateEvent stateEvent = (IntegraStateEvent) event;
if (stateEvent.getStateType() != this.stateType) {
return null;
}
if (this.objectNumbers.length == 1) {
int bitNbr = this.objectNumbers[0] - 1;
boolean invertState = hasOptionEnabled(Options.INVERT_STATE) && (this.stateType.getObjectType() == ObjectType.ZONE || this.stateType.getObjectType() == ObjectType.OUTPUT);
return booleanToState(item, stateEvent.isSet(bitNbr) ^ invertState);
} else if (this.objectNumbers.length == 0) {
int statesSet = stateEvent.statesSet();
if (item instanceof NumberItem) {
return new DecimalType(statesSet);
} else {
return booleanToState(item, statesSet > 0);
}
} else if (this.objectNumbers.length == 2 && item instanceof RollershutterItem) {
// roller shutter support
int upBitNbr = this.objectNumbers[0] - 1;
int downBitNbr = this.objectNumbers[1] - 1;
if (stateEvent.isSet(upBitNbr)) {
if (!stateEvent.isSet(downBitNbr)) {
return UpDownType.UP;
}
} else if (stateEvent.isSet(downBitNbr)) {
return UpDownType.DOWN;
}
}
return null;
}
Aggregations