1
0
mirror of synced 2026-03-10 04:23:39 +00:00

Compare commits

23 Commits

Author SHA1 Message Date
Daniel Chesterton
594a42320f Fix issue with fetching serial number (closes #35) 2021-10-26 21:38:19 +01:00
Daniel Chesterton
2886e5c1ca Merge pull request #36 from dchesterton/dependabot/github_actions/docker/build-push-action-2.7.0
[ci skip]: Bump docker/build-push-action from 2.6.1 to 2.7.0
2021-10-26 21:25:18 +01:00
Daniel Chesterton
9ba2544237 Merge pull request #39 from dchesterton/dependabot/github_actions/docker/setup-buildx-action-1.6.0
[ci skip]: Bump docker/setup-buildx-action from 1.5.1 to 1.6.0
2021-10-26 21:25:03 +01:00
bump_version
0ccdc6fe11 Version 1.0.10 [skip ci] 2021-10-26 20:13:44 +00:00
Daniel Chesterton
ed38b86eb6 Change bump-version 2021-10-26 21:13:17 +01:00
Daniel Chesterton
9d3d44f36b Merge pull request #46 from dchesterton/dependabot/pip/paho-mqtt-1.6.1
Bump paho-mqtt from 1.5.1 to 1.6.1
2021-10-26 21:09:59 +01:00
dependabot[bot]
8cb2cc2327 Bump paho-mqtt from 1.5.1 to 1.6.1
Bumps [paho-mqtt](https://github.com/eclipse/paho.mqtt.python) from 1.5.1 to 1.6.1.
- [Release notes](https://github.com/eclipse/paho.mqtt.python/releases)
- [Changelog](https://github.com/eclipse/paho.mqtt.python/blob/master/ChangeLog.txt)
- [Commits](https://github.com/eclipse/paho.mqtt.python/compare/v1.5.1...v1.6.1)

---
updated-dependencies:
- dependency-name: paho-mqtt
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-26 20:07:01 +00:00
Daniel Chesterton
4d4961e842 Merge pull request #45 from dchesterton/dependabot/github_actions/actions/checkout-2.3.5
[ci skip]: Bump actions/checkout from 2.3.4 to 2.3.5
2021-10-26 21:06:39 +01:00
Daniel Chesterton
cbb1995deb Merge pull request #42 from dchesterton/dependabot/pip/amcrest-1.9.3
Bump amcrest from 1.8.0 to 1.9.3
2021-10-26 21:06:20 +01:00
dependabot[bot]
781becf0d0 [ci skip]: Bump actions/checkout from 2.3.4 to 2.3.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5.
- [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.3.4...v2.3.5)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-18 12:06:55 +00:00
dependabot[bot]
8a1b1945ff Bump amcrest from 1.8.0 to 1.9.3
Bumps [amcrest](https://github.com/tchellomello/python-amcrest) from 1.8.0 to 1.9.3.
- [Release notes](https://github.com/tchellomello/python-amcrest/releases)
- [Commits](https://github.com/tchellomello/python-amcrest/compare/1.8.0...1.9.3)

---
updated-dependencies:
- dependency-name: amcrest
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-20 12:03:25 +00:00
dependabot[bot]
65623b45a2 [ci skip]: Bump docker/setup-buildx-action from 1.5.1 to 1.6.0
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 1.5.1 to 1.6.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v1.5.1...v1.6.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-06 12:05:58 +00:00
dependabot[bot]
4af6eac710 [ci skip]: Bump docker/build-push-action from 2.6.1 to 2.7.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 2.6.1 to 2.7.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v2.6.1...v2.7.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>
2021-08-20 12:06:38 +00:00
bump_version
7bbe3cbcf4 Version 1.0.9 [skip ci] 2021-08-07 20:26:29 +00:00
Daniel Chesterton
8e96fc5408 Add ping functionality to stop app hanging 2021-08-07 21:26:07 +01:00
bump_version
0f8858cef4 Version 1.0.8 [skip ci] 2021-08-03 17:10:40 +00:00
Daniel Chesterton
e43cda557a Merge pull request #31 from dchesterton/dependabot/pip/amcrest-1.8.0
Bump amcrest from 1.7.2 to 1.8.0
2021-08-03 18:10:19 +01:00
dependabot[bot]
7dff1b3bf4 Bump amcrest from 1.7.2 to 1.8.0
Bumps [amcrest](https://github.com/tchellomello/python-amcrest) from 1.7.2 to 1.8.0.
- [Release notes](https://github.com/tchellomello/python-amcrest/releases)
- [Commits](https://github.com/tchellomello/python-amcrest/compare/1.7.2...1.8.0)

---
updated-dependencies:
- dependency-name: amcrest
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-02 12:03:54 +00:00
bump_version
28f2761899 Version 1.0.7 [skip ci] 2021-07-27 17:01:21 +00:00
Daniel Chesterton
17854bda0f Merge pull request #29 from bennycooly/feature/mqtt-tls
Add TLS support
2021-07-27 18:01:02 +01:00
Ben Fu
88323631ea Update README with TLS vars 2021-07-26 10:40:26 -05:00
Ben Fu
2a56eee4f5 Add TLS support 2021-07-26 09:51:18 -05:00
bump_version
caacaea81f Version 1.0.6 [skip ci] 2021-07-18 20:23:21 +00:00
5 changed files with 67 additions and 18 deletions

View File

@@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2.3.4 uses: actions/checkout@v2.3.5
- name: Bump version - name: Bump version
uses: remorses/bump-version@js uses: chamini2/bump-version@js
id: version id: version
with: with:
version_file: ./VERSION version_file: ./VERSION
@@ -22,7 +22,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2.3.4 uses: actions/checkout@v2.3.5
with: with:
ref: main ref: main
- name: Set up QEMU - name: Set up QEMU
@@ -30,14 +30,14 @@ jobs:
with: with:
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
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.5.1 uses: docker/setup-buildx-action@v1.6.0
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1.10.0 uses: docker/login-action@v1.10.0
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.6.1 uses: docker/build-push-action@v2.7.0
with: with:
context: . context: .
push: true push: true

View File

@@ -14,6 +14,10 @@ It supports the following environment variables:
- `MQTT_HOST` (optional, default = 'localhost') - `MQTT_HOST` (optional, default = 'localhost')
- `MQTT_QOS` (optional, default = 0) - `MQTT_QOS` (optional, default = 0)
- `MQTT_PORT` (optional, default = 1883) - `MQTT_PORT` (optional, default = 1883)
- `MQTT_TLS_ENABLED` (required if using TLS) - set to `true` to enable
- `MQTT_TLS_CA_CERT` (required if using TLS) - path to the ca certs
- `MQTT_TLS_CERT` (required if using TLS) - path to the private cert
- `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)

View File

@@ -1 +1 @@
1.0.5 1.0.10

View File

@@ -1,3 +1,3 @@
amcrest==1.7.2 amcrest==1.9.3
paho-mqtt==1.5.1 paho-mqtt==1.6.1
python-slugify==5.0.2 python-slugify==5.0.2

View File

@@ -7,6 +7,7 @@ import sys
from json import dumps from json import dumps
import signal import signal
from threading import Timer from threading import Timer
import ssl
is_exiting = False is_exiting = False
mqtt_client = None mqtt_client = None
@@ -23,6 +24,10 @@ mqtt_qos = int(os.getenv("MQTT_QOS") or 0)
mqtt_port = int(os.getenv("MQTT_PORT") or 1883) mqtt_port = int(os.getenv("MQTT_PORT") or 1883)
mqtt_username = os.getenv("MQTT_USERNAME") mqtt_username = os.getenv("MQTT_USERNAME")
mqtt_password = os.getenv("MQTT_PASSWORD") # can be None mqtt_password = os.getenv("MQTT_PASSWORD") # can be None
mqtt_tls_enabled = os.getenv("MQTT_TLS_ENABLED") == "true"
mqtt_tls_ca_cert = os.getenv("MQTT_TLS_CA_CERT")
mqtt_tls_cert = os.getenv("MQTT_TLS_CERT")
mqtt_tls_key = os.getenv("MQTT_TLS_KEY")
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"
@@ -68,6 +73,8 @@ def on_mqtt_disconnect(client, userdata, rc):
def exit_gracefully(rc, skip_mqtt=False): def exit_gracefully(rc, skip_mqtt=False):
global topics, mqtt_client global topics, mqtt_client
log("Exiting app...")
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.loop_stop(force=True)
@@ -91,6 +98,14 @@ def refresh_storage_sensors():
except AmcrestError as error: except AmcrestError as error:
log(f"Error fetching storage information {error}", level="WARNING") log(f"Error fetching storage information {error}", level="WARNING")
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
@@ -129,14 +144,23 @@ camera = AmcrestCamera(
# Fetch camera details # Fetch camera details
log("Fetching camera details...") log("Fetching camera details...")
device_type = camera.device_type.replace("type=", "").strip() try:
is_ad110 = device_type == "AD110" device_type = camera.device_type.replace("type=", "").strip()
is_ad410 = device_type == "AD410" is_ad110 = device_type == "AD110"
is_doorbell = is_ad110 or is_ad410 is_ad410 = device_type == "AD410"
serial_number = camera.serial_number.strip() is_doorbell = is_ad110 or is_ad410
sw_version = camera.software_information[0].replace("version=", "").strip() serial_number = camera.serial_number
device_name = camera.machine_name.replace("name=", "").strip()
device_slug = slugify(device_name, separator="_") if not isinstance(serial_number, str):
log(f"Error fetching serial number", level="ERROR")
exit_gracefully(1)
sw_version = camera.software_information[0].replace("version=", "").strip()
device_name = camera.machine_name.replace("name=", "").strip()
device_slug = slugify(device_name, separator="_")
except AmcrestError as error:
log(f"Error fetching camera details", level="ERROR")
exit_gracefully(1)
log(f"Device type: {device_type}") log(f"Device type: {device_type}")
log(f"Serial number: {serial_number}") log(f"Serial number: {serial_number}")
@@ -169,8 +193,27 @@ mqtt_client = mqtt.Client(
client_id=f"amcrest2mqtt_{serial_number}", clean_session=False client_id=f"amcrest2mqtt_{serial_number}", clean_session=False
) )
mqtt_client.on_disconnect = on_mqtt_disconnect mqtt_client.on_disconnect = on_mqtt_disconnect
mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
mqtt_client.will_set(topics["status"], payload="offline", qos=mqtt_qos, retain=True) mqtt_client.will_set(topics["status"], payload="offline", qos=mqtt_qos, retain=True)
if mqtt_tls_enabled:
log(f"Setting up MQTT for TLS")
if mqtt_tls_ca_cert is None:
log("Missing var: MQTT_TLS_CA_CERT", level="ERROR")
sys.exit(1)
if mqtt_tls_cert is None:
log("Missing var: MQTT_TLS_CERT", level="ERROR")
sys.exit(1)
if mqtt_tls_cert is None:
log("Missing var: MQTT_TLS_KEY", level="ERROR")
sys.exit(1)
mqtt_client.tls_set(
ca_certs=mqtt_tls_ca_cert,
certfile=mqtt_tls_cert,
keyfile=mqtt_tls_key,
cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLS,
)
else:
mqtt_client.username_pw_set(mqtt_username, password=mqtt_password)
try: try:
mqtt_client.connect(mqtt_host, port=mqtt_port) mqtt_client.connect(mqtt_host, port=mqtt_port)
@@ -292,10 +335,12 @@ 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: try:
for code, payload in camera.event_actions("All", retries=5): for code, payload in camera.event_actions("All", retries=5, timeout_cmd=(10.00, 3600)):
if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110): if (is_ad110 and code == "ProfileAlarmTransmit") or (code == "VideoMotion" and not is_ad110):
motion_payload = "on" if payload["action"] == "Start" else "off" motion_payload = "on" if payload["action"] == "Start" else "off"
mqtt_publish(topics["motion"], motion_payload) mqtt_publish(topics["motion"], motion_payload)