use of org.openhab.core.types.UnDefType in project openhab1-addons by openhab.
the class InfluxDBPersistenceService method store.
/**
* {@inheritDoc}
*/
@Override
public void store(Item item, String alias) {
if (item.getState() instanceof UnDefType) {
return;
}
if (!isProperlyConfigured) {
logger.warn("Configuration for influxdb not yet loaded or broken.");
return;
}
if (!isConnected()) {
logger.warn("InfluxDB is not yet connected");
return;
}
String realName = item.getName();
String name = (alias != null) ? alias : realName;
State state = null;
if (item.getAcceptedCommandTypes().contains(HSBType.class)) {
state = item.getStateAs(HSBType.class);
logger.trace("Tried to get item as {}, state is {}", HSBType.class, state.toString());
} else if (item.getAcceptedDataTypes().contains(PercentType.class)) {
state = item.getStateAs(PercentType.class);
logger.trace("Tried to get item as {}, state is {}", PercentType.class, state.toString());
} else {
// All other items should return the best format by default
state = item.getState();
logger.trace("Tried to get item from item class {}, state is {}", item.getClass(), state.toString());
}
Object value = stateToObject(state);
logger.trace("storing {} in influxdb value {}, {}", name, value, item);
Point point = Point.measurement(name).field(VALUE_COLUMN_NAME, value).time(System.currentTimeMillis(), timeUnit).build();
try {
influxDB.write(dbName, retentionPolicy, point);
} catch (RuntimeException e) {
logger.error("storing failed with exception for item: {}", name);
handleDatabaseException(e);
}
}
use of org.openhab.core.types.UnDefType in project openhab1-addons by openhab.
the class MapDBPersistenceService method store.
@Override
public void store(Item item, String alias) {
if (item.getState() instanceof UnDefType) {
return;
}
if (alias == null) {
alias = item.getName();
}
logger.debug("store called for {}", alias);
State state = item.getState();
if (item instanceof ColorItem) {
state = item.getStateAs(HSBType.class);
} else if (item instanceof DimmerItem || item instanceof RollershutterItem) {
state = item.getStateAs(PercentType.class);
}
MapDBItem mItem = new MapDBItem();
mItem.setName(alias);
mItem.setState(state);
mItem.setTimestamp(new Date());
MapDBItem oldItem = map.put(alias, mItem);
if (!commitSameState) {
if (oldItem != null) {
if (!oldItem.getState().toString().equals(state.toString())) {
needsCommit = true;
}
}
}
logger.debug("Stored '{}' with state '{}' in mapdb database", alias, state.toString());
}
use of org.openhab.core.types.UnDefType in project openhab1-addons by openhab.
the class MongoDBPersistenceService 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) {
logger.warn("MongoDB not initialized");
return;
}
// Connect to mongodb server if we're not already connected
if (!isConnected()) {
connectToDatabase();
}
// If we still didn't manage to connect, then return!
if (!isConnected()) {
logger.warn("mongodb: No connection to database. Can not persist item '{}'! Will retry connecting to database next time.", item);
return;
}
String realName = item.getName();
String name = (alias != null) ? alias : realName;
Object value = this.convertValue(item.getState());
DBObject obj = new BasicDBObject();
obj.put(FIELD_ID, new ObjectId());
obj.put(FIELD_ITEM, name);
obj.put(FIELD_REALNAME, realName);
obj.put(FIELD_TIMESTAMP, new Date());
obj.put(FIELD_VALUE, value);
this.mongoCollection.save(obj);
logger.debug("MongoDB save {}={}", name, value);
}
use of org.openhab.core.types.UnDefType in project openhab1-addons by openhab.
the class BenqProjectorBinding method internalReceiveCommand.
/**
* @{inheritDoc
*/
@Override
protected void internalReceiveCommand(String itemName, Command command) {
for (BenqProjectorBindingProvider binding : super.providers) {
if (binding.providesBindingFor(itemName)) {
logger.debug("Process command " + command + " for " + itemName);
BenqProjectorBindingConfig cfg = binding.getConfigForItemName(itemName);
String resp = sendCommandToProjector(cfg, command);
State s = cfg.mode.parseResponse(resp);
if (!(s instanceof UnDefType)) {
eventPublisher.postUpdate(itemName, s);
logger.debug(itemName + " status is " + s);
} else {
logger.debug(itemName + " not updated as result was undefined");
}
}
}
}
use of org.openhab.core.types.UnDefType in project openhab1-addons by openhab.
the class BenqProjectorBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
for (BenqProjectorBindingProvider binding : super.providers) {
for (String itemName : binding.getItemNames()) {
logger.debug("Polling projector status for " + itemName);
BenqProjectorBindingConfig cfg = binding.getConfigForItemName(itemName);
State s = queryProjector(cfg);
if (!(s instanceof UnDefType)) {
eventPublisher.postUpdate(itemName, s);
logger.debug(itemName + " status is " + s);
} else {
logger.debug(itemName + " not updated as result was undefined");
}
}
}
}
Aggregations