Search in sources :

Example 11 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class KNXCoreTypeMapper method toDPTValue.

/*
     * (non-Javadoc)
     *
     * @see org.openhab.binding.knx.config.KNXTypeMapper#toDPTValue(org.openhab.core.types.Type, java.lang.String)
     */
@Override
public String toDPTValue(Type type, String dptID) {
    DPT dpt;
    int mainNumber = getMainNumber(dptID);
    if (mainNumber == -1) {
        logger.error("toDPTValue couldn't identify mainnumber in dptID: {}", dptID);
        return null;
    }
    try {
        DPTXlator translator = TranslatorTypes.createTranslator(mainNumber, dptID);
        dpt = translator.getType();
    } catch (KNXException e) {
        e.printStackTrace();
        return null;
    }
    // check for HSBType first, because it extends PercentType as well
    if (type instanceof HSBType) {
        Color color = ((HSBType) type).toColor();
        return "r:" + Integer.toString(color.getRed()) + " g:" + Integer.toString(color.getGreen()) + " b:" + Integer.toString(color.getBlue());
    } else if (type instanceof OnOffType) {
        return type.equals(OnOffType.OFF) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof UpDownType) {
        return type.equals(UpDownType.UP) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof IncreaseDecreaseType) {
        DPT valueDPT = ((DPTXlator3BitControlled.DPT3BitControlled) dpt).getControlDPT();
        return type.equals(IncreaseDecreaseType.DECREASE) ? valueDPT.getLowerValue() + " 5" : valueDPT.getUpperValue() + " 5";
    } else if (type instanceof OpenClosedType) {
        return type.equals(OpenClosedType.CLOSED) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof StopMoveType) {
        return type.equals(StopMoveType.STOP) ? dpt.getLowerValue() : dpt.getUpperValue();
    } else if (type instanceof PercentType) {
        return type.toString();
    } else if (type instanceof DecimalType) {
        switch(mainNumber) {
            case 2:
                DPT valueDPT = ((DPTXlator1BitControlled.DPT1BitControlled) dpt).getValueDPT();
                switch(((DecimalType) type).intValue()) {
                    case 0:
                        return "0 " + valueDPT.getLowerValue();
                    case 1:
                        return "0 " + valueDPT.getUpperValue();
                    case 2:
                        return "1 " + valueDPT.getLowerValue();
                    default:
                        return "1 " + valueDPT.getUpperValue();
                }
            case 18:
                int intVal = ((DecimalType) type).intValue();
                if (intVal > 63) {
                    return "learn " + (intVal - 0x80);
                } else {
                    return "activate " + intVal;
                }
            default:
                return type.toString();
        }
    } else if (type instanceof StringType) {
        return type.toString();
    } else if (type instanceof DateTimeType) {
        return formatDateTime((DateTimeType) type, dptID);
    }
    logger.debug("toDPTValue: Couldn't get value for {} dpt id {} (no mapping).", type, dptID);
    return null;
}
Also used : KNXException(tuwien.auto.calimero.exception.KNXException) StringType(org.openhab.core.library.types.StringType) Color(java.awt.Color) DPT(tuwien.auto.calimero.dptxlator.DPT) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) Datapoint(tuwien.auto.calimero.datapoint.Datapoint) StopMoveType(org.openhab.core.library.types.StopMoveType) DateTimeType(org.openhab.core.library.types.DateTimeType) DPTXlator(tuwien.auto.calimero.dptxlator.DPTXlator) OnOffType(org.openhab.core.library.types.OnOffType) OpenClosedType(org.openhab.core.library.types.OpenClosedType) DPTXlator3BitControlled(tuwien.auto.calimero.dptxlator.DPTXlator3BitControlled) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) DPTXlator1BitControlled(tuwien.auto.calimero.dptxlator.DPTXlator1BitControlled) HSBType(org.openhab.core.library.types.HSBType)

Example 12 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class Ipx800Dimmer method updateStateInternal.

@Override
protected boolean updateStateInternal(Type state) {
    boolean changed = false;
    if (state instanceof PercentType) {
        PercentType commandState = (PercentType) state;
        if (!lastState.equals(commandState)) {
            changed = true;
            lastState = commandState;
        }
    }
    return changed;
}
Also used : PercentType(org.openhab.core.library.types.PercentType)

Example 13 with PercentType

