Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b85a28e01 | ||
|
|
b6e6dc1eca | ||
|
|
2a683fefc8 | ||
|
|
a94b964f9f | ||
|
|
afb215850c | ||
|
|
c99b918e84 | ||
|
|
df45393453 | ||
|
|
f5b655dbf1 |
5
.github/workflows/publish.yml
vendored
5
.github/workflows/publish.yml
vendored
@@ -21,6 +21,10 @@ jobs:
|
|||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2.3.4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v1.2.0
|
uses: docker/setup-qemu-action@v1.2.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
@@ -33,6 +37,7 @@ jobs:
|
|||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v2.5.0
|
uses: docker/build-push-action@v2.5.0
|
||||||
with:
|
with:
|
||||||
|
context: .
|
||||||
push: true
|
push: true
|
||||||
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
|
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
|
||||||
tags: |
|
tags: |
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ RUN mkdir /install
|
|||||||
WORKDIR /install
|
WORKDIR /install
|
||||||
|
|
||||||
COPY requirements.txt /
|
COPY requirements.txt /
|
||||||
RUN pip install --prefix=/install -r /requirements.txt
|
RUN pip install --no-warn-script-location --prefix=/install -r /requirements.txt
|
||||||
|
|
||||||
FROM base
|
FROM base
|
||||||
COPY --from=builder /install /usr/local
|
COPY --from=builder /install /usr/local
|
||||||
COPY src /app
|
COPY src /app
|
||||||
|
COPY VERSION /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
CMD [ "python", "-u", "/app/amcrest2mqtt.py" ]
|
CMD [ "python", "-u", "/app/amcrest2mqtt.py" ]
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ mqtt_password = os.getenv("MQTT_PASSWORD") # can be None
|
|||||||
home_assistant = os.getenv("HOME_ASSISTANT") == "true"
|
home_assistant = os.getenv("HOME_ASSISTANT") == "true"
|
||||||
home_assistant_prefix = os.getenv("HOME_ASSISTANT_PREFIX") or "homeassistant"
|
home_assistant_prefix = os.getenv("HOME_ASSISTANT_PREFIX") or "homeassistant"
|
||||||
|
|
||||||
|
def read_file(file_name):
|
||||||
|
with open(file_name, 'r') as file:
|
||||||
|
data = file.read().replace('\n', '')
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def read_version():
|
||||||
|
if os.path.isfile("./VERSION"):
|
||||||
|
return read_file("./VERSION")
|
||||||
|
|
||||||
|
return read_file("../VERSION")
|
||||||
|
|
||||||
# Helper functions and callbacks
|
# Helper functions and callbacks
|
||||||
def log(msg, level="INFO"):
|
def log(msg, level="INFO"):
|
||||||
ts = datetime.now(timezone.utc).strftime("%d/%m/%Y %H:%M:%S")
|
ts = datetime.now(timezone.utc).strftime("%d/%m/%Y %H:%M:%S")
|
||||||
@@ -102,6 +114,10 @@ if mqtt_username is None:
|
|||||||
log("Please set the MQTT_USERNAME environment variable", level="ERROR")
|
log("Please set the MQTT_USERNAME environment variable", level="ERROR")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
version = read_version()
|
||||||
|
|
||||||
|
log(f"App Version: {version}")
|
||||||
|
|
||||||
# Handle interruptions
|
# Handle interruptions
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
@@ -129,6 +145,7 @@ log(f"Device name: {device_name}")
|
|||||||
|
|
||||||
# MQTT topics
|
# MQTT topics
|
||||||
topics = {
|
topics = {
|
||||||
|
"config": f"amcrest2mqtt/{serial_number}/config",
|
||||||
"status": f"amcrest2mqtt/{serial_number}/status",
|
"status": f"amcrest2mqtt/{serial_number}/status",
|
||||||
"event": f"amcrest2mqtt/{serial_number}/event",
|
"event": f"amcrest2mqtt/{serial_number}/event",
|
||||||
"motion": f"amcrest2mqtt/{serial_number}/motion",
|
"motion": f"amcrest2mqtt/{serial_number}/motion",
|
||||||
@@ -263,6 +280,14 @@ if home_assistant:
|
|||||||
|
|
||||||
# Main loop
|
# Main loop
|
||||||
mqtt_publish(topics["status"], "online")
|
mqtt_publish(topics["status"], "online")
|
||||||
|
mqtt_publish(topics["config"], {
|
||||||
|
"version": version,
|
||||||
|
"device_type": device_type,
|
||||||
|
"device_name": device_name,
|
||||||
|
"sw_version": sw_version,
|
||||||
|
"serial_number": serial_number,
|
||||||
|
}, json=True)
|
||||||
|
|
||||||
refresh_storage_sensors()
|
refresh_storage_sensors()
|
||||||
|
|
||||||
log("Listening for events...")
|
log("Listening for events...")
|
||||||
|
|||||||
Reference in New Issue
Block a user