From e4e01b62ac16a5662df5633e575f005e40df089e Mon Sep 17 00:00:00 2001 From: madejackson Date: Thu, 26 Sep 2024 15:59:46 +0200 Subject: [PATCH] init --- .github/workflows/docker-image.yml | 75 ++++++++++++++++++++++++++++++ .github/workflows/sync-fork.yml | 58 +++++++++++++++++++++++ README.md | 8 ++-- modbus_mqtt_bridge/Dockerfile | 6 +-- modbus_mqtt_bridge/adapter.py | 8 ++-- repository.yaml | 2 +- 6 files changed, 144 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/sync-fork.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..3ffbefc --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,75 @@ +# +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the branch called `master`. +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: 'amd64,arm64' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + tags: type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@v6 + with: + context: modbus_mqtt_bridge + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + diff --git a/.github/workflows/sync-fork.yml b/.github/workflows/sync-fork.yml new file mode 100644 index 0000000..5e61020 --- /dev/null +++ b/.github/workflows/sync-fork.yml @@ -0,0 +1,58 @@ +name: 'Upstream Sync' + +on: + schedule: + - cron: '0 7 * * 1,4' + # scheduled at 07:00 every Monday and Thursday + + workflow_dispatch: # click the button on Github repo! + inputs: + sync_test_mode: # Adds a boolean option that appears during manual workflow run for easy test mode config + description: 'Fork Sync Test Mode' + type: boolean + default: false + +jobs: + sync_latest_from_upstream: + runs-on: ubuntu-latest + name: Sync latest commits from upstream repo + + steps: + # REQUIRED step + # Step 1: run a standard checkout action, provided by github + - name: Checkout target repo + uses: actions/checkout@v4 + with: + # optional: set the branch to checkout, + # sync action checks out your 'target_sync_branch' anyway + #ref: master + # REQUIRED if your upstream repo is private (see wiki) + persist-credentials: false + + # REQUIRED step + # Step 2: run the sync action + - name: Sync upstream changes + id: sync + uses: aormsby/Fork-Sync-With-Upstream-action@v3.4.1 + with: + target_sync_branch: master + # REQUIRED 'target_repo_token' exactly like this! + target_repo_token: ${{ secrets.GITHUB_TOKEN }} + upstream_sync_branch: master + upstream_sync_repo: MerzSebastian/hassio-ModbusMQTTBridge + #upstream_repo_access_token: ${{ secrets.UPSTREAM_REPO_SECRET }} + + # Set test_mode true during manual dispatch to run tests instead of the true action!! + test_mode: ${{ inputs.sync_test_mode }} + + # Step 3: Display a sample message based on the sync output var 'has_new_commits' + - name: New commits found + if: steps.sync.outputs.has_new_commits == 'true' + run: echo "New commits were found to sync." + + - name: No new commits + if: steps.sync.outputs.has_new_commits == 'false' + run: echo "There were no new commits." + + - name: Show value of 'has_new_commits' + run: echo ${{ steps.sync.outputs.has_new_commits }} diff --git a/README.md b/README.md index 3d024c3..08bdd03 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 'Modbus MQTT Bridge' is a Home Assistant add-on that allows users to easily add Modbus devices to their Home Assistant instance using a simple user interface. This add-on provides a way to connect USB Modbus devices to Home Assistant via MQTT, which can be easily integrated with other devices and sensors. -![main_page](https://raw.githubusercontent.com/MerzSebastian/hassio-ModbusMQTTBridge/main/modbus_mqtt_bridge/documentation/main_page.png) +![main_page](https://raw.githubusercontent.com/aseracorp/ModbusMQTTBridge/main/modbus_mqtt_bridge/documentation/main_page.png) # Installation @@ -18,7 +18,7 @@ To install this add-on, follow these steps: 5. Open the menu on the top right and click on Repositories -6. Add the following URL to the input field: https://github.com/MerzSebastian/hassio-ModbusMQTTBridge +6. Add the following URL to the input field: https://github.com/aseracorp/ModbusMQTTBridge 7. Click on the "Add" button @@ -31,10 +31,10 @@ To install this add-on, follow these steps: Once the add-on is installed and configured, open up the provided ui and add your devices. 1. Select a device from the devices list - ![device_not_selected](https://raw.githubusercontent.com/MerzSebastian/hassio-ModbusMQTTBridge/main/modbus_mqtt_bridge/documentation/device_not_selected.png) + ![device_not_selected](https://raw.githubusercontent.com/aseracorp/ModbusMQTTBridge/main/modbus_mqtt_bridge/documentation/device_not_selected.png) 2. Fill out the additional inputs and press on Add - ![device_selected](https://raw.githubusercontent.com/MerzSebastian/hassio-ModbusMQTTBridge/main/modbus_mqtt_bridge/documentation/device_selected.png) + ![device_selected](https://raw.githubusercontent.com/aseracorp/ModbusMQTTBridge/main/modbus_mqtt_bridge/documentation/device_selected.png) Info: Using multiple slaves on the same usb device is curretly untested because I only have a single modbus device on hand. diff --git a/modbus_mqtt_bridge/Dockerfile b/modbus_mqtt_bridge/Dockerfile index 1f8e422..8fc898d 100644 --- a/modbus_mqtt_bridge/Dockerfile +++ b/modbus_mqtt_bridge/Dockerfile @@ -1,6 +1,4 @@ -ARG BUILD_FROM -FROM $BUILD_FROM -#FROM alpine:3.14 +FROM alpine:3.14 # Install requirements for add-on RUN apk add --no-cache python3 @@ -19,4 +17,4 @@ RUN pip3 install -r requirements.txt COPY ui/src /ui/src COPY devices /devices -CMD ["/usr/bin/with-contenv", "exec", "python3", "adapter.py"] \ No newline at end of file +CMD ["python3", "adapter.py"] \ No newline at end of file diff --git a/modbus_mqtt_bridge/adapter.py b/modbus_mqtt_bridge/adapter.py index b74ee43..ac4dfe9 100644 --- a/modbus_mqtt_bridge/adapter.py +++ b/modbus_mqtt_bridge/adapter.py @@ -13,14 +13,14 @@ from datetime import datetime # MQTT Setup -mqtt_response = requests.get("http://supervisor/services/mqtt", headers={ "Authorization": "Bearer " + os.environ.get('SUPERVISOR_TOKEN') }).json() +""" mqtt_response = requests.get("http://supervisor/services/mqtt", headers={ "Authorization": "Bearer " + os.environ.get('SUPERVISOR_TOKEN') }).json() if "data" not in mqtt_response.keys(): sys.exit('FATAL ERROR | Seems like no mqtt service could be found. Are you sure you installed Mosquitto?') else: - mqtt_response = mqtt_response["data"] + mqtt_response = mqtt_response["data"] """ client = mqtt.Client() -client.username_pw_set(username=mqtt_response["username"], password=mqtt_response["password"]) -client.connect(mqtt_response["host"], mqtt_response["port"], 60) +""" client.username_pw_set(username=mqtt_response["username"], password=mqtt_response["password"]) """ +client.connect("Mosquitto", "1883", 60) def get_all_devices(): devices = [] diff --git a/repository.yaml b/repository.yaml index 588ebc4..58c9a1c 100644 --- a/repository.yaml +++ b/repository.yaml @@ -1,3 +1,3 @@ name: Modbus MQTT Bridge -url: 'https://github.com/MerzSebastian/hassio-ModbusMQTTBridge' +url: 'https://github.com/aseracorp/ModbusMQTTBridge' maintainer: Sebastian Merz \ No newline at end of file