Skip to main content

Hat statechart engine

Project description

This library is part of Hat Open project - open-source framework of tools and libraries for developing applications used for remote monitoring, control and management of intelligent electronic devices such as IoT devices, PLCs, industrial automation or home automation systems.

Development of Hat Open and associated repositories is sponsored by Končar - Power Plant and Electric Traction Engineering Inc. (Končar KET - https://www.koncar-ket.hr).

For more information see:

About

Hierarchical state machine library with support for SCXML and Graphviz visualization:

EventName = str
"""Event name"""

StateName = str
"""State name"""

ActionName = str
"""Action name"""

ConditionName = str
"""Condition name"""

class Event(typing.NamedTuple):
    name: EventName
    payload: typing.Any = None

class Transition(typing.NamedTuple):
    event: EventName
    target: typing.Optional[StateName]
    actions: typing.List[ActionName] = []
    conditions: typing.List[ConditionName] = []
    internal: bool = False

class State(typing.NamedTuple):
    name: StateName
    children: typing.List['State'] = []
    transitions: typing.List[Transition] = []
    entries: typing.List[ActionName] = []
    exits: typing.List[ActionName] = []
    final: bool = False

Action = typing.Callable[['Statechart', typing.Optional[Event]], None]
"""Action function"""

Condition = typing.Callable[['Statechart', typing.Optional[Event]], bool]
"""Condition function"""

class Statechart:
    """Statechart engine"""

    def __init__(self,
                 states: typing.Iterable[State],
                 actions: typing.Dict[str, Action],
                 conditions: typing.Dict[str, Condition] = {}): ...

    @property
    def state(self) -> typing.Optional[StateName]:
        """Current state"""

    def register(self, event: Event):
        """Add event to queue"""

    async def run(self):
        """Run statechart"""

def parse_scxml(scxml: typing.Union[typing.TextIO, pathlib.Path]
                ) -> typing.List[State]:
    """Parse SCXML"""


def create_dot_graph(states: typing.Iterable[State]) -> str:
    """Create DOT representation of statechart"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hat_stc-0.4.1.dev20210707-cp38.cp39-none-any.whl (6.7 kB view details)

Uploaded CPython 3.8CPython 3.9

File details

Details for the file hat_stc-0.4.1.dev20210707-cp38.cp39-none-any.whl.

File metadata

  • Download URL: hat_stc-0.4.1.dev20210707-cp38.cp39-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: CPython 3.8, CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for hat_stc-0.4.1.dev20210707-cp38.cp39-none-any.whl
Algorithm Hash digest
SHA256 be938b410aa556d0ceda342beddefb68e028365b9ec41bdb02b740437a5dbe73
MD5 d82d0f59a3b272a9c79d806c35211b2e
BLAKE2b-256 b1331803d732e7fc3983ef118768c04954104f1ed68ecc3775cdce85470e03c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page