@XmlElement public float getValue() { return ((FloatResource) res).getValue(); }
/** * Checks if limits of the sensor are violated. */ public boolean areLimitsViolated(SensorAlarmPattern sensor) { final float x = sensor.reading.getValue(); if (sensor.minReading.isActive()) { final float min = sensor.minReading.getValue(); if (x < min) return true; } if (sensor.maxReading.isActive()) { final float max = sensor.maxReading.getValue(); if (x > max) return true; } return false; }
/** * Get a String representation of a {@link FloatResource} value that is suitable for human reading. * This is similar to {@link #getValue(SingleValueResource)}, but allows in addition to specify a * maximum number of decimals. * @param resource * @param maxDecimals * a negative value to show all digits, or a non-negative value to specify the number of decimal * digits to be shown. * @return the formatted value */ public static String getValue(FloatResource resource, int maxDecimals) { final String format = maxDecimals >= 0 ? "%." + maxDecimals + "f" : "%f"; if (resource instanceof TemperatureResource) { return String.format(Locale.ENGLISH,format + "°C", ((TemperatureResource) resource).getCelsius()); } else if (resource instanceof PhysicalUnitResource) { return String.format(Locale.ENGLISH,format + " " + ((PhysicalUnitResource) resource).getUnit(), resource.getValue()); } else return String.format(Locale.ENGLISH,format, resource.getValue()); }
@Override protected String format(V resource, Locale locale) { final String output; if (resource instanceof FloatResource) { final int nrDecimals = this.nrDecimals; if (nrDecimals < 0) output = String.format(Locale.ENGLISH, "%f", ((FloatResource) resource).getValue()); else output = ValueResourceUtils.getValue((FloatResource) resource, nrDecimals); // default; override in derived class, if necessary // FIXME or use parameter? } else output = ValueResourceUtils.getValue(resource); return output; }
public void onGET(OgemaHttpRequest req) { FloatResource source = getResource(sva, req, null); if ((source == null)||(!source.isActive())) { myLabel.setText("n.a.", req); return; } String val; if(format != null) { val = String.format(format, source.getValue()); } else { val = String.format("%.1f", source.getValue()); } myLabel.setText(val, req); } };
public SingleRoomSimulationImpl(RoomsimulationServicePattern roomPattern, RoomSimConfigPattern configPattern, OgemaLogger logger) { this.roomPattern = roomPattern; this.configPattern = configPattern; this.logger = logger; calc = new HumdityCalculator(configPattern.simulatedHumidity.getValue(), configPattern.simulatedTemperature.getKelvin()); }
@Override public void resourceChanged(SingleValueResource resource) { float factor = 1; float offset = 0; if (pattern.scalingFactor.isActive()) factor = pattern.scalingFactor.getValue(); if (pattern.valueOffset.isActive()) offset = pattern.valueOffset.getValue(); try { ca.setChannelValue(channelConfiguration, transformBack(resource, factor, offset)); } catch (ChannelAccessException e) { logger.error("Could not set new value for channel " + channelConfiguration + ", resource " + resource,e); } }
private boolean filterSatisfied(float value, Filter filter) { if (filter == null || !filter.isActive()) return true; if (filter instanceof RangeFilter) { RangeFilter rfilter = (RangeFilter) filter; FloatResource ll = rfilter.range().lowerLimit(); FloatResource ul = rfilter.range().upperLimit(); if ((ll.isActive() && ll.getValue() > value) || (ul.isActive() && ul.getValue() < value)) { logger.debug("Filter not satisfied for resource {}. Boundaries: {} - {}, actual value: {}", target, ll .getValue(), ul.getValue(), value); return false; } } return true; }
public static String getValue(SingleValueResource resource) { if (resource instanceof StringResource) { return ((StringResource) resource).getValue(); } else if (resource instanceof FloatResource) { return String.valueOf(((FloatResource) resource).getValue()); } else if (resource instanceof IntegerResource) { return String.valueOf(((IntegerResource) resource).getValue()); } else if (resource instanceof BooleanResource) { return String.valueOf(((BooleanResource) resource).getValue()); } else if (resource instanceof TimeResource) { return String.valueOf(((TimeResource) resource).getValue()); } else throw new RuntimeException(); } }
private static String getResourceValueSimple(ValueResource res) { String value; if (res instanceof StringResource) value = ((StringResource) res).getValue(); else if (res instanceof IntegerResource) value = String.valueOf(((IntegerResource) res).getValue()); else if (res instanceof FloatResource) value = String.valueOf(((FloatResource) res).getValue()); else if (res instanceof TimeResource) value = String.valueOf(((TimeResource) res).getValue()); else if (res instanceof BooleanResource) value = String.valueOf(((BooleanResource) res).getValue()); else if (res instanceof ByteArrayResource) value = DatatypeConverter.printHexBinary(((ByteArrayResource) res).getValues()); else throw new IllegalArgumentException("Unexpected resource type"); return value; }
public static String valueString(Resource res) { String val; switch (res.getResourceType().getSimpleName()) { case "BooleanResource": val = Boolean.toString(((BooleanResource) res).getValue()); break; case "FloatResource": val = Float.toString(((FloatResource) res).getValue()); break; case "IntegerResource": val = Integer.toString(((IntegerResource) res).getValue()); break; case "StringResource": val = ((StringResource) res).getValue(); break; case "TimeResource": val = Long.toString(((TimeResource) res).getValue()); break; default: val = "..."; } return val; }
@Override public void onGET(OgemaHttpRequest req) { FloatResource source = getResource(sva, req, FloatResource.class); if((source instanceof TemperatureResource)&&(mode == 0)) myField.setValue(((TemperatureResource)source).getCelsius()+"",req); else myField.setValue(source.getValue()+"",req); }
/** * Tries to retrieve a float representation of the value of <code>resource</code>. If this is * not possible, for instance, if <code>resource</code> is a {@link StringResource} and its value is * not parsable as float, then a {@link NumberFormatException} is thrown. * @param resource * @throws NumberFormatException */ public static float getFloatValue(SingleValueResource resource) throws NumberFormatException { if (resource instanceof FloatResource) { return ((FloatResource) resource).getValue(); } else if (resource instanceof IntegerResource) { return ((IntegerResource) resource).getValue(); } else if (resource instanceof BooleanResource) { return (((BooleanResource) resource).getValue() ? 1 : 0); } else if (resource instanceof TimeResource) { return ((TimeResource) resource).getValue(); } else if (resource instanceof StringResource) { return Float.parseFloat(((StringResource) resource).getValue()); // throws NumberFormatException } else throw new RuntimeException(); }
final void resourceChanged(final long t, final SingleValueResource resource) { final Value v; if (resource instanceof FloatResource) v = new FloatValue(((FloatResource) resource).getValue()); else if (resource instanceof IntegerResource) v = new IntegerValue(((IntegerResource) resource).getValue()); else if (resource instanceof BooleanResource) v = new BooleanValue(((BooleanResource) resource).getValue()); else if (resource instanceof TimeResource) v = new LongValue(((TimeResource) resource).getValue()); else throw new IllegalArgumentException(); values.add(new SampledValue(v, t, Quality.GOOD)); }
@Override public void resourceChanged(Resource res) { logger.debug("OGEMA value changed for HomeMatic {}/{}", address, valueKey); if (res instanceof FloatResource) { float value = ((FloatResource) res).getValue(); conn.performSetValue(address, valueKey, value); } else if (res instanceof IntegerResource) { int value = ((IntegerResource) res).getValue(); conn.performSetValue(address, valueKey, value); } else if (res instanceof StringResource) { String value = ((StringResource) res).getValue(); conn.performSetValue(address, valueKey, value); } else if (res instanceof BooleanResource) { boolean value = ((BooleanResource) res).getValue(); conn.performSetValue(address, valueKey, value); } else { LoggerFactory.getLogger(SwitchChannel.class).warn("HomeMatic parameter resource is of unsupported type: {}", res.getResourceType()); } } }
@Override public void channelEvent(EventType type, List<SampledValueContainer> channels) { logger.trace("Channel event for {}", pattern.target); for (SampledValueContainer container: channels) { if (container.getChannelLocator().equals(channelConfiguration.getChannelLocator())) { float factor = 1; float offset = 0; if (pattern.scalingFactor.isActive()) factor = pattern.scalingFactor.getValue(); if (pattern.valueOffset.isActive()) offset = pattern.valueOffset.getValue(); Value value = transform(container.getSampledValue().getValue(), factor, offset); ValueResourceUtils.setValue(pattern.target, value); pattern.target.activate(false); } } }
public static Value getValue(SingleValueResource resource) { if (resource instanceof FloatResource) { return new FloatValue(((FloatResource) resource).getValue()); } else if (resource instanceof IntegerResource) { return new IntegerValue(((IntegerResource) resource).getValue()); } else if (resource instanceof BooleanResource) { return new BooleanValue(((BooleanResource) resource).getValue()); } else if (resource instanceof TimeResource) { return new LongValue(((TimeResource) resource).getValue()); } else throw new RuntimeException(); }
/** * Update the rules how the threshold shall be calculated, including the * question if the target resource should be set active or inactive. */ private void updateAndEnforceRules() { m_active = m_config.source().isActive(); m_threshold = m_config.threshold().getValue(); m_invert = m_config.invert().getValue(); m_equalityExceeds = m_config.equalityExceeds().getValue(); enforceRules(); }
/** * Creates an instance of the configuration object from an existing configuration. */ public ThresholdConfigurationImpl(ResourceManipulatorImpl base, ThresholdModel configResource) { m_base = base; m_appMan = base.getApplicationManager(); m_source = configResource.source(); m_threshold = configResource.threshold().getValue(); m_target = configResource.target(); m_equalityExceeds = configResource.equalityExceeds().getValue(); m_invert = configResource.invert().getValue(); m_config = configResource; }
/** * Apply the threshold rule. */ private void enforceRules() { BooleanResource target = m_config.target(); if (!m_active) { target.deactivate(false); return; } final float value = m_config.source().getValue(); final boolean thresholdExceeded = (m_equalityExceeds) ? (value >= m_threshold) : (value > m_threshold); final boolean newState = (m_invert) ? (!thresholdExceeded) : thresholdExceeded; if (target.isActive()) { final boolean oldState = target.getValue(); if (oldState != newState) target.setValue(newState); } else { target.setValue(newState); target.activate(false); } lastExecTime = appMan.getFrameworkTime(); }