use of org.openhab.core.library.types.PercentType 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);
    }
}
Also used : SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) SappBindingProvider(org.openhab.binding.sapp.SappBindingProvider) StopMoveType(org.openhab.core.library.types.StopMoveType) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) Item(org.openhab.core.items.Item) ContactItem(org.openhab.core.library.items.ContactItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) SappPnmas(org.openhab.binding.sapp.internal.model.SappPnmas) SappAddressRollershutterControl(org.openhab.binding.sapp.internal.model.SappAddressRollershutterControl) UpDownType(org.openhab.core.library.types.UpDownType) PercentType(org.openhab.core.library.types.PercentType) SappCentralExecuter(org.openhab.binding.sapp.internal.executer.SappCentralExecuter) SappAddressOnOffControl(org.openhab.binding.sapp.internal.model.SappAddressOnOffControl) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) SappAddressDimmer(org.openhab.binding.sapp.internal.model.SappAddressDimmer) SappAddressDecimal(org.openhab.binding.sapp.internal.model.SappAddressDecimal) OnOffType(org.openhab.core.library.types.OnOffType) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) DecimalType(org.openhab.core.library.types.DecimalType) IncreaseDecreaseType(org.openhab.core.library.types.IncreaseDecreaseType) SappException(com.github.paolodenti.jsapp.core.command.base.SappException) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Example 14 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class JpaHistoricItem method fromPersistedItem.

/**
     * Converts the string value of the persisted item to the state of a HistoricItem.
     * 
     * @param pItem the persisted JpaPersistentItem
     * @param item the source reference Item
     * @return historic item
     */
public static HistoricItem fromPersistedItem(JpaPersistentItem pItem, Item item) {
    State state;
    if (item instanceof NumberItem) {
        state = new DecimalType(Double.valueOf(pItem.getValue()));
    } else if (item instanceof DimmerItem) {
        state = new PercentType(Integer.valueOf(pItem.getValue()));
    } else if (item instanceof SwitchItem) {
        state = OnOffType.valueOf(pItem.getValue());
    } else if (item instanceof ContactItem) {
        state = OpenClosedType.valueOf(pItem.getValue());
    } else if (item instanceof RollershutterItem) {
        state = PercentType.valueOf(pItem.getValue());
    } else if (item instanceof ColorItem) {
        state = new HSBType(pItem.getValue());
    } else if (item instanceof DateTimeItem) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(Long.valueOf(pItem.getValue())));
        state = new DateTimeType(cal);
    } else if (item instanceof LocationItem) {
        PointType pType = null;
        String[] comps = pItem.getValue().split(";");
        if (comps.length >= 2) {
            pType = new PointType(new DecimalType(comps[0]), new DecimalType(comps[1]));
            if (comps.length == 3) {
                pType.setAltitude(new DecimalType(comps[2]));
            }
        }
        state = pType;
    } else if (item instanceof CallItem) {
        state = new CallType(pItem.getValue());
    } else {
        state = new StringType(pItem.getValue());
    }
    return new JpaHistoricItem(item.getName(), state, pItem.getTimestamp());
}
Also used : LocationItem(org.openhab.core.library.items.LocationItem) StringType(org.openhab.core.library.types.StringType) ContactItem(org.openhab.core.library.items.ContactItem) Calendar(java.util.Calendar) CallType(org.openhab.library.tel.types.CallType) ColorItem(org.openhab.core.library.items.ColorItem) PercentType(org.openhab.core.library.types.PercentType) DateTimeItem(org.openhab.core.library.items.DateTimeItem) Date(java.util.Date) NumberItem(org.openhab.core.library.items.NumberItem) DateTimeType(org.openhab.core.library.types.DateTimeType) State(org.openhab.core.types.State) DimmerItem(org.openhab.core.library.items.DimmerItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) DecimalType(org.openhab.core.library.types.DecimalType) PointType(org.openhab.core.library.types.PointType) CallItem(org.openhab.library.tel.items.CallItem) HSBType(org.openhab.core.library.types.HSBType) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 15 with PercentType

use of org.openhab.core.library.types.PercentType in project openhab1-addons by openhab.

the class MysqlPersistenceService method store.

/**
     * @{inheritDoc
     */
