Add STORAGE_POLL_INTERVAL environment variable

pull/29/head 1.0.6
Daniel Chesterton 4 years ago
parent dc6b6c0149
commit d7e52c0843

@ -27,6 +27,8 @@ jobs:
ref: main 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
with:
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.5.1
- name: Login to DockerHub - name: Login to DockerHub

@ -16,6 +16,7 @@ It supports the following environment variables:
- `MQTT_PORT` (optional, default = 1883) - `MQTT_PORT` (optional, default = 1883)
- `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)
It exposes events to the following topics: It exposes events to the following topics:

@ -8,7 +8,6 @@ from json import dumps
import signal import signal
from threading import Timer from threading import Timer
storage_sensors_interval = 60 # 1 hour
is_exiting = False is_exiting = False
mqtt_client = None mqtt_client = None
@ -17,6 +16,7 @@ amcrest_host = os.getenv("AMCREST_HOST")
amcrest_port = int(os.getenv("AMCREST_PORT") or 80) amcrest_port = int(os.getenv("AMCREST_PORT") or 80)
amcrest_username = os.getenv("AMCREST_USERNAME") or "admin" amcrest_username = os.getenv("AMCREST_USERNAME") or "admin"
amcrest_password = os.getenv("AMCREST_PASSWORD") amcrest_password = os.getenv("AMCREST_PASSWORD")
storage_poll_interval = int(os.getenv("STORAGE_POLL_INTERVAL") or 3600)
mqtt_host = os.getenv("MQTT_HOST") or "localhost" mqtt_host = os.getenv("MQTT_HOST") or "localhost"
mqtt_qos = int(os.getenv("MQTT_QOS") or 0) mqtt_qos = int(os.getenv("MQTT_QOS") or 0)
@ -78,9 +78,9 @@ def exit_gracefully(rc, skip_mqtt=False):
os._exit(rc) os._exit(rc)
def refresh_storage_sensors(): def refresh_storage_sensors():
global camera, topics, storage_sensors_interval global camera, topics, storage_poll_interval
Timer(storage_sensors_interval, refresh_storage_sensors).start() Timer(storage_poll_interval, refresh_storage_sensors).start()
log("Fetching storage sensors...") log("Fetching storage sensors...")
try: try:
@ -239,6 +239,7 @@ if home_assistant:
json=True, json=True,
) )
if storage_poll_interval > 0:
mqtt_publish( mqtt_publish(
topics["home_assistant"]["storage_used_percent"], topics["home_assistant"]["storage_used_percent"],
base_config base_config
@ -288,6 +289,7 @@ mqtt_publish(topics["config"], {
"serial_number": serial_number, "serial_number": serial_number,
}, json=True) }, json=True)
if storage_poll_interval > 0:
refresh_storage_sensors() refresh_storage_sensors()
log("Listening for events...") log("Listening for events...")

Loading…
Cancel
Save