Validate that value is a valid battery level integer.
966306
def is_battery_level(value):
    """"""
    try:
        value = percent_int(value)
        return value
    except vol.Invalid:
        _LOGGER.warning(
            '%s is not a valid battery level, falling back to battery level 0',
            value)
        return 0
913461
def handle_battery_level(msg):
    """"""
    if not msg.gateway.is_sensor(msg.node_id):
        return None
    msg.gateway.sensors[msg.node_id].battery_level = msg.payload
    msg.gateway.alert(msg)
    return None
426131
def is_integer(self, value, strict=False):
        """"""
        if value is not None:
            if isinstance(value, numbers.Number):
                return
        value = stringify(value)
        if value is not None and value.isnumeric():
            return
        self.shout('value %r is not an integer', strict, value)
1165450
def validate(self, instance, value):
        """"""
        if isinstance(value, string_types):
            value = COLORS_NAMED.get(value, value)
            if value.upper() == 'RANDOM':
                value = random.choice(COLORS_20)
            value = value.upper().lstrip('#')
            if len(value) == 3:
                value = ''.join(v*2 for v in value)
            if len(value) != 6:
                self.error(instance, value, extra='Color must be known name '
                           'or a hex with 6 digits. e.g. "#FF0000"')
            try:
                value = [
                    int(value[i:i + 6 // 3], 16) for i in range(0, 6, 6 // 3)
                ]
            except ValueError:
                self.error(instance, value,
                           extra='Hex color must be base 16 (0-F)')
        if not isinstance(value, (list, tuple)):
            self.error(instance, value,
                       extra='Color must be a list or tuple of length 3')
        if len(value) != 3:
            self.error(instance, value, extra='Color must be length 3')
        for val in value:
            if not isinstance(val, integer_types) or not 0 <= val <= 255:
                self.error(instance, value,
                           extra='Color values must be ints 0-255.')
        return tuple(value)
1364298
public void validate() {
    if (policy == null) {
      if (value == 0) {
        policy = FillPolicy.ZERO;
      } else if (Double.isNaN(value)) {
        policy = FillPolicy.NOT_A_NUMBER;
      } else {
        policy = FillPolicy.SCALAR;
      }
    } else {
      switch (policy) {
      case NONE:
      case NOT_A_NUMBER:
        if (value != 0 && !Double.isNaN(value)) {
          throw new IllegalArgumentException(
              "The value for NONE and NAN must be NaN");
        }
        value = Double.NaN;
        break;
      case ZERO:
        if (value != 0) {
          throw new IllegalArgumentException("The value for ZERO must be 0");
        }
        value = 0;
        break;
      case NULL:
        if (value != 0 && !Double.isNaN(value)) {
          throw new IllegalArgumentException("The value for NULL must be 0");
        }
        value = Double.NaN;
        break;
      case SCALAR: // it CAN be zero
        break;
      }
    }
  }
192679
def validate(method):
    """"""

    @wraps(method)
    def mod_run(self, rinput):
        self.validate_input(rinput)
        #
        result = method(self, rinput)
        #
        self.validate_result(result)
        return result

    return mod_run
336350
def _is_valid_integer(self, inpt, metadata):
        """"""
        if not isinstance(inpt, int):
            return False
        if metadata.get_minimum_integer() and inpt < metadata.get_maximum_integer():
            return False
        if metadata.get_maximum_integer() and inpt > metadata.get_minimum_integer():
            return False
        if metadata.get_integer_set() and inpt not in metadata.get_integer_set():
            return False
        else:
            return True
688428
def _validate(self):
        

        if self._state is not states.INITIAL:
            raise ValueError(obj=self._uid,
                             attribute='state',
                             expected_value=states.INITIAL,
                             actual_value=self._state)

        if not self._executable:
            raise MissingError(obj=self._uid,
                               missing_attribute='executable')
874141
def _validate_timeout(timeout, infinity_ok=False):
    
    if timeout is None:
        return

    if timeout == 'infinity':
        if infinity_ok:
            return
        else:
            raise ValueError(
                'timeout must be a positive integer '
                '("infinity" is not valid)')

    if isinstance(timeout, six.integer_types) and timeout > 0:
        return

    raise ValueError('timeout must be a positive integer')
1333964
def validate(self, value):
        """"""
        if value in list(self.choices.keys()):
            self._choice = value
            return True
        try:
            self._choice = list(self.choices.keys())[int(value)]
            return True
        except (ValueError, IndexError):
            self.error_message = '%s is not a valid choice.' % value
            return False
242568
public static void validate(BigInteger nummer, Ort ort) {
        if (nummer.compareTo(BigInteger.ONE) < 0) {
            throw new InvalidValueException(nummer, "number");
        }
        validate(ort);
    }
1144202
def is_valid_int(value):
        """"""
        if 0 <= value <= Parameter.MAX:  # This includes ON and OFF
            return True
        if value == Parameter.UNKNOWN_VALUE:
            return True
        if value == Parameter.CURRENT_POSITION:
            return True
        return False
733699
def validate(self, key, value):
    """"""
    if self._validator is not None:
      self._validator(key, value)
238419
def validate_resource(self, value):
        """"""

        def do_backoff(*args, **kwargs):
            """Call self._test_connection with exponential backoff, for self._max_tries attempts"""
            attempts = 0
            while True:
                try:
                    self._test_connection(*args, **kwargs)
                    break
                except ValidationError:
                    wait_secs = min(self._max_wait, 2 ** attempts)
                    attempts += 1
                    if attempts < self._max_tries:
                        time.sleep(wait_secs)
                    else:
                        raise

        do_backoff(value)
129817
def is_valid(number):
    """"""
    n = str(number)
    if not n.isdigit():
        return False
    return int(n[-1]) == get_check_digit(n[:-1])
816854
def __validInputs(self):
        """"""
        #if not isinstance(self.__column, Column):
        #    raise Sitools2Exception("column must be an instance of Column")
        try:
            float(self.__minVal)
        except ValueError as ex:
            raise Sitools2Exception(ex)
        try:
            float(self.__maxVal)
        except ValueError as ex:
            raise Sitools2Exception(ex)
        
        if float(self.__minVal) >= float(self.__maxVal):
            raise Sitools2Exception("maxVal must be superior to minVal")
549578
def _validate_int(name, value, limits=(), strip='%'):
    '''
    
    '''
    comment = ''
    # Must be integral
    try:
        if isinstance(value, string_types):
            value = value.strip(' ' + strip)
        value = int(value)
    except (TypeError, ValueError):
        comment += '{0} must be an integer '.format(name)
    # Must be in range
    else:
        if len(limits) == 2:
            if value < limits[0] or value > limits[1]:
                comment += '{0} must be in the range [{1[0]}, {1[1]}] '.format(name, limits)
    return value, comment