moves "Validating Property Setters" to docs

This commit is contained in:
Mose Müller
2024-08-19 15:52:08 +02:00
parent 9b8279da85
commit b0c3c4cad9
4 changed files with 45 additions and 45 deletions

View File

@ -12,4 +12,4 @@
[Customizing Web Interface]: ./user-guide/interaction/main.md#customization-options
[Task Management]: ./user-guide/Tasks.md
[Units]: ./getting-started.md#understanding-units-in-pydase
[Property Validation]: ./getting-started.md#using-validate_set-to-validate-property-setters
[Property Validation]: ./user-guide/Validating-Property-Setters.md

View File

@ -0,0 +1,38 @@
# Using `validate_set` to Validate Property Setters
The `validate_set` decorator ensures that a property setter reads back the set value using the property getter and checks it against the desired value.
This decorator can be used to validate that a parameter has been correctly set on a device within a specified precision and timeout.
The decorator takes two keyword arguments: `timeout` and `precision`. The `timeout` argument specifies the maximum time (in seconds) to wait for the value to be within the precision boundary.
If the value is not within the precision boundary after this time, an exception is raised.
The `precision` argument defines the acceptable deviation from the desired value.
If `precision` is `None`, the value must be exact.
For example, if `precision` is set to `1e-5`, the value read from the device must be within ±0.00001 of the desired value.
Heres how to use the `validate_set` decorator in a `DataService` class:
```python
import pydase
from pydase.observer_pattern.observable.decorators import validate_set
class Service(pydase.DataService):
def __init__(self) -> None:
super().__init__()
self._device = RemoteDevice() # dummy class
@property
def value(self) -> float:
# Implement how to get the value from the remote device...
return self._device.value
@value.setter
@validate_set(timeout=1.0, precision=1e-5)
def value(self, value: float) -> None:
# Implement how to set the value on the remote device...
self._device.value = value
if __name__ == "__main__":
pydase.Server(service=Service()).run()
```