rydiqule.sensor_utils.match_states

rydiqule.sensor_utils.match_states(statespec: int | str | Tuple[float, ...] | List[int | str | Tuple[float, ...]] | Tuple[float | List[float], ...], compare_list: List[int | str | Tuple[float, ...]]) List[int | str | Tuple[float, ...]][source]

Return all states in a list matching the pattern described by a given specification.

A StateSpec is described by a tuple containing floats or strings, or lists of floats or strings. A state s in compare_list is considered a match to statespec if s and statespec are the same length and for each element in statespec, :

  1. The corresponding element in s is equal to the element in statespec (in the case of a

    single value)

  2. The element is s is an element of the list which is an element of statespec (in the

    case of a list element of statespec).

  3. The element of statespec is the string "all"

Parameters:
  • statespec (StateSpec) – The state specification against which to compare elements of the list.

  • compare_list (List[State]) – The list of individual states to compare.

Returns:

Sublist of compare_list containing all elements of compare_list matching statespec.

Return type:

list of State

Examples

While primarily intended for internal use, match_states can be accessed directly through sensor_utils.

>>> compare_states = [(0,0),
...       (1,0),(1,1),
...       (2,0),(2,1),(2,2)
...      ]
>>> spec = (2,[0,1,2])
>>> print(rq.sensor_utils.match_states(spec, compare_states))
[(2, 0), (2, 1), (2, 2)]
>>> wildcard_spec = (2,"all")
>>> print(rq.sensor_utils.match_states(wildcard_spec, compare_states))
[(2, 0), (2, 1), (2, 2)]