From d6bd168314f697ca44c678419ce691457b565601 Mon Sep 17 00:00:00 2001 From: Justin Vanderhooft Date: Fri, 15 Apr 2022 14:47:56 -0400 Subject: [PATCH] feat: readme and ci builds (#11) --- .github/workflows/build.yml | 52 +++++++++++++++++++++++++++++ README.md | 65 +++++++++++++++++++++++++++++++++++++ README.rst | 0 pyproject.toml | 23 ++++++++++--- 4 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 README.md delete mode 100644 README.rst diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4841e80 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,52 @@ +name: Build and Release + +on: + pull_request: + types: + - opened + - reopened + - synchronize + + push: + branches: + - main + + release: + types: [published] + +jobs: + build: + name: "Build" + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + + - uses: actions/setup-python@v2 + name: Install Python + with: + python-version: 3.9 + + - name: Install Poetry + uses: abatilo/actions-poetry@v2.0.0 + with: + poetry-version: 1.1.13 + + - name: Install poetry-dynamic-versioning + run: pip install poetry-dynamic-versioning + + - name: Install Dependencies + run: poetry install + + - name: Build + run: poetry build + + - name: Publish to PyPI + if: github.event_name != 'pull_request' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a570fe0 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# Melnor Bluetooth + +![PyPI](https://img.shields.io/pypi/v/melnor-bluetooth?style=flat-square) ![Codecov branch](https://img.shields.io/codecov/c/github/vanstinator/melnor-bluetooth/main?style=flat-square) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/vanstinator/melnor-bluetooth/Build%20and%20Release/main?style=flat-square) +![PyPI - Downloads](https://img.shields.io/pypi/dm/melnor-bluetooth?style=flat-square) + +Melnor Bluetooth is a reverse engineered implementation of the Bluetooth protocol for all "smart" bluetooth-enabled watering valves under the Melnor, EcoAquastar, Eden, and other brands. + +The library _should_ run on MacOS, Linux, or Windows. It's primarily developed on MacOS and other platforms likely have bugs. PRs and tests are welcome to improve quality across all platforms. + + +### Getting Started + +#### CLI +A simple CLI has been provided for basic debugging purposes. It's not intended for any real use and isn't suitable for running a valve in the real world. + +This project uses poetry for dependency management and building. Running this project locally is as simple as the following steps: + +1. Clone the repository +1. `poetry install` +1. `poetry run cli.py` + + +The python API has been designed to be as easy to use as possible. A few examples are provided below: + +#### Read battery state +```python + import asyncio + + from melnor_bluetooth.constants import BATTERY_UUID + from melnor_bluetooth.device import Device + + address = '00:00:00:00:00' # fill with your device mac address + + async main(): + device = Device(address, 4) + await device.connect() + + print(device.battery_life); + + await device.disconnect(); + + asyncio.run(main()) + +``` + +#### Turn on a zone +```python + import asyncio + + from melnor_bluetooth.device import Device + + address = '00:00:00:00:00' # fill with your device mac address + + async main(): + device = Device(address, 4) + await device.connect() + + device.zone1.is_watering = True; + + await device.push_state(); + await device.disconnect(); + + asyncio.run(main()) + +``` diff --git a/README.rst b/README.rst deleted file mode 100644 index e69de29..0000000 diff --git a/pyproject.toml b/pyproject.toml index 39c33d0..50a10ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,13 @@ [tool.poetry] -name = "melnor-bluetooh" -version = "0.1.0" -description = "A small python library for discovery and interacting with Melnor, Aquastar, etc bluetooth water timers." authors = ["Justin Vanderhooft "] +description = "A small python library for discovery and interacting with Melnor, Aquastar, etc bluetooth water timers." +license = "MIT" +name = "melnor-bluetooth" +readme = "README.md" +version = "0.0.0" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning"] build-backend = "poetry.core.masonry.api" [tool.black] @@ -44,5 +46,18 @@ mockito = "^1.3.0" flake8 = "^4.0.1" syrupy = "^1.7.4" +[tool.poetry-dynamic-versioning] +bump = false +enable = true +format-jinja = """ + {%- if distance == 0 -%} + {{ serialize_pep440(base, stage, revision) }} + {%- elif revision is not none -%} + {{ serialize_pep440(base, stage, revision + 1, dev=distance) }} + {%- else -%} + {{ serialize_pep440(bump_version(base), stage, revision, dev=distance) }} + {%- endif -%} +""" + [tool.pytest.ini_options] asyncio_mode = 'auto'