WebThingsIO / webthing-arduino

Simple server for ESP8266, ESP32, Ethernet, or WiFi101-compatible boards compliant with Mozilla's proposed WoT API
Mozilla Public License 2.0
207 stars 78 forks source link

Thing minimum/maximum #87

Closed gigs2go closed 4 years ago

gigs2go commented 5 years ago

The current default values (in Thing.h) for minimum and maximum are :

  double minimum = 0;
  double maximum = -1;

In order to check a new value is in range, I put (in ESPWebThingAdapter::setThingProperty):

    case NUMBER: {
      ThingPropertyValue value;
      value.number = newValue.as<double>();
      // Added to account for min/max range - just ignores invalid values
      if ( value.number >= property->minimum && value.number <= property->maximum ) {
          property->setValue(value);
      }
      break;
    }

I believe the default values for min/max should be :

  double minimum = -DBL_MAX;
  double maximum = DBL_MAX;

so the above logic will work even if the values are not set explicitly.

mrstegeman commented 4 years ago

It seems like the code which uses the library should be the one validating the value before setting it, since it is also that code which is defining the min/max.