Skip to content
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
16 changes: 12 additions & 4 deletions src/fastcs/attributes/attr_r.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class AttrR(Attribute[DType_T, AttributeIORefT]):
"""A read-only ``Attribute``."""
"""A read-only ``Attribute``"""

def __init__(
self,
Expand All @@ -44,7 +44,7 @@ def get(self) -> DType_T:
"""Get the cached value of the attribute."""
return self._value

async def update(self, value: DType_T) -> None:
async def update(self, value: Any) -> None:
"""Update the value of the attibute

This sets the cached value of the attribute presented in the API. It should
Expand All @@ -54,8 +54,16 @@ async def update(self, value: DType_T) -> None:
To request a change to the setpoint of the attribute, use the ``put`` method,
which will attempt to apply the change to the underlying source.

Args:
value: The new value of the attribute

Raises:
ValueError: If the value fails to be validated to DType_T

"""
self.log_event("Attribute set", attribute=self, value=value)
self.log_event(
"Attribute set", value=value, value_type=type(value), attribute=self
)

self._value = self._datatype.validate(value)

Expand All @@ -66,7 +74,7 @@ async def update(self, value: DType_T) -> None:
)
except Exception as e:
logger.opt(exception=e).error(
"On update callback failed", attribute=self, value=value
"On update callbacks failed", attribute=self, value=value
)
raise

Expand Down
9 changes: 9 additions & 0 deletions src/fastcs/datatypes/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def validate(self, value: Any) -> DType_T:
modify the value passed in and help the cast succeed or after to perform further
validation of the coerced type.

Args:
value: The value to validate

Returns:
The validated value

Raises:
ValueError: If the value cannot be coerced

"""
if isinstance(value, self.dtype):
return value
Expand Down