Skip to content

Commit

Permalink
Merge pull request #91 from dmgav/fix-colon-in-pv-name
Browse files Browse the repository at this point in the history
Support for ':' (colon) characters in PV prefix
  • Loading branch information
evalott100 authored Feb 15, 2024
2 parents d2084df + 236d252 commit b1f933c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/pandablocks_ioc/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class _RecordUpdater:
Args:
record_info: The RecordInfo structure for the record
record_prefix: The prefix of the record name
client: The client used to send data to PandA
all_values_dict: The dictionary containing the most recent value of all records
as returned from GetChanges. This dict will be dynamically updated by other
Expand All @@ -317,6 +318,7 @@ class _RecordUpdater:
"""

record_info: RecordInfo
record_prefix: str
client: AsyncioClient
all_values_dict: Dict[EpicsName, RecordValue]
labels: Optional[List[str]]
Expand Down Expand Up @@ -344,7 +346,8 @@ async def update(self, new_val: Any):
# value is None - expected for action-write fields
val = new_val

panda_field = device_and_record_to_panda_name(self.record_info.record.name)
record_name = self.record_info.record.name.removeprefix(self.record_prefix)
panda_field = device_and_record_to_panda_name(record_name)

await self.client.send(Put(panda_field, val))

Expand All @@ -360,7 +363,9 @@ async def update(self, new_val: Any):
)
try:
if self.record_info.record:
record_name = self.record_info.record.name.split(":", maxsplit=1)[1]
record_name = self.record_info.record.name.removeprefix(
self.record_prefix + ":"
)

assert record_name in self.all_values_dict
old_val = self.all_values_dict[record_name]
Expand Down Expand Up @@ -408,7 +413,6 @@ class _TimeRecordUpdater(_RecordUpdater):
of `time` do not have a `MIN` attribute."""

base_record: RecordWrapper
record_prefix: str
is_type_time: bool

async def update(self, new_val: Any):
Expand Down Expand Up @@ -646,6 +650,7 @@ def _create_record_info(
):
record_updater = _RecordUpdater(
record_info,
self._record_prefix,
self._client,
self._all_values_dict,
labels if labels else None,
Expand Down Expand Up @@ -717,11 +722,11 @@ def _make_time(
)
updater = _TimeRecordUpdater(
record_dict[units_record_name],
self._record_prefix,
self._client,
self._all_values_dict,
labels,
time_record_info.record,
self._record_prefix,
isinstance(field_info, TimeFieldInfo),
)

Expand Down Expand Up @@ -1425,7 +1430,7 @@ def _make_action_write(
)

updater = _WriteRecordUpdater(
record_info, self._client, self._all_values_dict, None
record_info, self._record_prefix, self._client, self._all_values_dict, None
)

record_info.add_record(record_info.record)
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/mocked_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def mocked_time_record_updater(
yield (
_TimeRecordUpdater(
mocked_record_info,
new_random_test_prefix,
client,
{},
["TEST1", "TEST2", "TEST3"],
base_record,
new_random_test_prefix,
True,
),
new_random_test_prefix,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def record_updater() -> _RecordUpdater:
client.send = AsyncMock() # type: ignore
record_info = RecordInfo(float)
mocked_record = MagicMock()
mocked_record.name = "PREFIX:ABC:DEF"
record_prefix = "PREFIX:ES"
mocked_record.name = record_prefix + ":ABC:DEF"
record_info.add_record(mocked_record)

return _RecordUpdater(record_info, client, {}, None)
return _RecordUpdater(record_info, record_prefix, client, {}, None)


@pytest.fixture
Expand Down

0 comments on commit b1f933c

Please sign in to comment.