Skip to content

Commit

Permalink
Merge pull request #19 from AravindaDP/iron
Browse files Browse the repository at this point in the history
Add qos parameter to SubscriberState
  • Loading branch information
dcconner authored and David Conner committed May 21, 2024
1 parent a4560cc commit a153d4f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions flexbe_states/flexbe_states/subscriber_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,34 @@
from flexbe_core import EventState, Logger

from flexbe_core.proxy import ProxySubscriberCached
from flexbe_core.proxy.qos import QOS_DEFAULT


class SubscriberState(EventState):
"""
Gets the latest message on the given topic and stores it to userdata.
-- topic string The topic on which should be listened.
-- msg_type type The type of messages of this topic.
-- blocking bool Blocks until a message is received.
-- clear bool Drops last message on this topic on enter
in order to only handle message received since this state is active.
-- qos QoSProfile A QoSProfile to apply to the subscription.
#> message object Latest message on the given topic of the respective type.
<= received Message has been received and stored in userdata or state is not blocking.
<= unavailable The topic is not available when this state becomes actives.
"""

def __init__(self, topic, msg_type="", blocking=True, clear=False):
def __init__(self, topic, msg_type="", blocking=True, clear=False, qos=QOS_DEFAULT):
super(SubscriberState, self).__init__(outcomes=['received', 'unavailable'],
output_keys=['message'])
self._topic = topic
self._msg_type = msg_type
self._blocking = blocking
self._clear = clear
self._qos = qos
self._connected = False

if not self._connect():
Expand Down Expand Up @@ -86,7 +90,7 @@ def on_enter(self, userdata):

def _connect(self):
try:
self._sub = ProxySubscriberCached({self._topic: self._msg_type}, inst_id=id(self))
self._sub = ProxySubscriberCached({self._topic: self._msg_type}, qos=self._qos, inst_id=id(self))
self._connected = True
return True
except Exception: # pylint: disable=W0703
Expand Down

0 comments on commit a153d4f

Please sign in to comment.