Skip to content

Commit 82593a0

Browse files
committed
allowed initial value on attributes
1 parent 129288a commit 82593a0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/fastcs/attributes.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Updater(Protocol):
2727
"""Protocol for updating the cached readback value of an ``Attribute``."""
2828

2929
# If update period is None then the attribute will not be updated as a task.
30-
update_period: float | None
30+
update_period: float | None = None
3131

3232
async def update(self, controller: Any, attr: AttrR) -> None:
3333
pass
@@ -95,6 +95,7 @@ def __init__(
9595
access_mode=AttrMode.READ,
9696
group: str | None = None,
9797
handler: Updater | None = None,
98+
initial_value: T | None = None,
9899
allowed_values: list[T] | None = None,
99100
description: str | None = None,
100101
) -> None:
@@ -106,7 +107,7 @@ def __init__(
106107
allowed_values=allowed_values, # type: ignore
107108
description=description,
108109
)
109-
self._value: T = datatype.dtype()
110+
self._value: T = datatype.dtype() if initial_value is None else initial_value
110111
self._update_callback: AttrCallback[T] | None = None
111112
self._updater = handler
112113

@@ -177,7 +178,7 @@ def sender(self) -> Sender | None:
177178
return self._sender
178179

179180

180-
class AttrRW(AttrW[T], AttrR[T]):
181+
class AttrRW(AttrR[T], AttrW[T]):
181182
"""A read-write ``Attribute``."""
182183

183184
def __init__(
@@ -186,15 +187,17 @@ def __init__(
186187
access_mode=AttrMode.READ_WRITE,
187188
group: str | None = None,
188189
handler: Handler | None = None,
190+
initial_value: T | None = None,
189191
allowed_values: list[T] | None = None,
190192
description: str | None = None,
191193
) -> None:
192194
super().__init__(
193195
datatype, # type: ignore
194196
access_mode,
195-
group,
196-
handler,
197-
allowed_values, # type: ignore
197+
group=group,
198+
handler=handler,
199+
initial_value=initial_value,
200+
allowed_values=allowed_values, # type: ignore
198201
description=description,
199202
)
200203

0 commit comments

Comments
 (0)