mirror of
https://github.com/tiqi-group/pydase_service_base.git
synced 2025-04-20 00:20:01 +02:00
updates to pydase version 0.8.0
This commit is contained in:
parent
c02a979be4
commit
2eb5cba02a
@ -5,18 +5,11 @@ from typing import Any
|
|||||||
import pydase
|
import pydase
|
||||||
import pydase.components
|
import pydase.components
|
||||||
import pydase.units as u
|
import pydase.units as u
|
||||||
|
import pydase.version
|
||||||
import tiqi_rpc
|
import tiqi_rpc
|
||||||
from pydase.data_service.data_service_observer import DataServiceObserver
|
from pydase.data_service.data_service_observer import DataServiceObserver
|
||||||
import pydase.version
|
from pydase.utils.helpers import get_object_attr_from_path # type: ignore
|
||||||
|
from pydase.utils.serialization.types import SerializedObject
|
||||||
if pydase.version.__major__ == 0 and pydase.version.__minor__ > 7:
|
|
||||||
from pydase.utils.helpers import get_object_attr_from_path
|
|
||||||
else:
|
|
||||||
from pydase.utils.helpers import get_object_attr_from_path_list
|
|
||||||
|
|
||||||
def get_object_attr_from_path(target_obj: Any, path: str) -> Any:
|
|
||||||
return get_object_attr_from_path_list(target_obj, path.split("."))
|
|
||||||
|
|
||||||
|
|
||||||
from pydase_service_base.ionizer_interface.rpc_interface import RPCInterface
|
from pydase_service_base.ionizer_interface.rpc_interface import RPCInterface
|
||||||
|
|
||||||
@ -43,19 +36,19 @@ class IonizerServer:
|
|||||||
self.server.install_signal_handlers = lambda: None # type: ignore
|
self.server.install_signal_handlers = lambda: None # type: ignore
|
||||||
|
|
||||||
def notify_ionizer(
|
def notify_ionizer(
|
||||||
self, full_access_path: str, value: Any, cached_value: dict[str, Any]
|
self, full_access_path: str, value: Any, cached_value: SerializedObject
|
||||||
) -> None:
|
) -> None:
|
||||||
"""This function notifies Ionizer about changed values.
|
"""This function notifies Ionizer about changed values.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
- parent_path (str): The parent path of the parameter.
|
full_access_path (str):
|
||||||
- attr_name (str): The name of the changed parameter.
|
The full access path of the parameter.
|
||||||
- value (Any): The value of the parameter.
|
value (Any):
|
||||||
|
The new value of the parameter.
|
||||||
|
cached_value (SerializedObject):
|
||||||
|
The serialized representation of the cached parameter.
|
||||||
"""
|
"""
|
||||||
parent_path_list, attr_name = (
|
attr_name = full_access_path.split(".")[-1]
|
||||||
full_access_path.split(".")[:-1],
|
|
||||||
full_access_path.split(".")[-1],
|
|
||||||
) # without classname
|
|
||||||
if isinstance(value, Enum):
|
if isinstance(value, Enum):
|
||||||
value = value.value
|
value = value.value
|
||||||
if isinstance(value, u.Quantity):
|
if isinstance(value, u.Quantity):
|
||||||
|
@ -6,17 +6,9 @@ from pydase import DataService
|
|||||||
from pydase.components import NumberSlider
|
from pydase.components import NumberSlider
|
||||||
from pydase.data_service.data_service_observer import DataServiceObserver
|
from pydase.data_service.data_service_observer import DataServiceObserver
|
||||||
from pydase.units import Quantity
|
from pydase.units import Quantity
|
||||||
import pydase.version
|
from pydase.utils.helpers import get_object_attr_from_path
|
||||||
|
from pydase.utils.serialization.serializer import dump
|
||||||
if pydase.version.__major__ == 0 and pydase.version.__minor__ > 7:
|
from pydase.utils.serialization.types import SerializedObject
|
||||||
from pydase.utils.helpers import get_object_attr_from_path
|
|
||||||
else:
|
|
||||||
from pydase.utils.helpers import get_object_attr_from_path_list
|
|
||||||
|
|
||||||
def get_object_attr_from_path(target_obj: Any, path: str) -> Any:
|
|
||||||
return get_object_attr_from_path_list(target_obj, path.split("."))
|
|
||||||
|
|
||||||
|
|
||||||
from pydase.version import __version__
|
from pydase.version import __version__
|
||||||
|
|
||||||
|
|
||||||
@ -36,8 +28,8 @@ class RPCInterface:
|
|||||||
async def name(self) -> str:
|
async def name(self) -> str:
|
||||||
return self._service.__class__.__name__
|
return self._service.__class__.__name__
|
||||||
|
|
||||||
async def get_props(self) -> dict[str, Any]:
|
async def get_props(self) -> SerializedObject:
|
||||||
return self._service.serialize()["value"]
|
return self._service.serialize()["value"] # type: ignore
|
||||||
|
|
||||||
async def get_param(self, full_access_path: str) -> Any:
|
async def get_param(self, full_access_path: str) -> Any:
|
||||||
"""Returns the value of the parameter given by the full_access_path.
|
"""Returns the value of the parameter given by the full_access_path.
|
||||||
@ -84,7 +76,9 @@ class RPCInterface:
|
|||||||
elif isinstance(current_value, NumberSlider):
|
elif isinstance(current_value, NumberSlider):
|
||||||
full_access_path = full_access_path + "value"
|
full_access_path = full_access_path + "value"
|
||||||
|
|
||||||
self._state_manager.set_service_attribute_value_by_path(full_access_path, value)
|
self._state_manager.set_service_attribute_value_by_path(
|
||||||
|
full_access_path, dump(value)
|
||||||
|
)
|
||||||
|
|
||||||
async def remote_call(self, full_access_path: str, *args: Any) -> Any:
|
async def remote_call(self, full_access_path: str, *args: Any) -> Any:
|
||||||
method_object = get_object_attr_from_path(self._service, full_access_path)
|
method_object = get_object_attr_from_path(self._service, full_access_path)
|
||||||
|
@ -14,7 +14,7 @@ build-backend = "poetry.core.masonry.api"
|
|||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
confz = "^2.0.0"
|
confz = "^2.0.0"
|
||||||
pydase = ">=0.6.0"
|
pydase = ">=0.8.0"
|
||||||
|
|
||||||
# optional dependencies
|
# optional dependencies
|
||||||
tiqi-rpc = { git = "ssh://git@gitlab.phys.ethz.ch/tiqi-projects/tiqi-rpc-python.git", optional = true }
|
tiqi-rpc = { git = "ssh://git@gitlab.phys.ethz.ch/tiqi-projects/tiqi-rpc-python.git", optional = true }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user