44from collections .abc import Callable
55from typing import Generic
66
7- from .attribute_io_ref import AttributeIORefT
8- from .datatypes import ATTRIBUTE_TYPES , AttrSetCallback , AttrUpdateCallback , DataType , T
7+ from fastcs .attribute_io_ref import AttributeIORefT
8+ from fastcs .datatypes import (
9+ ATTRIBUTE_TYPES ,
10+ AttrSetCallback ,
11+ AttrUpdateCallback ,
12+ DataType ,
13+ T ,
14+ )
15+ from fastcs .tracer import Tracer
916
1017ONCE = float ("inf" )
1118"""Special value to indicate that an attribute should be updated once on start up."""
1219
1320
14- class Attribute (Generic [T , AttributeIORefT ]):
21+ class Attribute (Generic [T , AttributeIORefT ], Tracer ):
1522 """Base FastCS attribute.
1623
1724 Instances of this class added to a ``Controller`` will be used by the FastCS class.
@@ -24,6 +31,8 @@ def __init__(
2431 group : str | None = None ,
2532 description : str | None = None ,
2633 ) -> None :
34+ super ().__init__ ()
35+
2736 assert issubclass (datatype .dtype , ATTRIBUTE_TYPES ), (
2837 f"Attr type must be one of { ATTRIBUTE_TYPES } , "
2938 "received type {datatype.dtype}"
@@ -73,6 +82,9 @@ def update_datatype(self, datatype: DataType[T]) -> None:
7382 for callback in self ._update_datatype_callbacks :
7483 callback (datatype )
7584
85+ def __repr__ (self ):
86+ return f"{ self .__class__ .__name__ } ({ self ._datatype } )"
87+
7688
7789class AttrR (Attribute [T , AttributeIORefT ]):
7890 """A read-only ``Attribute``."""
@@ -101,6 +113,8 @@ def get(self) -> T:
101113 return self ._value
102114
103115 async def set (self , value : T ) -> None :
116+ self .log_event ("Attribute set" , attribute = self , value = value )
117+
104118 self ._value = self ._datatype .validate (value )
105119
106120 if self ._on_set_callbacks is not None :
0 commit comments