{"id":44338716,"url":"https://github.com/initialed85/stato","last_synced_at":"2026-02-11T12:17:52.858Z","repository":{"id":104290149,"uuid":"356845501","full_name":"initialed85/stato","owner":"initialed85","description":"A simple state machine library written in Go","archived":false,"fork":false,"pushed_at":"2024-05-25T14:11:26.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T02:51:51.310Z","etag":null,"topics":["fsm","fsm-library","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/initialed85.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-11T11:11:28.000Z","updated_at":"2024-05-25T14:11:29.000Z","dependencies_parsed_at":"2024-06-20T03:11:12.796Z","dependency_job_id":null,"html_url":"https://github.com/initialed85/stato","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/initialed85/stato","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/initialed85%2Fstato","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/initialed85%2Fstato/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/initialed85%2Fstato/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/initialed85%2Fstato/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/initialed85","download_url":"https://codeload.github.com/initialed85/stato/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/initialed85%2Fstato/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29332787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fsm","fsm-library","go","golang"],"created_at":"2026-02-11T12:17:52.133Z","updated_at":"2026-02-11T12:17:52.852Z","avatar_url":"https://github.com/initialed85.png","language":"Go","readme":"# stato\n\n# status: working and refreshed recently for use in an OCPP server\n\nNamed after the iconic Holden Statesman, `stato` tries to be a simple state machine library providing states and\ntransitions with one or more on-enter and on-exit callbacks for both.\n\n## Usage\n\nThe example below builds a state machine that's intended to be used via the `ChangeState()` approach (i.e. try to find\na unique for the source state to the destination state) but you can also explicitly use the `Transition()` approach\n(i.e. try to invoke a transition that calls for a specific source state and destination state).\n\n```golang\npackage state_machines\n\nimport (\n\t\"fmt\"\n\t\"github.com/initialed85/stato/pkg/fsm\"\n)\n\ntype ConnectorFSM struct {\n\tAvailable     *fsm.State\n\tPreparing     *fsm.State\n\tCharging      *fsm.State\n\tSuspendedEV   *fsm.State\n\tSuspendedEVSE *fsm.State\n\tFinishing     *fsm.State\n\tReserved      *fsm.State\n\tUnavailable   *fsm.State\n\tFaulted       *fsm.State\n\tstates        []*fsm.State\n\ttransitions   []*fsm.Transition\n\tmachine       *fsm.Machine\n}\n\nfunc NewConnectorFSM() (*ConnectorFSM, error) {\n\tf := ConnectorFSM{\n\t\tAvailable: fsm.NewState(\n\t\t\t\"Available\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tPreparing: fsm.NewState(\n\t\t\t\"Preparing\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tCharging: fsm.NewState(\n\t\t\t\"Charging\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tSuspendedEV: fsm.NewState(\n\t\t\t\"SuspendedEV\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tSuspendedEVSE: fsm.NewState(\n\t\t\t\"SuspendedEVSE\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tFinishing: fsm.NewState(\n\t\t\t\"Finishing\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tReserved: fsm.NewState(\n\t\t\t\"Reserved\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tUnavailable: fsm.NewState(\n\t\t\t\"Unavailable\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t\tFaulted: fsm.NewState(\n\t\t\t\"Faulted\",\n\t\t\t[]func() error{},\n\t\t\t[]func() error{},\n\t\t),\n\t}\n\n\tf.states = []*fsm.State{\n\t\tf.Available,\n\t\tf.Preparing,\n\t\tf.Charging,\n\t\tf.SuspendedEV,\n\t\tf.SuspendedEVSE,\n\t\tf.Finishing,\n\t\tf.Reserved,\n\t\tf.Unavailable,\n\t\tf.Faulted,\n\t}\n\n\talpha := map[string]*fsm.State{\n\t\t\"A\": f.Available,\n\t\t\"B\": f.Preparing,\n\t\t\"C\": f.Charging,\n\t\t\"D\": f.SuspendedEV,\n\t\t\"E\": f.SuspendedEVSE,\n\t\t\"F\": f.Finishing,\n\t\t\"G\": f.Reserved,\n\t\t\"H\": f.Unavailable,\n\t\t\"I\": f.Faulted,\n\t}\n\n\tnumeric := map[string]*fsm.State{\n\t\t\"1\": f.Available,\n\t\t\"2\": f.Preparing,\n\t\t\"3\": f.Charging,\n\t\t\"4\": f.SuspendedEV,\n\t\t\"5\": f.SuspendedEVSE,\n\t\t\"6\": f.Finishing,\n\t\t\"7\": f.Reserved,\n\t\t\"8\": f.Unavailable,\n\t\t\"9\": f.Faulted,\n\t}\n\n\t// note: don't trust this matrix if you're implementing an OCPP server- it was hand-entered by a human\n\tpermutations := []string{\n\t\t\"__\", \"A2\", \"A3\", \"A4\", \"A5\", \"__\", \"A7\", \"A8\", \"A9\",\n\t\t\"B1\", \"__\", \"B3\", \"B4\", \"B5\", \"__\", \"__\", \"__\", \"B9\",\n\t\t\"C1\", \"__\", \"__\", \"C4\", \"C5\", \"C6\", \"__\", \"C8\", \"C9\",\n\t\t\"D1\", \"__\", \"D3\", \"__\", \"D5\", \"D6\", \"__\", \"D8\", \"D9\",\n\t\t\"E1\", \"__\", \"E3\", \"E4\", \"__\", \"E6\", \"__\", \"E8\", \"E9\",\n\t\t\"F1\", \"F2\", \"__\", \"__\", \"__\", \"__\", \"__\", \"F8\", \"F9\",\n\t\t\"G1\", \"G2\", \"__\", \"__\", \"__\", \"__\", \"__\", \"G8\", \"G9\",\n\t\t\"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"__\", \"__\", \"__\", \"H9\",\n\t\t\"I1\", \"I2\", \"I3\", \"I4\", \"I5\", \"I6\", \"I7\", \"I8\", \"_\",\n\t}\n\n\tfor _, permutation := range permutations {\n\t\tsource := permutation[0:1]\n\t\tdestination := permutation[1:2]\n\n\t\tsourceState, alphaOk := alpha[source]\n\t\tdestinationState, numericOk := numeric[destination]\n\n\t\tif !(alphaOk \u0026\u0026 numericOk) {\n\t\t\tcontinue\n\t\t}\n\n\t\tf.transitions = append(\n\t\t\tf.transitions,\n\t\t\tfsm.NewTransition(\n\t\t\t\tfmt.Sprintf(\"%vTo%v\", source, destination),\n\t\t\t\t[]func() error{},\n\t\t\t\t[]func() error{},\n\t\t\t\tsourceState,\n\t\t\t\tdestinationState,\n\t\t\t),\n\t\t)\n\t}\n\n\tmachine, err := fsm.NewMachine(\n\t\t\"Connector\",\n\t\tf.states,\n\t\tf.transitions,\n\t\tf.Unavailable,\n\t)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tf.machine = machine\n\n\treturn \u0026f, nil\n}\n\nfunc (c *ConnectorFSM) ChangeState(destinationState *fsm.State) error {\n\treturn c.machine.ChangeState(destinationState)\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitialed85%2Fstato","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finitialed85%2Fstato","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finitialed85%2Fstato/lists"}