1
0
mirror of synced 2026-03-09 20:13:40 +00:00

Compare commits

12 Commits
1.0.15 ... main

Author SHA1 Message Date
bump_version
9917b41381 Version 1.0.16 [skip ci] 2022-03-23 12:31:00 +00:00
Daniel Chesterton
d23d12fbb2 Various updates
- Bump dependencies
- Remove ping functionality in favour of new python-amcrest functionality (closes #33 and #38)
- Fix issue with MQTT publish hanging indefinitely if the app cannot connect to broker
- Display build date in software version (closes #53)
2022-03-23 12:30:33 +00:00
Daniel Chesterton
948a8b565d Merge pull request #62 from dchesterton/dependabot/github_actions/actions/checkout-3
[ci skip]: Bump actions/checkout from 2.4.0 to 3
2022-03-23 10:17:16 +00:00
Daniel Chesterton
479bd008b6 Merge pull request #61 from dchesterton/dependabot/github_actions/docker/login-action-1.14.1
[ci skip]: Bump docker/login-action from 1.12.0 to 1.14.1
2022-03-23 10:17:05 +00:00
Daniel Chesterton
d67afe7eda Merge pull request #66 from dchesterton/dependabot/github_actions/docker/build-push-action-2.10.0
[ci skip]: Bump docker/build-push-action from 2.7.0 to 2.10.0
2022-03-23 10:16:56 +00:00
dependabot[bot]
9950622314 [ci skip]: Bump docker/build-push-action from 2.7.0 to 2.10.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 2.7.0 to 2.10.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v2.7.0...v2.10.0)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-15 12:06:52 +00:00
Daniel Chesterton
72decbcc05 [ci skip] Merge pull request #64 from SirGoodenough/main
Mention HA Addons in out of scope
2022-03-15 11:46:02 +00:00
Sir GoodEnough
e75365fc26 HA Addons Section 2022-03-09 17:10:37 -06:00
Sir GoodEnough
4562f5d31d HA Addons Section 2022-03-09 17:08:08 -06:00
dependabot[bot]
5623e60da7 [ci skip]: Bump actions/checkout from 2.4.0 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 12:08:50 +00:00
dependabot[bot]
93f239feeb [ci skip]: Bump docker/login-action from 1.12.0 to 1.14.1
Bumps [docker/login-action](https://github.com/docker/login-action) from 1.12.0 to 1.14.1.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](https://github.com/docker/login-action/compare/v1.12.0...v1.14.1)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 12:08:48 +00:00
bump_version
cbb3b4734b Version 1.0.15 [skip ci] 2021-12-31 03:21:49 +00:00
5 changed files with 47 additions and 40 deletions

View File

@@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2.4.0 uses: actions/checkout@v3
- name: Bump version - name: Bump version
uses: remorses/bump-version@js uses: remorses/bump-version@js
id: version id: version
@@ -21,7 +21,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2.4.0 uses: actions/checkout@v3
with: with:
ref: main ref: main
- name: Set up QEMU - name: Set up QEMU
@@ -31,12 +31,12 @@ jobs:
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.6.0 uses: docker/setup-buildx-action@v1.6.0
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1.12.0 uses: docker/login-action@v1.14.1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push - name: Build and push
uses: docker/build-push-action@v2.7.0 uses: docker/build-push-action@v2.10.0
with: with:
context: . context: .
push: true push: true

View File

@@ -20,7 +20,7 @@ It supports the following environment variables:
- `MQTT_TLS_KEY` (required if using TLS) - path to the private key - `MQTT_TLS_KEY` (required if using TLS) - path to the private key
- `HOME_ASSISTANT` (optional, default = false) - `HOME_ASSISTANT` (optional, default = false)
- `HOME_ASSISTANT_PREFIX` (optional, default = 'homeassistant') - `HOME_ASSISTANT_PREFIX` (optional, default = 'homeassistant')
- `STORAGE_POLL_INTERVAL` (optional, default = 3600) - how often to fetch storage data (in seconds) - `STORAGE_POLL_INTERVAL` (optional, default = 3600) - how often to fetch storage data (in seconds) (set to 0 to disable functionality)
- `DEVICE_NAME` (optional) - override the default device name used in the Amcrest app - `DEVICE_NAME` (optional) - override the default device name used in the Amcrest app
It exposes events to the following topics: It exposes events to the following topics:
@@ -70,6 +70,16 @@ The app will not support multiple devices. You can run multiple instances of the
Docker is the only supported way of deploying the application. The app should run directly via Python but this is not supported. Docker is the only supported way of deploying the application. The app should run directly via Python but this is not supported.
### Home Assistant Addons
There are a couple of Home Assistant Addons that use my code to be able to port this software into Supervised versions of Home Assistant. I do not specifically support the add-ons themselves, only the base software in the original docker format. Please contact the authors of those add-ons for support if using that method.
https://github.com/ikifar2012/amcrest2mqtt-addon/blob/master/README.md
[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](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%2Fikifar2012%2Fha-addons)
https://github.com/robsonke/hassio-addons/blob/master/amcrest2mqtt/README.md
[![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](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%2Frobsonke%2Fhassio-addons)
## Buy Me A ~~Coffee~~ Beer 🍻 ## Buy Me A ~~Coffee~~ Beer 🍻
A few people have kindly requested a way to donate a small amount of money. If you feel so inclined I've set up a "Buy Me A Coffee" A few people have kindly requested a way to donate a small amount of money. If you feel so inclined I've set up a "Buy Me A Coffee"

View File

@@ -1 +1 @@
1.0.14 1.0.16

View File

@@ -1,3 +1,3 @@
amcrest==1.9.3 amcrest==1.9.7
paho-mqtt==1.6.1 paho-mqtt==1.6.1
python-slugify==5.0.2 python-slugify==6.1.1

View File

@@ -8,6 +8,7 @@ from json import dumps
import signal import signal
from threading import Timer from threading import Timer
import ssl import ssl
import asyncio
is_exiting = False is_exiting = False
mqtt_client = None mqtt_client = None
@@ -59,8 +60,8 @@ def mqtt_publish(topic, payload, exit_on_error=True, json=False):
) )
if msg.rc == mqtt.MQTT_ERR_SUCCESS: if msg.rc == mqtt.MQTT_ERR_SUCCESS:
msg.wait_for_publish() msg.wait_for_publish(2)
return msg return
log(f"Error publishing MQTT message: {mqtt.error_string(msg.rc)}", level="ERROR") log(f"Error publishing MQTT message: {mqtt.error_string(msg.rc)}", level="ERROR")
@@ -79,7 +80,6 @@ def exit_gracefully(rc, skip_mqtt=False):
if mqtt_client is not None and mqtt_client.is_connected() and skip_mqtt == False: if mqtt_client is not None and mqtt_client.is_connected() and skip_mqtt == False:
mqtt_publish(topics["status"], "offline", exit_on_error=False) mqtt_publish(topics["status"], "offline", exit_on_error=False)
mqtt_client.loop_stop(force=True)
mqtt_client.disconnect() mqtt_client.disconnect()
# Use os._exit instead of sys.exit to ensure an MQTT disconnect event causes the program to exit correctly as they # Use os._exit instead of sys.exit to ensure an MQTT disconnect event causes the program to exit correctly as they
@@ -104,14 +104,6 @@ def refresh_storage_sensors():
def to_gb(total): def to_gb(total):
return str(round(float(total[0]) / 1024 / 1024 / 1024, 2)) return str(round(float(total[0]) / 1024 / 1024 / 1024, 2))
def ping_camera():
Timer(30, ping_camera).start()
response = os.system(f"ping -c1 -W100 {amcrest_host} >/dev/null 2>&1")
if response != 0:
log("Ping unsuccessful", level="ERROR")
exit_gracefully(1)
def signal_handler(sig, frame): def signal_handler(sig, frame):
# exit immediately upon receiving a second SIGINT # exit immediately upon receiving a second SIGINT
global is_exiting global is_exiting
@@ -162,6 +154,10 @@ try:
exit_gracefully(1) exit_gracefully(1)
sw_version = camera.software_information[0].replace("version=", "").strip() sw_version = camera.software_information[0].replace("version=", "").strip()
build_version = camera.software_information[1].strip()
amcrest_version = f"{sw_version} ({build_version})"
if not device_name: if not device_name:
device_name = camera.machine_name.replace("name=", "").strip() device_name = camera.machine_name.replace("name=", "").strip()
@@ -172,7 +168,7 @@ except AmcrestError as error:
log(f"Device type: {device_type}") log(f"Device type: {device_type}")
log(f"Serial number: {serial_number}") log(f"Serial number: {serial_number}")
log(f"Software version: {sw_version}") log(f"Software version: {amcrest_version}")
log(f"Device name: {device_name}") log(f"Device name: {device_name}")
# MQTT topics # MQTT topics
@@ -256,7 +252,7 @@ if home_assistant:
"manufacturer": "Amcrest", "manufacturer": "Amcrest",
"model": device_type, "model": device_type,
"identifiers": serial_number, "identifiers": serial_number,
"sw_version": sw_version, "sw_version": amcrest_version,
"via_device": "amcrest2mqtt", "via_device": "amcrest2mqtt",
}, },
} }
@@ -411,7 +407,7 @@ mqtt_publish(topics["config"], {
"version": version, "version": version,
"device_type": device_type, "device_type": device_type,
"device_name": device_name, "device_name": device_name,
"sw_version": sw_version, "sw_version": amcrest_version,
"serial_number": serial_number, "serial_number": serial_number,
"host": amcrest_host, "host": amcrest_host,
}, json=True) }, json=True)
@@ -419,25 +415,26 @@ mqtt_publish(topics["config"], {
if storage_poll_interval > 0: if storage_poll_interval > 0:
refresh_storage_sensors() refresh_storage_sensors()
ping_camera()
log("Listening for events...") log("Listening for events...")
try: async def main():
for code, payload in camera.event_actions("All", retries=5, timeout_cmd=(10.00, 3600)): try:
if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110): async for code, payload in camera.async_event_actions("All"):
motion_payload = "on" if payload["action"] == "Start" else "off" if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110):
mqtt_publish(topics["motion"], motion_payload) motion_payload = "on" if payload["action"] == "Start" else "off"
elif code == "CrossRegionDetection" and payload["data"]["ObjectType"] == "Human": mqtt_publish(topics["motion"], motion_payload)
human_payload = "on" if payload["action"] == "Start" else "off" elif code == "CrossRegionDetection" and payload["data"]["ObjectType"] == "Human":
mqtt_publish(topics["human"], human_payload) human_payload = "on" if payload["action"] == "Start" else "off"
elif code == "_DoTalkAction_": mqtt_publish(topics["human"], human_payload)
doorbell_payload = "on" if payload["data"]["Action"] == "Invite" else "off" elif code == "_DoTalkAction_":
mqtt_publish(topics["doorbell"], doorbell_payload) doorbell_payload = "on" if payload["data"]["Action"] == "Invite" else "off"
mqtt_publish(topics["doorbell"], doorbell_payload)
mqtt_publish(topics["event"], payload, json=True) mqtt_publish(topics["event"], payload, json=True)
log(str(payload)) log(str(payload))
except AmcrestError as error: except AmcrestError as error:
log(f"Amcrest error {error}", level="ERROR") log(f"Amcrest error: {error}", level="ERROR")
exit_gracefully(1) exit_gracefully(1)
asyncio.run(main())