use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Iec6205621MeterBinding method execute.
/**
* @{inheritDoc
*/
@Override
protected void execute() {
// the frequently executed code (polling) goes here ...
Map<String, Map<String, DataSet>> cache = new HashMap<String, Map<String, DataSet>>();
for (Iec6205621MeterBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
for (Entry<String, Meter> entry : meterDeviceConfigurtions.entrySet()) {
Meter reader = entry.getValue();
String meterName = provider.getMeterName(itemName);
if (meterName != null && meterName.equals(entry.getKey())) {
Map<String, DataSet> dataSets;
if ((dataSets = cache.get(meterName)) == null) {
if (logger.isDebugEnabled()) {
logger.debug("Read meter: {}; {}", meterName, reader.getConfig().getSerialPort());
}
dataSets = reader.read();
cache.put(meterName, dataSets);
}
String obis = provider.getObis(itemName);
if (obis != null && dataSets.containsKey(obis)) {
DataSet dataSet = dataSets.get(obis);
if (logger.isDebugEnabled()) {
logger.debug("Updating item {} with OBIS code {} and value {}", itemName, obis, dataSet.getValue());
}
Class<? extends Item> itemType = provider.getItemType(itemName);
if (itemType.isAssignableFrom(NumberItem.class)) {
eventPublisher.postUpdate(itemName, new DecimalType(dataSet.getValue()));
}
if (itemType.isAssignableFrom(StringItem.class)) {
String value = dataSet.getValue();
eventPublisher.postUpdate(itemName, new StringType(value));
}
}
}
}
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class HueBinding method execute.
/**
* Get current hue settings of the bulbs and update the items that are connected with the bulb.
* The refreshinterval determines the polling frequency.
*/
@Override
public void execute() {
if (activeBridge != null) {
// Get settings and update the bulbs
// Observation : If the power of a hue lamp is removed, the status is not updated in hue hub.
// The heartbeat functionality should fix this, but
logger.debug("Start Hue data refresh");
HueSettings settings = activeBridge.getSettings();
if (settings == null) {
logger.warn("Hue settings were null, maybe misconfigured bridge IP.");
return;
} else if (!settings.isAuthorized()) {
logger.warn("openHAB not authorized to access Hue bridge");
return;
}
Set<String> keys = settings.getKeys();
for (String key : keys) {
try {
HueBulb bulb = bulbCache.get(key);
if (bulb == null) {
bulb = new HueBulb(activeBridge, key, settings);
bulbCache.put(key, bulb);
}
bulb.getStatus(settings);
} catch (NumberFormatException e) {
logger.warn("lights index {} is not a number", key);
}
}
// Multiple items of different types can be linked to one bulb.
for (HueBindingProvider provider : this.providers) {
for (String hueItemName : provider.getInBindingItemNames()) {
HueBindingConfig deviceConfig = getConfigForItemName(hueItemName);
if (deviceConfig != null) {
HueBulb bulb = bulbCache.get(deviceConfig.getDeviceId());
if (bulb != null) {
//
if ((bulb.getIsOn() == true) && (bulb.getIsReachable() == true)) {
if ((deviceConfig.itemStateOnOffType == null) || (deviceConfig.itemStateOnOffType.equals(OnOffType.ON) == false)) {
eventPublisher.postUpdate(hueItemName, OnOffType.ON);
deviceConfig.itemStateOnOffType = OnOffType.ON;
}
} else {
if ((deviceConfig.itemStateOnOffType == null) || (deviceConfig.itemStateOnOffType.equals(OnOffType.OFF) == false)) {
eventPublisher.postUpdate(hueItemName, OnOffType.OFF);
deviceConfig.itemStateOnOffType = OnOffType.OFF;
}
}
if (deviceConfig.getType().equals(BindingType.brightness)) {
if ((bulb.getIsOn() == true) && (bulb.getIsReachable() == true)) {
// Only postUpdate when bulb is on, otherwise dimmer item is not retaining state and
// shows to max brightness value
PercentType newPercent = new PercentType((int) Math.round((bulb.getBrightness() * (double) 100) / HueBulb.MAX_BRIGHTNESS));
if ((deviceConfig.itemStatePercentType == null) || (deviceConfig.itemStatePercentType.equals(newPercent) == false)) {
eventPublisher.postUpdate(hueItemName, newPercent);
deviceConfig.itemStatePercentType = newPercent;
}
}
} else if (deviceConfig.getType().equals(BindingType.rgb)) {
if ((bulb.getIsOn() == true) && (bulb.getIsReachable() == true)) {
// Only postUpdate when bulb is on, otherwise color item is not retaining state and
// shows to max brightness value
DecimalType decimalHue = new DecimalType(bulb.getHue() / (double) 182);
PercentType percentBrightness = new PercentType((int) Math.round((bulb.getBrightness() * (double) 100) / HueBulb.MAX_BRIGHTNESS));
PercentType percentSaturation = new PercentType((int) Math.round((bulb.getSaturation() * (double) 100) / HueBulb.MAX_SATURATION));
HSBType newHsb = new HSBType(decimalHue, percentSaturation, percentBrightness);
if ((deviceConfig.itemStateHSBType == null) || (deviceConfig.itemStateHSBType.equals(newHsb) == false)) {
eventPublisher.postUpdate(hueItemName, newHsb);
deviceConfig.itemStateHSBType = newHsb;
}
}
}
}
}
}
}
logger.debug("Done Hue data refresh.");
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class HeatPumpBinding method internalReceiveCommand.
@Override
protected void internalReceiveCommand(String itemName, Command command) {
HeatPumpGenericBindingProvider provider = findFirstProvider();
if (provider != null) {
HeatPumpBindingConfig bindingConfig = provider.getHeatPumpBindingConfig(itemName);
HeatpumpCommandType commandType = bindingConfig.getType();
switch(commandType) {
case TYPE_HEATING_OPERATION_MODE:
if (command instanceof DecimalType) {
int value = ((DecimalType) command).intValue();
HeatpumpOperationMode mode = HeatpumpOperationMode.fromValue(value);
if (mode != null) {
if (sendParamToHeatpump(PARAM_HEATING_OPERATION_MODE, mode.getValue())) {
logger.info("Heatpump heating operation mode set to {}.", mode.name());
}
} else {
logger.warn("Heatpump heating operation mode with value {} is unknown.", value);
}
} else {
logger.warn("Heatpump heating operation mode item {} must be from type:{}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_HEATING_TEMPERATURE:
if (command instanceof DecimalType) {
float temperature = ((DecimalType) command).floatValue();
int value = (int) (temperature * 10.);
if (sendParamToHeatpump(PARAM_HEATING_TEMPERATURE, value)) {
logger.info("Heatpump heating temperature set to {}.", temperature);
}
} else {
logger.warn("Heatpump heating temperature item {} must be from type:{}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_WARMWATER_OPERATION_MODE:
if (command instanceof DecimalType) {
int value = ((DecimalType) command).intValue();
HeatpumpOperationMode mode = HeatpumpOperationMode.fromValue(value);
if (mode != null) {
if (sendParamToHeatpump(PARAM_WARMWATER_OPERATION_MODE, mode.getValue())) {
logger.info("Heatpump warmwater operation mode set to: {}. ", mode.name());
}
} else {
logger.warn("Heatpump warmwater operation mode with value {} is unknown.", value);
}
} else {
logger.warn("Heatpump warmwater operation mode item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_WARMWATER_TEMPERATURE:
if (command instanceof DecimalType) {
float temperature = ((DecimalType) command).floatValue();
int value = (int) (temperature * 10.);
if (sendParamToHeatpump(PARAM_WARMWATER_TEMPERATURE, value)) {
logger.info("Heatpump warmwater temperature set to {}.", temperature);
}
} else {
logger.warn("Heatpump warmwater temperature item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_COOLING_OPERATION_MODE:
if (command instanceof DecimalType) {
int value = ((DecimalType) command).intValue();
HeatpumpCoolingOperationMode mode = HeatpumpCoolingOperationMode.fromValue(value);
if (mode != null) {
if (sendParamToHeatpump(PARAM_COOLING_OPERATION_MODE, mode.getValue())) {
logger.info("Heatpump cooling operation mode set to {}.", mode.name());
}
} else {
logger.warn("Heatpump cooling operation mode with value {} is unknown.", value);
}
} else {
logger.warn("Heatpump cooling operation mode item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_COOLING_RELEASE_TEMPERATURE:
if (command instanceof DecimalType) {
float temperature = ((DecimalType) command).floatValue();
int value = (int) (temperature * 10.);
if (sendParamToHeatpump(PARAM_COOLING_RELEASE_TEMP, value)) {
logger.info("Heatpump cooling release temperature set to {}.", temperature);
}
} else {
logger.warn("Heatpump cooling release temperature item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_COOLING_INLET_TEMP:
if (command instanceof DecimalType) {
float temperature = ((DecimalType) command).floatValue();
int value = (int) (temperature * 10.);
if (sendParamToHeatpump(PARAM_COOLING_INLET_TEMP, value)) {
logger.info("Heatpump cooling target temp MK1 set to {}.", temperature);
}
} else {
logger.warn("Heatpump cooling target temp MK1 item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_COOLING_START_AFTER_HOURS:
if (command instanceof DecimalType) {
float hours = ((DecimalType) command).floatValue();
int value = (int) (hours * 10.);
if (sendParamToHeatpump(PARAM_COOLING_START, value)) {
logger.info("Heatpump cooling start after hours set to {}.", hours);
}
} else {
logger.warn("Heatpump cooling start after hours item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
case TYPE_COOLING_STOP_AFTER_HOURS:
if (command instanceof DecimalType) {
float hours = ((DecimalType) command).floatValue();
int value = (int) (hours * 10.);
if (sendParamToHeatpump(PARAM_COOLING_STOP, value)) {
logger.info("Heatpump cooling stop after hours set to {}.", hours);
}
} else {
logger.warn("Heatpump cooling stop after hours item {} must be from type: {}.", itemName, DecimalType.class.getSimpleName());
}
break;
default:
}
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Area method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int setting = 0;
String str = "";
switch(config.getObjectType()) {
case AREA_ENTRY_TIMER:
setting = properties.getEntryTimer();
break;
case AREA_EXIT_TIMER:
setting = properties.getExitTimer();
break;
case AREA_STATUS_ENTRY_DELAY:
setting = properties.getEntryDelay();
break;
case AREA_STATUS_EXIT_DELAY:
setting = properties.getExitDelay();
break;
case AREA_STATUS_MODE:
setting = properties.getMode();
str = omni ? (setting < omniText.length ? omniText[setting] : "Unknown") : (setting < luminaText.length ? luminaText[setting] : "Unknown");
break;
case AREA_STATUS_ALARM:
setting = properties.getAlarms();
for (int i = 0; i < alarms.length; i++) {
if (((setting >> i) & 1) > 0) {
if (str.length() > 0) {
str += " | ";
}
str += alarms[i];
}
}
break;
default:
break;
}
logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(setting));
} else if (item instanceof StringItem) {
publisher.postUpdate(item.getName(), new StringType(str));
}
}
use of org.openhab.core.library.types.DecimalType in project openhab1-addons by openhab.
the class Thermostat method updateItem.
@Override
public void updateItem(Item item, OmniLinkBindingConfig config, EventPublisher publisher) {
int setting = 0;
String mode = null;
switch(config.getObjectType()) {
case THERMO_COOL_POINT:
setting = celsius ? MessageUtils.omniToC(properties.getCoolSetpoint()) : MessageUtils.omniToF(properties.getCoolSetpoint());
break;
case THERMO_TEMP:
setting = celsius ? MessageUtils.omniToC(properties.getTemperature()) : MessageUtils.omniToF(properties.getTemperature());
break;
case THERMO_HEAT_POINT:
setting = celsius ? MessageUtils.omniToC(properties.getHeatSetpoint()) : MessageUtils.omniToF(properties.getHeatSetpoint());
break;
case THERMO_FAN_MODE:
setting = properties.isFan() ? 1 : 0;
break;
case THERMO_HOLD_MODE:
setting = properties.isHold() ? 1 : 0;
break;
case THERMO_SYSTEM_MODE:
setting = properties.getMode();
if (setting < MODES.length) {
mode = MODES[setting];
}
break;
default:
return;
}
logger.debug("updating item {} for type {} to {}", item.getName(), config.getObjectType(), setting);
if (item instanceof NumberItem) {
publisher.postUpdate(item.getName(), new DecimalType(setting));
} else if (item instanceof SwitchItem) {
publisher.postUpdate(item.getName(), setting > 0 ? OnOffType.ON : OnOffType.OFF);
} else if (item instanceof StringItem && mode != null) {
publisher.postUpdate(item.getName(), new StringType(mode));
}
}
Aggregations