use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class DigitalSTROMBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
if (!serverIsFound()) {
login();
} else {
if (digitalSTROM.getTime(getSessionToken()) == -1) {
logger.warn("test method failed ... new login now");
login();
}
}
for (DigitalSTROMBindingProvider provider : providers) {
for (DigitalSTROMBindingConfig itemConf : provider.getAllCircuitConsumptionItems()) {
String itemName = itemConf.itemName;
int refreshInterval = itemConf.timeinterval;
Long lastUpdateTimeStamp = lastUpdateMap.get(itemName);
if (lastUpdateTimeStamp == null) {
lastUpdateTimeStamp = 0L;
}
long age = System.currentTimeMillis() - lastUpdateTimeStamp;
boolean needsUpdate = age >= refreshInterval;
if (needsUpdate) {
logger.debug("item '{}' is about to be refreshed now", itemName);
int consumptionValue = -1;
if (itemConf.consumption == null || itemConf.consumption.equals(ConsumptionConfig.OUTPUT_CURRENT)) {
itemConf.consumption = ConsumptionConfig.ACTIVE_POWER;
}
switch(itemConf.consumption) {
case ACTIVE_POWER:
List<CachedMeteringValue> consumptionList = digitalSTROM.getLatest(getSessionToken(), MeteringTypeEnum.consumption, ".meters(" + itemConf.dsmid.getValue().toLowerCase() + ")", null);
if (consumptionList != null) {
consumptionValue = 0;
for (CachedMeteringValue value : consumptionList) {
consumptionValue += value.getValue();
}
}
break;
case ELECTRIC_METER:
List<CachedMeteringValue> energyList = digitalSTROM.getLatest(getSessionToken(), MeteringTypeEnum.energy, ".meters(" + itemConf.dsmid.getValue().toLowerCase() + ")", MeteringUnitsEnum.Wh);
if (energyList != null) {
consumptionValue = 0;
for (CachedMeteringValue value : energyList) {
consumptionValue += value.getValue();
}
}
break;
default:
break;
}
org.openhab.core.types.State state = UnDefType.NULL;
if (consumptionValue != -1) {
state = new DecimalType(consumptionValue);
}
if (state != null) {
eventPublisher.postUpdate(itemName, state);
}
lastUpdateMap.put(itemName, System.currentTimeMillis());
}
}
for (DigitalSTROMBindingConfig itemConf : provider.getAllDeviceConsumptionItems()) {
String itemName = itemConf.itemName;
int refreshInterval = itemConf.timeinterval;
Long lastUpdateTimeStamp = lastUpdateMap.get(itemName);
if (lastUpdateTimeStamp == null) {
lastUpdateTimeStamp = 0L;
}
long age = System.currentTimeMillis() - lastUpdateTimeStamp;
boolean needsUpdate = age >= refreshInterval;
if (needsUpdate) {
logger.debug("item '{}' is about to be refreshed now", itemName);
Device device = getDsidToDeviceMap().get(itemConf.dsid.getValue());
if (device != null) {
if (itemConf.sensor == null) {
SensorIndexEnum sensorIndex = null;
try {
sensorIndex = SensorIndexEnum.valueOf(itemConf.consumption.name());
} catch (Exception e) {
sensorIndex = SensorIndexEnum.ACTIVE_POWER;
}
addLowPriorityJob(new DeviceConsumptionSensorJob(device, sensorIndex));
lastUpdateMap.put(itemName, System.currentTimeMillis());
} else {
SensorIndexEnum sensorIndex = null;
try {
sensorIndex = SensorIndexEnum.valueOf(itemConf.sensor.name());
} catch (Exception e) {
}
addHighPriorityJob(new DeviceSensorValueJob(device, sensorIndex));
}
}
}
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Keypad method handleEvent.
/**
* {@inheritDoc}
*/
@Override
public void handleEvent(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, DSCAlarmEvent event) {
APIMessage apiMessage = null;
int state;
if (event != null) {
apiMessage = event.getAPIMessage();
logger.debug("handleEvent(): Keypad Item Name: {}", item.getName());
if (config != null) {
if (config.getDSCAlarmItemType() != null) {
switch(config.getDSCAlarmItemType()) {
case KEYPAD_READY_LED:
case KEYPAD_ARMED_LED:
case KEYPAD_MEMORY_LED:
case KEYPAD_BYPASS_LED:
case KEYPAD_TROUBLE_LED:
case KEYPAD_PROGRAM_LED:
case KEYPAD_FIRE_LED:
case KEYPAD_BACKLIGHT_LED:
case KEYPAD_AC_LED:
state = Integer.parseInt(apiMessage.getAPIData().substring(1));
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(state));
}
if (item instanceof StringItem) {
publisher.postUpdate(item.getName(), new StringType(ledStates[state]));
}
break;
case KEYPAD_LCD_UPDATE:
case KEYPAD_LCD_CURSOR:
publisher.postUpdate(item.getName(), new StringType(apiMessage.getAPIData()));
break;
default:
logger.debug("handleEvent(): Keypad item not updated.");
break;
}
}
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Panel method refreshItem.
/**
* {@inheritDoc}
*/
@Override
public void refreshItem(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, int state, String description) {
logger.debug("refreshItem(): Panel Item Name: {}", item.getName());
String str = "";
OnOffType onOffType;
if (config != null) {
if (config.getDSCAlarmItemType() != null) {
switch(config.getDSCAlarmItemType()) {
case PANEL_CONNECTION:
publisher.postUpdate(item.getName(), new DecimalType(state));
break;
case PANEL_MESSAGE:
publisher.postUpdate(item.getName(), new StringType(description));
break;
case PANEL_SYSTEM_ERROR:
str = String.format("%03d: %s", state, ((state == 0) ? "No Error" : description));
publisher.postUpdate(item.getName(), new StringType(str));
break;
case PANEL_TIME:
str = getFormattedPanelTime(description);
publisher.postUpdate(item.getName(), new DateTimeType(str));
break;
case PANEL_TIME_STAMP:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_TIME_BROADCAST:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_COMMAND:
publisher.postUpdate(item.getName(), new DecimalType(state));
break;
case PANEL_TROUBLE_MESSAGE:
publisher.postUpdate(item.getName(), new StringType(description));
break;
case PANEL_TROUBLE_LED:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_SERVICE_REQUIRED:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_AC_TROUBLE:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_TELEPHONE_TROUBLE:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_FTC_TROUBLE:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_ZONE_FAULT:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_ZONE_TAMPER:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_ZONE_LOW_BATTERY:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_TIME_LOSS:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_FIRE_KEY_ALARM:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_PANIC_KEY_ALARM:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_AUX_KEY_ALARM:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
case PANEL_AUX_INPUT_ALARM:
onOffType = (state == 1) ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
break;
default:
logger.debug("refreshItem(): Panel item not updated.");
break;
}
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Panel method handleEvent.
/**
* {@inheritDoc}
*/
@Override
public void handleEvent(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, DSCAlarmEvent event) {
APIMessage apiMessage = null;
int apiCode = -1;
boolean boolState;
int state = 0;
OnOffType onOffType;
if (event != null) {
apiMessage = event.getAPIMessage();
apiCode = Integer.parseInt(apiMessage.getAPICode());
String str = "";
logger.debug("handleEvent(): Panel Item Name: {}", item.getName());
if (config != null) {
if (config.getDSCAlarmItemType() != null) {
switch(config.getDSCAlarmItemType()) {
case PANEL_CONNECTION:
publisher.postUpdate(item.getName(), new DecimalType(state));
break;
case PANEL_MESSAGE:
if (apiMessage != null) {
str = apiMessage.getAPIDescription();
}
publisher.postUpdate(item.getName(), new StringType(str));
break;
case PANEL_SYSTEM_ERROR:
int systemErrorCode = 0;
if (apiMessage != null) {
systemErrorCode = Integer.parseInt(apiMessage.getAPIData());
str = String.format("%03d: %s", systemErrorCode, apiMessage.getError());
publisher.postUpdate(item.getName(), new StringType(str));
}
break;
case PANEL_TROUBLE_MESSAGE:
if (apiMessage != null) {
str = apiMessage.getAPIDescription();
}
publisher.postUpdate(item.getName(), new StringType(str));
break;
case PANEL_TROUBLE_LED:
if (apiMessage != null) {
boolState = (apiCode == 840) ? true : false;
onOffType = boolState ? OnOffType.ON : OnOffType.OFF;
publisher.postUpdate(item.getName(), onOffType);
}
break;
case PANEL_TIME:
if (apiMessage != null) {
str = getFormattedPanelTime(apiMessage.getAPIData());
publisher.postUpdate(item.getName(), new DateTimeType(str));
}
break;
default:
logger.debug("handleEvent(): Panel item not updated.");
break;
}
}
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Partition method handleEvent.
/**
* {@inheritDoc}
*/
@Override
public void handleEvent(Item item, DSCAlarmBindingConfig config, EventPublisher publisher, DSCAlarmEvent event) {
int state = 0;
int apiCode = -1;
APIMessage apiMessage = null;
String str = "";
if (event != null) {
apiMessage = event.getAPIMessage();
apiCode = Integer.parseInt(apiMessage.getAPICode());
str = apiMessage.getAPIName();
logger.debug("handleEvent(): Partition Item Name: {}", item.getName());
if (config != null) {
if (config.getDSCAlarmItemType() != null) {
switch(config.getDSCAlarmItemType()) {
case PARTITION_STATUS:
switch(apiCode) {
case 650:
case 653:
case 654:
state = 1;
break;
case 651:
case 672:
case 673:
state = 0;
break;
default:
break;
}
publisher.postUpdate(item.getName(), new StringType(str));
break;
case PARTITION_ARM_MODE:
if (apiCode == 652) {
state = Integer.parseInt(apiMessage.getMode()) + 1;
}
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(state));
}
if (item instanceof StringItem) {
publisher.postUpdate(item.getName(), new StringType(str));
}
break;
case PARTITION_OPENING_CLOSING_MODE:
switch(apiCode) {
case 700:
state = 1;
break;
case 701:
state = 2;
break;
case 702:
state = 3;
break;
case 750:
state = 4;
break;
case 751:
state = 5;
break;
default:
state = 0;
str = "";
break;
}
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(state));
}
if (item instanceof StringItem) {
publisher.postUpdate(item.getName(), new StringType(str));
}
break;
default:
logger.debug("handleEvent(): Partition item not updated.");
break;
}
}
}
}
}
Aggregations