1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

add an easy way for a state to ignore packets by creating a ReceiveTransition back to itself

This commit is contained in:
Joel Bender 2018-06-29 00:13:32 -04:00
parent 9db07dc8d5
commit e9c511c2c2

View File

@ -346,6 +346,24 @@ class State(object):
"""Called with PDU received after match."""
self.state_machine.after_receive(pdu)
def ignore(self, pdu_type, **pdu_attrs):
"""Create a ReceiveTransition from this state to itself, if match
is successful the effect is to ignore the PDU.
:param criteria: PDU to match
"""
if _debug: State._debug("ignore(%s) %r %r", self.doc_string, pdu_type, pdu_attrs)
# create a bundle of the match criteria
criteria = (pdu_type, pdu_attrs)
if _debug: State._debug(" - criteria: %r", criteria)
# add this to the list of transitions
self.receive_transitions.append(ReceiveTransition(criteria, self))
# return this state, no new state is created
return self
def unexpected_receive(self, pdu):
"""Called with PDU that did not match. Unless this is trapped by the
state, the default behaviour is to fail."""