@Override
public void store(Item item, String alias) {
    // Don't log undefined/uninitialised data
    if (item.getState() instanceof UnDefType) {
        return;
    }
    // If we've not initialised the bundle, then return
    if (initialized == false) {
        return;
    }
    // Connect to mySQL server if we're not already connected
    if (!isConnected()) {
        connectToDatabase();
    }
    // If we still didn't manage to connect, then return!
    if (!isConnected()) {
        logger.warn("mySQL: No connection to database. Can not persist item '{}'! " + "Will retry connecting to database when error count:{} equals errReconnectThreshold:{}", item, errCnt, errReconnectThreshold);
        return;
    }
    // Get the table name for this item
    String tableName = getTable(item);
    if (tableName == null) {
        logger.error("Unable to store item '{}'.", item.getName());
        return;
    }
    // Do some type conversion to ensure we know the data type.
    // This is necessary for items that have multiple types and may return their
    // state in a format that's not preferred or compatible with the MySQL type.
    // eg. DimmerItem can return OnOffType (ON, OFF), or PercentType (0-100).
    // We need to make sure we cover the best type for serialisation.
    String value;
    if (item instanceof ColorItem) {
        value = item.getStateAs(HSBType.class).toString();
    } else if (item instanceof RollershutterItem) {
        value = item.getStateAs(PercentType.class).toString();
    } else {
        /*
             * !!ATTENTION!!
             * 
             * 1.
             * DimmerItem.getStateAs(PercentType.class).toString() always returns 0
             * RollershutterItem.getStateAs(PercentType.class).toString() works as expected
             * 
             * 2.
             * (item instanceof ColorItem) == (item instanceof DimmerItem) = true
             * Therefore for instance tests ColorItem always has to be tested before DimmerItem
             * 
             * !!ATTENTION!!
             */
        // All other items should return the best format by default
        value = item.getState().toString();
    }
    // Get current timestamp
    long timeNow = Calendar.getInstance().getTimeInMillis();
    Timestamp timestamp = new Timestamp(timeNow);
    String sqlCmd = null;
    PreparedStatement statement = null;
    try {
        if (localtime) {
            sqlCmd = new String("INSERT INTO " + tableName + " (TIME, VALUE) VALUES(?,?) ON DUPLICATE KEY UPDATE VALUE=?;");
            statement = connection.prepareStatement(sqlCmd);
            statement.setTimestamp(1, timestamp);
            statement.setString(2, value);
            statement.setString(3, value);
        } else {
            sqlCmd = new String("INSERT INTO " + tableName + " (TIME, VALUE) VALUES(NOW(),?) ON DUPLICATE KEY UPDATE VALUE=?;");
            statement = connection.prepareStatement(sqlCmd);
            statement.setString(1, value);
            statement.setString(2, value);
        }
        statement.executeUpdate();
        logger.debug("mySQL: Stored item '{}' as '{}'[{}] in SQL database at {}.", item.getName(), item.getState().toString(), value, timestamp.toString());
        logger.debug("mySQL: query: {}", sqlCmd);
        // Success
        errCnt = 0;
    } catch (Exception e) {
        errCnt++;
        logger.error("mySQL: Could not store item '{}' in database with " + "statement '{}': {}", item.getName(), sqlCmd, e.getMessage());
    } finally {
        if (statement != null) {
            try {
                statement.close();
            } catch (Exception hidden) {
            }
        }
    }
}
Also used : UnDefType(org.openhab.core.types.UnDefType) RollershutterItem(org.openhab.core.library.items.RollershutterItem) ColorItem(org.openhab.core.library.items.ColorItem) PreparedStatement(java.sql.PreparedStatement) PercentType(org.openhab.core.library.types.PercentType) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) ItemNotFoundException(org.openhab.core.items.ItemNotFoundException)

Aggregations

PercentType (org.openhab.core.library.types.PercentType)105 DecimalType (org.openhab.core.library.types.DecimalType)43 State (org.openhab.core.types.State)29 StringType (org.openhab.core.library.types.StringType)27 DimmerItem (org.openhab.core.library.items.DimmerItem)22 Test (org.junit.Test)21 HSBType (org.openhab.core.library.types.HSBType)19 OnOffType (org.openhab.core.library.types.OnOffType)19 RollershutterItem (org.openhab.core.library.items.RollershutterItem)17 NumberItem (org.openhab.core.library.items.NumberItem)16 BigDecimal (java.math.BigDecimal)14 SwitchItem (org.openhab.core.library.items.SwitchItem)13 IncreaseDecreaseType (org.openhab.core.library.types.IncreaseDecreaseType)13 ColorItem (org.openhab.core.library.items.ColorItem)11 DateTimeType (org.openhab.core.library.types.DateTimeType)11 Calendar (java.util.Calendar)9 ContactItem (org.openhab.core.library.items.ContactItem)9 UpDownType (org.openhab.core.library.types.UpDownType)9 StopMoveType (org.openhab.core.library.types.StopMoveType)7 DateTimeItem (org.openhab.core.library.items.DateTimeItem)6