mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-21 00:40:01 +02:00
feat: adding support for enums
- handling fronend upates - adding serialization for DataService classes - adapting notification emission
This commit is contained in:
parent
f30cd15d3f
commit
e48e33c948
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import inspect
|
||||
from collections.abc import Callable
|
||||
from enum import Enum
|
||||
from itertools import chain
|
||||
from typing import Any
|
||||
|
||||
@ -517,6 +518,15 @@ class DataService(rpyc.Service):
|
||||
"readonly": prop.fset is None,
|
||||
"doc": inspect.getdoc(prop),
|
||||
}
|
||||
elif isinstance(value, Enum):
|
||||
result[key] = {
|
||||
"type": "Enum",
|
||||
"value": value.name,
|
||||
"enum": {
|
||||
name: member.value
|
||||
for name, member in value.__class__.__members__.items()
|
||||
},
|
||||
}
|
||||
else:
|
||||
result[key] = {
|
||||
"type": type(value).__name__,
|
||||
|
@ -3,6 +3,7 @@ import os
|
||||
import signal
|
||||
import threading
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from enum import Enum
|
||||
from types import FrameType
|
||||
from typing import Any, Optional
|
||||
|
||||
@ -147,7 +148,11 @@ class Server:
|
||||
"data": {
|
||||
"parent_path": parent_path,
|
||||
"name": name,
|
||||
"value": value,
|
||||
"value": value.name
|
||||
if isinstance(
|
||||
value, Enum
|
||||
) # enums are not JSON serializable
|
||||
else value,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -1,3 +1,4 @@
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any, TypedDict
|
||||
|
||||
@ -55,6 +56,10 @@ class WebAPI:
|
||||
attr = getattr(self.service, data["name"])
|
||||
if isinstance(attr, DataService):
|
||||
attr.apply_updates(data["value"])
|
||||
elif isinstance(attr, Enum):
|
||||
setattr(
|
||||
self.service, data["name"], attr.__class__[data["value"]["value"]]
|
||||
)
|
||||
else:
|
||||
setattr(self.service, data["name"], data["value"])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user