Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Nov 1, 2024
1 parent 030a2e1 commit 609e0ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/fastcs_pandablocks/panda/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@


def _strip_description(description: str | None) -> str | None:
if description is None:
return description
return description[:MAXIMUM_DESCRIPTION_LENGTH]
return None if description is None else description[:MAXIMUM_DESCRIPTION_LENGTH]


class FieldController(SubController):
Expand Down Expand Up @@ -140,6 +138,7 @@ def __init__(
self,
panda_name: PandaName,
field_info: SubtypeTimeFieldInfo,
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Expand All @@ -163,6 +162,7 @@ def __init__(
self,
panda_name: PandaName,
field_info: SubtypeTimeFieldInfo,
initial_value: RawInitialValuesType,
):
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Expand Down Expand Up @@ -320,15 +320,17 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)

self.top_level_attribute = AttrRW(
String(),
description=_strip_description(bit_mux_field_info.description),
handler=DefaultFieldHandler(panda_name),
group=WidgetGroup.INPUTS.value,
initial_value=initial_values[panda_name],
)

self._additional_attributes["delay"] = AttrRW(
Float(),
Int(),
description="Clock delay on input.",
handler=DefaultFieldHandler(panda_name),
group=WidgetGroup.INPUTS.value,
Expand Down
35 changes: 14 additions & 21 deletions src/fastcs_pandablocks/types/_string_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
PANDA_SEPARATOR = "."


def _extract_number_at_of_string(string: str) -> tuple[str, int | None]:
def _extract_number_at_end_of_string(string: str) -> tuple[str, int | None]:
pattern = r"(\D+)(\d+)$"
match = re.match(pattern, string)
if match:
Expand Down Expand Up @@ -40,7 +40,7 @@ def _to_python_attribute_name(string: str):
return string.replace("-", "_").lower()


def _choose_sub_pv(sub_pv_1: T, sub_pv_2: T) -> T:
def _choose_sub_name(sub_pv_1: T, sub_pv_2: T) -> T:
if sub_pv_1 is not None and sub_pv_2 is not None:
if sub_pv_1 != sub_pv_2:
raise TypeError(
Expand All @@ -49,14 +49,6 @@ def _choose_sub_pv(sub_pv_1: T, sub_pv_2: T) -> T:
return sub_pv_2 or sub_pv_1


def _check_eq(sub_pv_1: T, sub_pv_2: T) -> bool:
if sub_pv_1 is not None and sub_pv_2 is not None:
return sub_pv_1 == sub_pv_2
elif sub_pv_1 and sub_pv_2 is None:
return False
return True


@dataclass(frozen=True)
class PandaName:
block: str | None = None
Expand Down Expand Up @@ -87,7 +79,7 @@ def from_string(cls, name: str):
return PandaName()

block, block_number, field, sub_field = None, None, None, None
block, block_number = _extract_number_at_of_string(split_name[0])
block, block_number = _extract_number_at_end_of_string(split_name[0])
field = split_name[1] if len(split_name) > 1 else None
sub_field = split_name[2] if len(split_name) > 2 else None

Expand All @@ -97,10 +89,10 @@ def from_string(cls, name: str):

def __add__(self, other: PandaName) -> PandaName:
return PandaName(
block=_choose_sub_pv(self.block, other.block),
block_number=_choose_sub_pv(self.block_number, other.block_number),
field=_choose_sub_pv(self.field, other.field),
sub_field=_choose_sub_pv(self.sub_field, other.sub_field),
block=_choose_sub_name(self.block, other.block),
block_number=_choose_sub_name(self.block_number, other.block_number),
field=_choose_sub_name(self.field, other.field),
sub_field=_choose_sub_name(self.sub_field, other.sub_field),
)

@cached_property
Expand All @@ -116,9 +108,10 @@ def attribute_name(self) -> str:
return ""

def __contains__(self, other: PandaName) -> bool:
return (
_check_eq(other.block, self.block)
and _check_eq(other.block_number, self.block_number)
and _check_eq(other.field, self.field)
and _check_eq(other.sub_field, self.sub_field)
)
for attr in ("block", "block_number", "field", "sub_field"):
sub_value, super_value = getattr(other, attr), getattr(self, attr)
if super_value is None:
break
if sub_value != super_value:
return False
return True

0 comments on commit 609e0ad

Please sign in to comment.