Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String DataType #12

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/fastcs/backends/epics/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
SignalRW,
SignalW,
SignalX,
TextFormat,
TextRead,
TextWrite,
Tree,
WriteWidget,
)

from fastcs.attributes import Attribute, AttrR, AttrRW, AttrW
from fastcs.datatypes import Bool, DataType, Float, Int
from fastcs.datatypes import Bool, DataType, Float, Int, String
from fastcs.exceptions import FastCSException
from fastcs.mapping import Mapping

Expand Down Expand Up @@ -62,6 +63,8 @@
return LED()
case Int() | Float():
return TextRead()
case String():
return TextRead(format=TextFormat.string)

Check warning on line 67 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L66-L67

Added lines #L66 - L67 were not covered by tests
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand All @@ -72,6 +75,8 @@
return CheckBox()
case Int() | Float():
return TextWrite()
case String():
return TextWrite(format=TextFormat.string)

Check warning on line 79 in src/fastcs/backends/epics/gui.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/gui.py#L78-L79

Added lines #L78 - L79 were not covered by tests
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand Down
8 changes: 7 additions & 1 deletion src/fastcs/backends/epics/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from fastcs.attributes import AttrR, AttrRW, AttrW
from fastcs.backend import Backend
from fastcs.datatypes import Bool, DataType, Float, Int
from fastcs.datatypes import Bool, DataType, Float, Int, String
from fastcs.exceptions import FastCSException
from fastcs.mapping import Mapping

Expand All @@ -25,6 +25,8 @@
return builder.longIn(pv_name)
case Float(prec):
return builder.aIn(pv_name, PREC=prec)
case String():
return builder.longStringIn(pv_name)

Check warning on line 29 in src/fastcs/backends/epics/ioc.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/ioc.py#L28-L29

Added lines #L28 - L29 were not covered by tests
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand Down Expand Up @@ -54,6 +56,10 @@
return builder.aOut(
pv_name, always_update=True, on_update=on_update, PREC=prec
)
case String():
return builder.longStringOut(

Check warning on line 60 in src/fastcs/backends/epics/ioc.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/backends/epics/ioc.py#L59-L60

Added lines #L59 - L60 were not covered by tests
pv_name, always_update=True, on_update=on_update
)
case _:
raise FastCSException(f"Unsupported type {type(datatype)}: {datatype}")

Expand Down
9 changes: 8 additions & 1 deletion src/fastcs/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from typing import Awaitable, Callable, Generic, TypeVar

T = TypeVar("T", int, float, bool)
T = TypeVar("T", int, float, bool, str)
ATTRIBUTE_TYPES: tuple[type] = T.__constraints__ # type: ignore


Expand Down Expand Up @@ -42,3 +42,10 @@
@property
def dtype(self) -> type[bool]:
return bool


@dataclass(frozen=True)
class String(DataType[str]):
@property
def dtype(self) -> type[str]:
return str

Check warning on line 51 in src/fastcs/datatypes.py

View check run for this annotation

Codecov / codecov/patch

src/fastcs/datatypes.py#L51

Added line #L51 was not covered by tests
Loading