Skip to content

Commit

Permalink
use same logic Tagno as for aioca and p4p callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kivel committed Jan 15, 2025
1 parent 7f0e8fa commit 8592cbd
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/ophyd_async/tango/core/_tango_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,25 +732,21 @@ def set_callback(self, callback: Callback | None) -> None:
" for which polling is disabled."
)

if callback and self.proxies[self.read_trl].has_subscription(): # type: ignore
msg = "Cannot set a callback when one is already set"
raise RuntimeError(msg)

if self.proxies[self.read_trl].has_subscription(): # type: ignore
self.proxies[self.read_trl].unsubscribe_callback() # type: ignore

if callback:
try:
# TODO: remove assert, I fail to get the test to work
# as soon as move the assert into a separate RunTime error
# the `test_tango_sim` fails
assert not self.proxies[self.read_trl].has_subscription() # type: ignore # noqa: S101
self.proxies[self.read_trl].subscribe_callback(callback) # type: ignore
except AssertionError as ae:
raise RuntimeError(
"Cannot set a callback when one is already set"
) from ae
except RuntimeError as exc:
raise RuntimeError(
f"Cannot set callback for {self.read_trl}. {exc}"
) from exc

else:
self.proxies[self.read_trl].unsubscribe_callback() # type: ignore

def set_polling(
self,
allow_polling: bool = True,
Expand Down

0 comments on commit 8592cbd

Please sign in to comment.