swb-meter


Nameswb-meter JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
Summaryswitch-bot meters server
upload_time2024-07-14 08:38:28
maintainerNone
docs_urlNone
authorkj-9
requires_python>=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # swb-meter

[![PyPI](https://img.shields.io/pypi/v/swb-meter.svg)](https://pypi.org/project/swb-meter/)
[![Changelog](https://img.shields.io/github/v/release/kj-9/swb-meter?include_prereleases&label=changelog)](https://github.com/kj-9/swb-meter/releases)
[![Tests](https://github.com/kj-9/swb-meter/actions/workflows/ci.yml/badge.svg)](https://github.com/kj-9/swb-meter/actions/workflows/ci.yml)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/kj-9/swb-meter/blob/master/LICENSE)

A cli tool to gather [switchbot meters'](https://www.switchbot.jp/products/switchbot-meter) data and writes to sqlite.


with streamlit app to visualize the data:

![スクリーンショット 2024-07-13 22 35 45](https://github.com/user-attachments/assets/eb1d2b38-e2b5-4c83-8c19-5d6f2badb7df)



## Installation

Install this tool using `pip`:
```bash
pip install swb-meter
```

## Usage

For help, run `swb-meter --help`:
<!-- [[[cog
import cog
from swb_meter import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["--help"])
help = result.output.replace("Usage: cli", "Usage: swb-meter")
cog.out(
    f"```bash\n{help}\n```"
)
]]] -->
```bash
Usage: swb-meter [OPTIONS] COMMAND [ARGS]...

  SwitchBot Meters Server CLI tool.

  `swb-meter` allows you to listen for SwitchBot meters and insert the data into
  a SQLite database.

  By default the backend database is configured current directory with the name
  `swb_meter.db` (created if not exists).

  To change the database path by setting the environment variable
  `SWB_METER_DB_PATH`:

      $ export SWB_METER_DB_PATH=/path/to/db.sqlite

      or:

      $ SWB_METER_DB_PATH=/path/to/db.sqlite swb-meter listen

  To get started, add a meter with an alias (typically the room name where the
  meter is located) with its MAC address:

      $ swb-meter add "Living Room" 12:34:56:78:90:AB

  This will add a record to the `Meter` table.

      $ swb-meter ls
      Living Room 12:34:56:78:90:AB
      Total: 1 meters

  Then, start listening for the meters:

      $ swb-meter listen

  The data will be inserted into the `Temperature` table in the database.

  To visualize the data, you can run the Streamlit app in another terminal. You
  need optional dependencies [streamlit] installed:

      $ pip install swb-meter[streamlit]

  then run the Streamlit app:

      $ swb-meter streamlit

  By default, the log level is set to `INFO`.

  To change log level, set environment variable `SWB_METER_LOG_LEVEL=DEBUG` for
  verbose output.

      $ export SWB_METER_LOG_LEVEL=DEBUG

      or:

      $ SWB_METER_LOG_LEVEL=DEBUG swb-meter listen

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  add        Add a SwitchBot meter to the master table with an alias.
  listen     Listen for SwitchBot meters and insert data into the...
  ls         List all SwitchBot meters in the master table.
  rm         Remove a SwitchBot meter from the master table.
  streamlit  Run the Streamlit app for visualizing the temperature data.

```
<!-- [[[end]]] -->

You can also use:
```bash
python -m swb_meter --help
```

### Commands

#### `swb-meter add`
<!-- [[[cog
import cog
from swb_meter import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["add", "--help"])
help = result.output.replace("Usage: cli", "Usage: swb-meter")
cog.out(
    f"```bash\n{help}\n```"
)
]]] -->
```bash
Usage: swb-meter add [OPTIONS] ALIAS MAC_ADDRESS

  Add a SwitchBot meter to the master table with an alias.

  Example:
      $ swb-meter add "Living Room" 12:34:56:78:90:AB

Options:
  -u, --upsert  Upsert the existing record's alias
  --help        Show this message and exit.

```
<!-- [[[end]]] -->


#### `swb-meter ls`
<!-- [[[cog
import cog
from swb_meter import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["ls", "--help"])
help = result.output.replace("Usage: cli", "Usage: swb-meter")
cog.out(
    f"```bash\n{help}\n```"
)
]]] -->
```bash
Usage: swb-meter ls [OPTIONS]

  List all SwitchBot meters in the master table.

  Example:
      $ swb-meter ls

Options:
  --help  Show this message and exit.

```
<!-- [[[end]]] -->


#### `swb-meter rm`
<!-- [[[cog
import cog
from swb_meter import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["rm", "--help"])
help = result.output.replace("Usage: cli", "Usage: swb-meter")
cog.out(
    f"```bash\n{help}\n```"
)
]]] -->
```bash
Usage: swb-meter rm [OPTIONS] MAC_ADDRESS

  Remove a SwitchBot meter from the master table.

  Example:
      $ swb-meter rm 12:34:56:78:90:AB

Options:
  --help  Show this message and exit.

```
<!-- [[[end]]] -->


#### `swb-meter listen`
<!-- [[[cog
import cog
from swb_meter import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["listen", "--help"])
help = result.output.replace("Usage: cli", "Usage: swb-meter")
cog.out(
    f"```bash\n{help}\n```"
)
]]] -->
```bash
Usage: swb-meter listen [OPTIONS]

  Listen for SwitchBot meters and insert data into the temperature table.

  This command listens for SwitchBot meters and inserts the data into the
  temperature table. For each scan, wait for the specified timeout duration
  until all data is found and inserted once for each meter. The interval option
  specifies the time to wait between scans.

  Example:
      $ swb-meter listen

      $ swb-meter listen -t 10 -i 60 # Timeout 10 seconds, Interval 60 seconds

Options:
  -t, --timeout FLOAT     Timeout in seconds for each scan
  -i, --interval INTEGER  Interval in seconds between scans
  -s, --scans INTEGER     Number of scans. Default is None (infinite)
  --help                  Show this message and exit.

```
<!-- [[[end]]] -->


#### `swb-meter streamlit`
<!-- [[[cog
import cog
from swb_meter import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["streamlit", "--help"])
help = result.output.replace("Usage: cli", "Usage: swb-meter")
cog.out(
    f"```bash\n{help}\n```"
)
]]] -->
```bash
Usage: swb-meter streamlit [OPTIONS]

  Run the Streamlit app for visualizing the temperature data.

  Example:
      $ swb-meter app

Options:
  --help  Show this message and exit.

```
<!-- [[[end]]] -->


## Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:
```bash
cd swb-meter
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "swb-meter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "kj-9",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/dc/59/350ba7643629a0a0bd2d232a0c8fb116893e80fc266300abe8b054677743/swb_meter-0.1.0.tar.gz",
    "platform": null,
    "description": "# swb-meter\n\n[![PyPI](https://img.shields.io/pypi/v/swb-meter.svg)](https://pypi.org/project/swb-meter/)\n[![Changelog](https://img.shields.io/github/v/release/kj-9/swb-meter?include_prereleases&label=changelog)](https://github.com/kj-9/swb-meter/releases)\n[![Tests](https://github.com/kj-9/swb-meter/actions/workflows/ci.yml/badge.svg)](https://github.com/kj-9/swb-meter/actions/workflows/ci.yml)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/kj-9/swb-meter/blob/master/LICENSE)\n\nA cli tool to gather [switchbot meters'](https://www.switchbot.jp/products/switchbot-meter) data and writes to sqlite.\n\n\nwith streamlit app to visualize the data:\n\n![\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2024-07-13 22 35 45](https://github.com/user-attachments/assets/eb1d2b38-e2b5-4c83-8c19-5d6f2badb7df)\n\n\n\n## Installation\n\nInstall this tool using `pip`:\n```bash\npip install swb-meter\n```\n\n## Usage\n\nFor help, run `swb-meter --help`:\n<!-- [[[cog\nimport cog\nfrom swb_meter import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: swb-meter\")\ncog.out(\n    f\"```bash\\n{help}\\n```\"\n)\n]]] -->\n```bash\nUsage: swb-meter [OPTIONS] COMMAND [ARGS]...\n\n  SwitchBot Meters Server CLI tool.\n\n  `swb-meter` allows you to listen for SwitchBot meters and insert the data into\n  a SQLite database.\n\n  By default the backend database is configured current directory with the name\n  `swb_meter.db` (created if not exists).\n\n  To change the database path by setting the environment variable\n  `SWB_METER_DB_PATH`:\n\n      $ export SWB_METER_DB_PATH=/path/to/db.sqlite\n\n      or:\n\n      $ SWB_METER_DB_PATH=/path/to/db.sqlite swb-meter listen\n\n  To get started, add a meter with an alias (typically the room name where the\n  meter is located) with its MAC address:\n\n      $ swb-meter add \"Living Room\" 12:34:56:78:90:AB\n\n  This will add a record to the `Meter` table.\n\n      $ swb-meter ls\n      Living Room 12:34:56:78:90:AB\n      Total: 1 meters\n\n  Then, start listening for the meters:\n\n      $ swb-meter listen\n\n  The data will be inserted into the `Temperature` table in the database.\n\n  To visualize the data, you can run the Streamlit app in another terminal. You\n  need optional dependencies [streamlit] installed:\n\n      $ pip install swb-meter[streamlit]\n\n  then run the Streamlit app:\n\n      $ swb-meter streamlit\n\n  By default, the log level is set to `INFO`.\n\n  To change log level, set environment variable `SWB_METER_LOG_LEVEL=DEBUG` for\n  verbose output.\n\n      $ export SWB_METER_LOG_LEVEL=DEBUG\n\n      or:\n\n      $ SWB_METER_LOG_LEVEL=DEBUG swb-meter listen\n\nOptions:\n  --version  Show the version and exit.\n  --help     Show this message and exit.\n\nCommands:\n  add        Add a SwitchBot meter to the master table with an alias.\n  listen     Listen for SwitchBot meters and insert data into the...\n  ls         List all SwitchBot meters in the master table.\n  rm         Remove a SwitchBot meter from the master table.\n  streamlit  Run the Streamlit app for visualizing the temperature data.\n\n```\n<!-- [[[end]]] -->\n\nYou can also use:\n```bash\npython -m swb_meter --help\n```\n\n### Commands\n\n#### `swb-meter add`\n<!-- [[[cog\nimport cog\nfrom swb_meter import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"add\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: swb-meter\")\ncog.out(\n    f\"```bash\\n{help}\\n```\"\n)\n]]] -->\n```bash\nUsage: swb-meter add [OPTIONS] ALIAS MAC_ADDRESS\n\n  Add a SwitchBot meter to the master table with an alias.\n\n  Example:\n      $ swb-meter add \"Living Room\" 12:34:56:78:90:AB\n\nOptions:\n  -u, --upsert  Upsert the existing record's alias\n  --help        Show this message and exit.\n\n```\n<!-- [[[end]]] -->\n\n\n#### `swb-meter ls`\n<!-- [[[cog\nimport cog\nfrom swb_meter import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"ls\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: swb-meter\")\ncog.out(\n    f\"```bash\\n{help}\\n```\"\n)\n]]] -->\n```bash\nUsage: swb-meter ls [OPTIONS]\n\n  List all SwitchBot meters in the master table.\n\n  Example:\n      $ swb-meter ls\n\nOptions:\n  --help  Show this message and exit.\n\n```\n<!-- [[[end]]] -->\n\n\n#### `swb-meter rm`\n<!-- [[[cog\nimport cog\nfrom swb_meter import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"rm\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: swb-meter\")\ncog.out(\n    f\"```bash\\n{help}\\n```\"\n)\n]]] -->\n```bash\nUsage: swb-meter rm [OPTIONS] MAC_ADDRESS\n\n  Remove a SwitchBot meter from the master table.\n\n  Example:\n      $ swb-meter rm 12:34:56:78:90:AB\n\nOptions:\n  --help  Show this message and exit.\n\n```\n<!-- [[[end]]] -->\n\n\n#### `swb-meter listen`\n<!-- [[[cog\nimport cog\nfrom swb_meter import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"listen\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: swb-meter\")\ncog.out(\n    f\"```bash\\n{help}\\n```\"\n)\n]]] -->\n```bash\nUsage: swb-meter listen [OPTIONS]\n\n  Listen for SwitchBot meters and insert data into the temperature table.\n\n  This command listens for SwitchBot meters and inserts the data into the\n  temperature table. For each scan, wait for the specified timeout duration\n  until all data is found and inserted once for each meter. The interval option\n  specifies the time to wait between scans.\n\n  Example:\n      $ swb-meter listen\n\n      $ swb-meter listen -t 10 -i 60 # Timeout 10 seconds, Interval 60 seconds\n\nOptions:\n  -t, --timeout FLOAT     Timeout in seconds for each scan\n  -i, --interval INTEGER  Interval in seconds between scans\n  -s, --scans INTEGER     Number of scans. Default is None (infinite)\n  --help                  Show this message and exit.\n\n```\n<!-- [[[end]]] -->\n\n\n#### `swb-meter streamlit`\n<!-- [[[cog\nimport cog\nfrom swb_meter import cli\nfrom click.testing import CliRunner\nrunner = CliRunner()\nresult = runner.invoke(cli.cli, [\"streamlit\", \"--help\"])\nhelp = result.output.replace(\"Usage: cli\", \"Usage: swb-meter\")\ncog.out(\n    f\"```bash\\n{help}\\n```\"\n)\n]]] -->\n```bash\nUsage: swb-meter streamlit [OPTIONS]\n\n  Run the Streamlit app for visualizing the temperature data.\n\n  Example:\n      $ swb-meter app\n\nOptions:\n  --help  Show this message and exit.\n\n```\n<!-- [[[end]]] -->\n\n\n## Development\n\nTo contribute to this tool, first checkout the code. Then create a new virtual environment:\n```bash\ncd swb-meter\npython -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e '.[test]'\n```\nTo run the tests:\n```bash\npytest\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "switch-bot meters server",
    "version": "0.1.0",
    "project_urls": {
        "CI": "https://github.com/kj-9/swb-meter/actions",
        "Changelog": "https://github.com/kj-9/swb-meter/releases",
        "Homepage": "https://github.com/kj-9/swb-meter",
        "Issues": "https://github.com/kj-9/swb-meter/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b485d36de6889e8988e912f3ab99a2fff780e543e9c043348205a187f0c3fd53",
                "md5": "c4c8a1a247f33ff410ad75edf1edaccf",
                "sha256": "1b1848565693334bc6b83a7b446f80305ba5c221311f9713d2ac5d619082a378"
            },
            "downloads": -1,
            "filename": "swb_meter-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c4c8a1a247f33ff410ad75edf1edaccf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 15417,
            "upload_time": "2024-07-14T08:38:27",
            "upload_time_iso_8601": "2024-07-14T08:38:27.481416Z",
            "url": "https://files.pythonhosted.org/packages/b4/85/d36de6889e8988e912f3ab99a2fff780e543e9c043348205a187f0c3fd53/swb_meter-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dc59350ba7643629a0a0bd2d232a0c8fb116893e80fc266300abe8b054677743",
                "md5": "983fadad93537da0bab58b0c0fdbc888",
                "sha256": "4ad6c3a174b74ef47db4223fab23ea259e2b6fe71417fdf4b26178f12a9cab16"
            },
            "downloads": -1,
            "filename": "swb_meter-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "983fadad93537da0bab58b0c0fdbc888",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 15156,
            "upload_time": "2024-07-14T08:38:28",
            "upload_time_iso_8601": "2024-07-14T08:38:28.842461Z",
            "url": "https://files.pythonhosted.org/packages/dc/59/350ba7643629a0a0bd2d232a0c8fb116893e80fc266300abe8b054677743/swb_meter-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 08:38:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kj-9",
    "github_project": "swb-meter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "swb-meter"
}
        
Elapsed time: 0.34428s