cic-internal-integration/apps/cic-ussd/cic_ussd/state_machine/state_machine.py

43 lines
1.5 KiB
Python
Raw Normal View History

2021-02-06 16:13:47 +01:00
# standard imports
import logging
# third party imports
from transitions import Machine
# local imports
logg = logging.getLogger(__name__)
class UssdStateMachine(Machine):
"""This class describes a finite state machine responsible for maintaining all the states that describe the ussd
menu as well as providing a means for navigating through these states based on different user inputs.
It defines different helper functions that co-ordinate with the stakeholder components of the ussd menu: i.e the
User, UssdSession, UssdMenu to facilitate user interaction with ussd menu.
:cvar chain_str: The chain name and network id.
:type chain_str: str
:cvar states: A list of pre-defined states.
:type states: list
:cvar transitions: A list of pre-defined transitions.
:type transitions: list
"""
chain_str = None
states = []
transitions = []
def __repr__(self):
return f'<KenyaUssdStateMachine: {self.state}>'
def __init__(self, ussd_session: dict):
"""
:param ussd_session: A Ussd session object that contains contextual data that informs the state machine's state
changes.
:type ussd_session: dict
"""
self.ussd_session = ussd_session
super(UssdStateMachine, self).__init__(initial=ussd_session.get('state'),
model=self,
states=self.states,
transitions=self.transitions)