|
9 | 9 | from builtins import object |
10 | 10 | from collections.abc import Callable |
11 | 11 | from threading import Event |
12 | | -from typing import TYPE_CHECKING, Optional, Tuple, TypeVar |
| 12 | +from typing import TYPE_CHECKING, Optional, Tuple, TypeVar, TypeGuard, overload, Literal |
13 | 13 |
|
14 | 14 | from CaChannel import CaChannel, CaChannelException, ca |
15 | 15 |
|
|
32 | 32 | ) |
33 | 33 |
|
34 | 34 | if TYPE_CHECKING: |
35 | | - from genie_python.genie import PVValue |
| 35 | + from genie_python.genie import PVValue, PVBaseValue |
| 36 | + |
| 37 | + def is_int_or_str_list(val: list[PVBaseValue]) -> TypeGuard[list[int | str]]: |
| 38 | + return all(isinstance(x, int) or isinstance(x, str) for x in val) |
36 | 39 |
|
37 | 40 | from .channel_access_exceptions import ( |
38 | 41 | InvalidEnumStringException, |
@@ -306,6 +309,8 @@ def get_pv_value( |
306 | 309 | value = chan.getw(ca.DBR_CHAR) |
307 | 310 | # Could see if the element count is > 1 instead |
308 | 311 | if isinstance(value, list): |
| 312 | + if TYPE_CHECKING: |
| 313 | + assert is_int_or_str_list(value) |
309 | 314 | return waveform_to_string(value) |
310 | 315 | else: |
311 | 316 | return str(value) |
@@ -384,7 +389,7 @@ def connect_to_pv(ca_channel: CaChannel) -> None: |
384 | 389 | try: |
385 | 390 | ca_channel.search_and_connect(None, CaChannelWrapper.putCB, event) |
386 | 391 | except CaChannelException as e: |
387 | | - raise UnableToConnectToPVException(ca_channel.name(), e) |
| 392 | + raise UnableToConnectToPVException(ca_channel.name(), str(e)) |
388 | 393 |
|
389 | 394 | ca_channel.flush_io() |
390 | 395 |
|
@@ -451,6 +456,8 @@ def add_monitor( |
451 | 456 | when the pv disconnects |
452 | 457 | use_numpy (bool, optional): True use numpy to return arrays, |
453 | 458 | False return a list; None for use the default |
| 459 | + to_string: if set to true, will ensure anything passed to call_back_function's value |
| 460 | + is a string |
454 | 461 | Returns: |
455 | 462 | unsubscribe event function |
456 | 463 | """ |
|
0 commit comments