Utils¶
- class nirahmq.utils.BaseModel[source]¶
Bases:
BaseModelA customized
pydantic.BaseModelclass for use by the rest of the library.
- nirahmq.utils.clamp(val: T, min_: T, max_: T) T[source]¶
Clamp a value in the range \([min\_, max\_]\).
- Parameters:
val (T) – The value to be clamped
min_ (T) – The minimum allowed value (inclusive)
max_ (T) – The maximum allowed value (inclusive)
- Returns:
The clamped value
- Return type:
T
- nirahmq.utils.sanitize_string(string: str) str[source]¶
Sanitizes a string for use as an MQTT topic.
Note
The sanitization is not an MQTT restriction but a Home Assistant one.
- nirahmq.utils.Unset = _Unset.TOKEN¶
A custom singleton type used by to indicate a value is unset.
- utils.Optional = Optional¶
A custom type alias that marks a variable as of types
TorUnset.
- utils.Required = Required¶
A custom type used by
nirahmq.components.base.ComponentBaseto mark a class field as required during serialization.