hasmtools


Namehasmtools JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryVisualize Home Assistant Finite State Machines
upload_time2024-12-09 03:40:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseApache-2.0
keywords homeassistant fsm
VCS
bugtrack_url
requirements click pydot PyYAML
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # hasmtools

A small tool to help me working with the Finite State Machine Sensor for Home Assistant by
generating a png and converting the definition between JSON and YAML.

See https://github.com/edalquist/ha_state_machine for the Sensor.

# Features

* write your definition in YAML instead of JSON
* convert from YAML to JSON and back
* generate an image of the state machine using graphviz

# Examples

## YAML input file

```yaml
initial:
  a: state2
  b: state3
state2:
  a: initial
  b: state3
state3:
  a: initial
  b: state2
```
Note that in yaml the first state is the default/initial state.

## Converted to JSON

```
 $ hasmtool example.yaml example.json
```

```json
{
    "state": {
        "status": "initial"
    },
    "transitions": {
        "initial": {
            "a": "state2",
            "b": "state3"
        },
        "state2": {
            "a": "initial",
            "b": "state3"
        },
        "state3": {
            "a": "initial",
            "b": "state2"
        }
    }
}
```

## Finally converted to PNG

```
 $ hasmtool example.json example.png
```

![State Machine rendered as png](https://github.com/mutax/hasmtools/raw/main/example.png)

## An example with timeouts

source: https://github.com/edalquist/ha_state_machine/blob/main/example.json

```json
{
  "state": {
    "status": "IDLE"
  },
  "transitions": {
    "IDLE": {
      "above": "STARTING"
    },
    "STARTING": {
      "timeout": { "after": 6, "to": "RUNNING" },
      "below": "IDLE"
    },
    "RUNNING": {
      "below": "STOPPING"
    },
    "STOPPING": {
      "timeout": { "after": 15, "to": "DONE" },
      "above": "RUNNING",
      "middle": "RUNNING"
    },
    "DONE": {
      "timeout": { "after": 15, "to": "IDLE" }
    }
  }
}
```

![FSM with timeouts](https://github.com/mutax/hasmtools/raw/main/timeouts.png)



# Status

Working MVP.

# Why Did I Do This?

It started with the desire to have a visualization of the FSM, then I realised I like yaml more than json for it, so one thing led to another...

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "hasmtools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "HomeAssistant, FSM",
    "author": null,
    "author_email": "Florian Streibelt <mail+github@yakshaving.de>",
    "download_url": "https://files.pythonhosted.org/packages/84/a2/80f59dbcd77403f3c1d65ace7e08a3cf7b8238423b8e998cac78f1bb3c14/hasmtools-0.0.3.tar.gz",
    "platform": null,
    "description": "# hasmtools\n\nA small tool to help me working with the Finite State Machine Sensor for Home Assistant by\ngenerating a png and converting the definition between JSON and YAML.\n\nSee https://github.com/edalquist/ha_state_machine for the Sensor.\n\n# Features\n\n* write your definition in YAML instead of JSON\n* convert from YAML to JSON and back\n* generate an image of the state machine using graphviz\n\n# Examples\n\n## YAML input file\n\n```yaml\ninitial:\n  a: state2\n  b: state3\nstate2:\n  a: initial\n  b: state3\nstate3:\n  a: initial\n  b: state2\n```\nNote that in yaml the first state is the default/initial state.\n\n## Converted to JSON\n\n```\n $ hasmtool example.yaml example.json\n```\n\n```json\n{\n    \"state\": {\n        \"status\": \"initial\"\n    },\n    \"transitions\": {\n        \"initial\": {\n            \"a\": \"state2\",\n            \"b\": \"state3\"\n        },\n        \"state2\": {\n            \"a\": \"initial\",\n            \"b\": \"state3\"\n        },\n        \"state3\": {\n            \"a\": \"initial\",\n            \"b\": \"state2\"\n        }\n    }\n}\n```\n\n## Finally converted to PNG\n\n```\n $ hasmtool example.json example.png\n```\n\n![State Machine rendered as png](https://github.com/mutax/hasmtools/raw/main/example.png)\n\n## An example with timeouts\n\nsource: https://github.com/edalquist/ha_state_machine/blob/main/example.json\n\n```json\n{\n  \"state\": {\n    \"status\": \"IDLE\"\n  },\n  \"transitions\": {\n    \"IDLE\": {\n      \"above\": \"STARTING\"\n    },\n    \"STARTING\": {\n      \"timeout\": { \"after\": 6, \"to\": \"RUNNING\" },\n      \"below\": \"IDLE\"\n    },\n    \"RUNNING\": {\n      \"below\": \"STOPPING\"\n    },\n    \"STOPPING\": {\n      \"timeout\": { \"after\": 15, \"to\": \"DONE\" },\n      \"above\": \"RUNNING\",\n      \"middle\": \"RUNNING\"\n    },\n    \"DONE\": {\n      \"timeout\": { \"after\": 15, \"to\": \"IDLE\" }\n    }\n  }\n}\n```\n\n![FSM with timeouts](https://github.com/mutax/hasmtools/raw/main/timeouts.png)\n\n\n\n# Status\n\nWorking MVP.\n\n# Why Did I Do This?\n\nIt started with the desire to have a visualization of the FSM, then I realised I like yaml more than json for it, so one thing led to another...\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Visualize Home Assistant Finite State Machines",
    "version": "0.0.3",
    "project_urls": {
        "Changelog": "https://github.com/mutax/hasmtools/CHANGES",
        "Documentation": "https://github.com/mutax/hasmtools",
        "Source": "https://github.com/mutax/hasmtools"
    },
    "split_keywords": [
        "homeassistant",
        " fsm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "072159b0ba73c200f3ae36f5f632d7028b3ad55d72288d69cf413bb5e7bc80c5",
                "md5": "e7d1f518d4601610bd42e07998fff2e8",
                "sha256": "52f395258b46830d434d1d114f7eb810020b966339c829c1be9738a234ceb1a4"
            },
            "downloads": -1,
            "filename": "hasmtools-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7d1f518d4601610bd42e07998fff2e8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 10003,
            "upload_time": "2024-12-09T03:40:40",
            "upload_time_iso_8601": "2024-12-09T03:40:40.166929Z",
            "url": "https://files.pythonhosted.org/packages/07/21/59b0ba73c200f3ae36f5f632d7028b3ad55d72288d69cf413bb5e7bc80c5/hasmtools-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "84a280f59dbcd77403f3c1d65ace7e08a3cf7b8238423b8e998cac78f1bb3c14",
                "md5": "e9bd4de0db22b2ccce57ffae0c9ff51a",
                "sha256": "d8471a1e1cc97e5e0b5c1fa7f3d42f3d25531fb14fb1f1183bbd3f81d692d6eb"
            },
            "downloads": -1,
            "filename": "hasmtools-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e9bd4de0db22b2ccce57ffae0c9ff51a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 90410,
            "upload_time": "2024-12-09T03:40:41",
            "upload_time_iso_8601": "2024-12-09T03:40:41.325567Z",
            "url": "https://files.pythonhosted.org/packages/84/a2/80f59dbcd77403f3c1d65ace7e08a3cf7b8238423b8e998cac78f1bb3c14/hasmtools-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-09 03:40:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mutax",
    "github_project": "hasmtools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "click",
            "specs": [
                [
                    ">=",
                    "8.1.7"
                ]
            ]
        },
        {
            "name": "pydot",
            "specs": [
                [
                    ">=",
                    "3.0.3"
                ]
            ]
        },
        {
            "name": "PyYAML",
            "specs": [
                [
                    ">=",
                    "6.0.2"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "hasmtools"
}
        
Elapsed time: 0.95739s