src.bluetooth_sig.gatt.characteristics.pipeline.validation

Validation logic for characteristic values.

Provides range, type, and length validation with a three-level precedence system: descriptor Valid Range > class-level attributes > YAML-derived ranges.

Classes

Name

Description

CharacteristicValidator

Validates characteristic values against range, type, and length constraints.

Module Contents

class src.bluetooth_sig.gatt.characteristics.pipeline.validation.CharacteristicValidator(char: Any)

Validates characteristic values against range, type, and length constraints.

Uses a back-reference to the owning characteristic to access validation attributes (min_value, max_value, expected_length, etc.) and YAML-derived metadata. This class is an internal implementation detail of BaseCharacteristic and should not be used directly.

validate_length(data: bytes | bytearray) src.bluetooth_sig.types.data_types.ValidationAccumulator

Validate data length meets requirements.

Parameters:

data – The data to validate.

Returns:

ValidationAccumulator with errors if validation fails.

validate_range(value: Any, ctx: src.bluetooth_sig.gatt.context.CharacteristicContext | None = None) src.bluetooth_sig.types.data_types.ValidationAccumulator

Validate value is within min/max range.

Validation precedence:
  1. Descriptor Valid Range (if present in context) — most specific, device-reported

  2. Class-level validation attributes (min_value, max_value) — characteristic spec defaults

  3. YAML-derived value range from structure — Bluetooth SIG specification

Parameters:
  • value – The value to validate.

  • ctx – Optional characteristic context containing descriptors.

Returns:

ValidationAccumulator with errors if validation fails.

validate_type(value: Any) src.bluetooth_sig.types.data_types.ValidationAccumulator

Validate value type matches expected_type if specified.

Parameters:

value – The value to validate.

Returns:

ValidationAccumulator with errors if validation fails.