Skip to content

Commit

Permalink
Fix check for valid handler
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Oct 30, 2023
1 parent 63b19ec commit 0179688
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hsm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def _on(self, event):
)
)

if handler:
if handler is not None:
if e is not None:
e.propagate = False
_call(handler, e)
Expand Down
24 changes: 24 additions & 0 deletions test/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import print_function

import hsm


class SM(hsm.StateMachine):
def __init__(self):
super(SM, self).__init__("SM")
self.A = self.add_state("A", initial=True)
self.B = self.add_state("B")

self.A.add_handler("event", self.handler)
self.A.add_transition
self.initialize()

def handler(self, event):
print("Processing event '{}' in state '{}'".format(event.name, self.leaf_state.name))
self._transition_to(self.B, event)


if __name__ == "__main__":
sm = SM()
sm.dispatch("event")
sm.dispatch("event")

0 comments on commit 0179688

Please sign in to comment.