diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 7a6984a..90618f5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,7 +3,7 @@ name: Bug report about: Create a report to help us improve title: '' labels: '' -assignees: yp87 +assignees: kamiKAC --- diff --git a/.github/workflows/leaf2mqtt.yml b/.github/workflows/leaf2mqtt.yml index 9acd6c3..9fb7729 100644 --- a/.github/workflows/leaf2mqtt.yml +++ b/.github/workflows/leaf2mqtt.yml @@ -2,70 +2,125 @@ name: Publish Docker image on: workflow_dispatch: + inputs: + tag: + type: string + description: Set tag for docker image if workflow not started from main + default: "" + required: false + push: - paths: - - 'pubspec.*' - - 'src/**' - - 'Dockerfile' - - '.github/workflows/**' branches: - main jobs: + release-please: + if: github.event_name != 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - uses: googleapis/release-please-action@v4 + id: release + - uses: actions/checkout@v4 + - name: tag major and minor versions + if: steps.release.outputs.release_created + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + git tag -d v${{ steps.release.outputs.major }} || true + git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true + git push origin :v${{ steps.release.outputs.major }} || true + git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true + git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}" + git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}" + git push origin v${{ steps.release.outputs.major }} + git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} + - name: display pr output + if: steps.release.outputs.prs_created == 'true' + run: |- + echo 'pr output: ${{ steps.release.outputs.pr }}' + echo 'prs output: ${{ steps.release.outputs.prs }}' + - name: install yq + if: steps.release.outputs.prs_created == 'true' + uses: chrisdickinson/setup-yq@v1.0.1 + with: + yq-version: v4.44.2 + - name: checkout release-please branch + if: steps.release.outputs.prs_created == 'true' + uses: actions/checkout@v4 + with: + ref: ${{ fromJson(steps.release.outputs.pr).headBranchName }} + - name: update addon version + if: steps.release.outputs.prs_created == 'true' + run: |- + version=$(yq '.version' ./pubspec.yaml) + yq -i ".version |= \"v${version}\"" addon/config.json + git add . + if [[ ! -z "$(git status --porcelain)" ]]; then + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + git commit -m "Update addon version" + git push + fi + + outputs: + release_created: ${{ steps.release.outputs.release_created }} + tag_name: ${{ steps.release.outputs.tag_name }} push_to_registry: name: Push Docker image to Docker Hub + needs: + - release-please + if: ${{ ! cancelled() && needs.release-please.outputs.release_created || github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest steps: - name: Check out the repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 200 - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - uses: docker/login-action@v1.10.0 + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUBUSERNAME }} password: ${{ secrets.DOCKERHUBACCESSTOKEN }} - + + - name: Get nearest tag + id: get-nearest-tag + if: ${{ github.ref != format('refs/heads/{0}', 'main') }} + shell: bash + run: |- + TAGS=$(git tag --list) + NEAREST_TAG=$(git describe --tags --abbrev=0) + SPECIFIC_TAG=$(git tag --points-at $(git rev-list -n 1 $NEAREST_TAG) | grep -E 'v[0-9]+\.[0-9]+\.[0-9]+') + if [[ ! -z "$SPECIFIC_TAG" ]]; then + echo "Nearest tag is: $SPECIFIC_TAG" + echo "Using tag ${SPECIFIC_TAG}-edge" + echo "nearest_tag=${SPECIFIC_TAG}-edge" >> $GITHUB_OUTPUT + else + echo "Nearest tag not found, using 'edge' tag" + echo "nearest_tag=edge" >> $GITHUB_OUTPUT + fi - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v5 with: - images: yp87/leaf2mqtt + images: ${{ secrets.DOCKERHUBUSERNAME }}/leaf2mqtt tags: | - type=raw,value=${{ github.run_number }} - type=raw,value=latest - + type=raw,value=${{ needs.release-please.outputs.tag_name }},enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + type=raw,value=${{ inputs.tag != '' && inputs.tag || steps.get-nearest-tag.outputs.nearest_tag }},enable=${{ github.ref != format('refs/heads/{0}', 'main') }} - name: Build and push Docker image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v5 with: context: . + build-args: | + APP_VERSION=${{ steps.meta.outputs.version }} push: true - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - - update_addon: - name: Update Home Assistant add-on - needs: push_to_registry - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Change image version number - uses: jossef/action-set-json-field@v1 - with: - file: addon/config.json - field: version - value: ${{ github.run_number }} - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Update add-on version + platforms: linux/amd64,linux/arm64,linux/arm/v8 + tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..3d2ac0b --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.1.0" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..85df016 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,39 @@ +# Changelog + +## [0.1.0](https://github.com/kamiKAC/leaf2mqtt/compare/v0.0.4...v0.1.0) (2024-06-30) + + +### Features + +* provide combined coordinates which are supported by openHAB ([#30](https://github.com/kamiKAC/leaf2mqtt/issues/30)) ([8bfd08a](https://github.com/kamiKAC/leaf2mqtt/commit/8bfd08a3e451ec79bdf5c2f845a6518fef54bb5e)) + +## [0.0.4](https://github.com/kamiKAC/leaf2mqtt/compare/v0.0.3...v0.0.4) (2024-06-16) + + +### Bug Fixes + +* correction of release-please-config ([3597bcd](https://github.com/kamiKAC/leaf2mqtt/commit/3597bcd4dc62b89397c29cdc6abb891df4834edb)) +* reorder of status fetch (https://github.com/kamiKAC/leaf2mqtt/pull/21) ([9307c0d](https://github.com/kamiKAC/leaf2mqtt/commit/9307c0d69bb69914670d6c857ec8760285a3e79f)) +* switch to dartcarwings v1.0.1 (solves https://github.com/kamiKAC/leaf2mqtt/issues/19) ([9307c0d](https://github.com/kamiKAC/leaf2mqtt/commit/9307c0d69bb69914670d6c857ec8760285a3e79f)) +* use build argument as version source - this enables displaying version of app in logs ([9307c0d](https://github.com/kamiKAC/leaf2mqtt/commit/9307c0d69bb69914670d6c857ec8760285a3e79f)) + + +### Miscellaneous Chores + +* release 0.0.4 ([719c8ea](https://github.com/kamiKAC/leaf2mqtt/commit/719c8eac3e9eb45d8452239c83076dd078b5cd54)) + + +## [0.0.3](https://github.com/kamiKAC/leaf2mqtt/compare/v0.0.2...v0.0.3) (2024-05-21) + + +### Bug Fixes + +* update to dartnissanconnect v1.0.5 ([#14](https://github.com/kamiKAC/leaf2mqtt/issues/14)) ([1d2315e](https://github.com/kamiKAC/leaf2mqtt/commit/1d2315ee762b6a764c6c203553e7fd40806b34c3)) + +## [0.0.2](https://github.com/kamiKAC/leaf2mqtt/compare/v0.0.2...v0.0.2) (2024-05-20) + + +### Continuous Integration + + +* Re-release v0.0.2 with dartnissanconnect v1.0.4 ([#12](https://github.com/kamiKAC/leaf2mqtt/issues/12)) ([551446c](https://github.com/kamiKAC/leaf2mqtt/commit/551446c5872921d36a6f662b55df5bce04ebb566)) diff --git a/Dockerfile b/Dockerfile index 14bcc1a..c4b716f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM dart:2.19.6-sdk AS build +ARG APP_VERSION=unknown RUN apt-get update && \ apt-get install -y git @@ -10,7 +11,7 @@ RUN dart pub get COPY . . RUN dart pub get --offline -RUN dart compile exe src/leaf_2_mqtt.dart -o src/leaf_2_mqtt +RUN dart compile exe -DAPP_VERSION=${APP_VERSION} src/leaf_2_mqtt.dart -o src/leaf_2_mqtt FROM scratch COPY --from=build /runtime/ / diff --git a/README.md b/README.md index c2e761a..8a5941a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -![Docker Pulls](https://img.shields.io/docker/pulls/yp87/leaf2mqtt) ![Docker Image Version (latest by date)](https://img.shields.io/docker/v/yp87/leaf2mqtt) +![Docker Pulls](https://img.shields.io/docker/pulls/kamikac/leaf2mqtt) ![Docker Image Version (latest by date)](https://img.shields.io/docker/v/kamikac/leaf2mqtt) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/kamiKAC/leaf2mqtt/leaf2mqtt.yml) + # leaf2mqtt > :warning: olderCanada and olderUSA support may break at anytime because Nissan keep changing the API key. Thank you Nissan for working against your customers. @@ -42,12 +43,12 @@ Should work with multiple Leafs, but it is untested. Please open an issue with f ### Home Assistant add-on Click the icon below to add this repository to your Home Assistant instance or follow the procedure highlighted on the [Home Assistant website](https://home-assistant.io/hassio/installing_third_party_addons). -[![Install leaf2mqtt add-on repo.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Fyp87%2Fleaf2mqtt) +[![Install leaf2mqtt add-on repo.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2FkamiKAC%2Fleaf2mqtt) ### Pre-built images -You can use pre-built images from here: https://hub.docker.com/r/yp87/leaf2mqtt +You can use pre-built images from here: https://hub.docker.com/r/kamikac/leaf2mqtt -tag example: `yp87/leaf2mqtt:latest` +tag example: `kamikac/leaf2mqtt:latest` ### Building the image @@ -180,6 +181,7 @@ In these examples, the `MQTT_BASE_TOPIC` is set to the default (`leaf`). | ------ | ---- | ----------- | | leaf/{vin}/location/latitude | String | The reported last known location's latitude in decimal degrees | | leaf/{vin}/location/longitude | String | The reported last known location's longitude in decimal degrees | +| leaf/{vin}/location/coordinates | String | The reported last known location (combined latitude and longitude in decimal degrees) | | leaf/{vin}/location/lastReceivedDateTimeUtc | Iso8601 UTC | The datetime when leaf2mqtt received the last location values | | leaf/{vin}/location/json | String | A json representation of all location status | @@ -267,6 +269,9 @@ In Home Assistant, calling a script like this `- service: script.some_script_nam # Let's have a cool down to give time to Home Assistant to update all the states. - delay: "00:00:10" +## OpenHAB integration +Once you configure and start application you can configure OpenHAB to get data for your Leaf. Example config file is [here](/openhab) and documentation is [here](/openhab/README.md) + ## Credits - Forked from [Troon/leaf2mqtt](https://github.com/Troon/leaf2mqtt). Thank you for the inspiration! - Using libraries from [Tobias Westergaard Kjeldsen](https://gitlab.com/tobiaswkjeldsen) to connect with the nissan leaf's APIs. Those libraries are also used for his [MyLeaf app](https://gitlab.com/tobiaswkjeldsen/carwingsflutter). diff --git a/addon/Dockerfile b/addon/Dockerfile index 1e19396..acd0e61 100644 --- a/addon/Dockerfile +++ b/addon/Dockerfile @@ -1,7 +1,7 @@ ARG BUILD_VERSION ARG BUILD_ARCH -FROM yp87/leaf2mqtt:${BUILD_VERSION} AS build +FROM kamikac/leaf2mqtt:${BUILD_VERSION} AS build FROM ghcr.io/hassio-addons/base/${BUILD_ARCH}:stable COPY --from=build / / diff --git a/addon/config.json b/addon/config.json index 12a6fa5..8abe897 100644 --- a/addon/config.json +++ b/addon/config.json @@ -1,14 +1,15 @@ { "name": "Leaf2MQTT", - "version": "46", + "version": "v0.1.0", "slug": "leaf2mqtt", "description": "Interact with your Nissan Leaf using MQTT", "startup": "application", - "url": "https://github.com/yp87/leaf2mqtt", + "url": "https://github.com/kamiKAC/leaf2mqtt", "init": false, "arch": [ "aarch64", - "amd64" + "amd64", + "armhf" ], "options": { "LEAF_USERNAME": "", diff --git a/docker-compose.yml b/docker-compose.yml index 6d7e53d..4132897 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,8 +3,7 @@ version: "3" services: leaf2mqtt: container_name: leaf2mqtt - build: . - image: leaf2mqtt + image: kamikac/leaf2mqtt logging: options: max-size: "1M" diff --git a/openhab/README.md b/openhab/README.md new file mode 100644 index 0000000..78a7a9d --- /dev/null +++ b/openhab/README.md @@ -0,0 +1,7 @@ +# OpenHAB example files for Leaf2MQTT + +To use this example config: + - copy `items`, `things` and `transform` directories to `openhab` directory (under Linux it is located under `/etc/) + - edit `.things` file so `mqtt:broker:mosquitto` Bridge points to your MQTT server or change Thing to point to your previously defined MQTT bridge + +Leaf Statistics should appear under `Cars` devices. diff --git a/openhab/items/leaf.items b/openhab/items/leaf.items new file mode 100644 index 0000000..4fef6f6 --- /dev/null +++ b/openhab/items/leaf.items @@ -0,0 +1,28 @@ +Group OF_Car "Nissan Leaf" (OF) ["Car"] + +tring Car_Update "Update" (OF_Car) ["Control"] { listWidget="oh-list-item"[actionItem="Car_Update", action="command" ,actionCommand="update", icon="f7:rectangle_split_3x1_fill"], channel="mqtt:topic:leaf:StatusUpdate" } +String Car_BatteryUpdate "Update battery state" (OF_Car) ["Control"] { listWidget="oh-list-item"[actionItem="Car_BatteryUpdate", action="command", actionCommand="update", icon="f7:rectangle_split_3x1_fill"], channel="mqtt:topic:leaf:StatusBatteryUpdate" } +String Car_LocationUpdate "Update location" (OF_Car) ["Control"] { listWidget="oh-list-item"[actionItem="Car_LocationUpdate", action="command", actionCommand="update", icon="f7:rectangle_split_3x1_fill"], channel="mqtt:topic:leaf:LocationUpdate" } +String Car_StatsUpdate "Update daily statistics" (OF_Car) ["Control"] { listWidget="oh-list-item"[actionItem="Car_StatsUpdate", action="command", actionCommand="='update ' + dayjs().format('YYYY-MM-DD HH:mm:ss')", icon="f7:rectangle_split_3x1_fill"], channel="mqtt:topic:leaf:DailyStatistics" } + +DateTime Car_StatsDate "Trip statistics for [%1$td-%1$tm-%1$ty]"