Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
madejackson committed Sep 26, 2024
1 parent 8225595 commit 8e9c70e
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 13 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -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

58 changes: 58 additions & 0 deletions .github/workflows/sync-fork.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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.

Expand Down
6 changes: 2 additions & 4 deletions modbus_mqtt_bridge/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
CMD ["python3", "adapter.py"]
8 changes: 4 additions & 4 deletions modbus_mqtt_bridge/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion repository.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: Modbus MQTT Bridge
url: 'https://github.com/MerzSebastian/hassio-ModbusMQTTBridge'
url: 'https://github.com/aseracorp/ModbusMQTTBridge'
maintainer: Sebastian Merz

0 comments on commit 8e9c70e

Please sign in to comment.