diff --git a/config.yaml.sample b/config.yaml.sample index 4520b6b..509b91c 100644 --- a/config.yaml.sample +++ b/config.yaml.sample @@ -5,7 +5,6 @@ mqtt: password: password qos: 0 prefix: amcrest2mqtt - homeassistant: True discovery_prefix: homeassistant tls_enabled: False tls_ca_cert: filename @@ -33,4 +32,5 @@ amcrest: media: path: /media + max_size: 25 # per recording, in MB; default is 25 media_source: media-source://media_source/local/videos diff --git a/src/amcrest2mqtt/mixins/amcrest.py b/src/amcrest2mqtt/mixins/amcrest.py index 37def70..6445cb2 100644 --- a/src/amcrest2mqtt/mixins/amcrest.py +++ b/src/amcrest2mqtt/mixins/amcrest.py @@ -147,6 +147,7 @@ class AmcrestMixin: "avty_t": self.mqtt_helper.avty_t(device_id), "clip_url": f"media-source://media_source/local/Videos/amcrest/{device["device_name"]}-latest.mp4", "icon": "mdi:web", + "enabled_by_default": False, "via_device": self.mqtt_helper.service_slug, "device": device_block, } diff --git a/src/amcrest2mqtt/mixins/helpers.py b/src/amcrest2mqtt/mixins/helpers.py index 9a997f8..862bf42 100644 --- a/src/amcrest2mqtt/mixins/helpers.py +++ b/src/amcrest2mqtt/mixins/helpers.py @@ -168,7 +168,8 @@ class HelpersMixin: if os.path.exists(media_path) and os.access(media_path, os.W_OK): media["path"] = media_path - self.logger.info(f"storing recordings in {media_path}, watch that it doesn't fill up the file system") + media.setdefault("max_size", 25) + self.logger.info(f"storing recordings in {media_path} up to {media["max_size"]} MB per file. Watch that it doesn't fill up the file system") else: self.logger.info("media_path not configured, not found, or is not writable. Will not be saving recordings") @@ -240,6 +241,11 @@ class HelpersMixin: file_name = f"{name}-{time}.mp4" file_path = Path(f"{path}/{file_name}") + # last chance to skip the recording + if self.b_to_mb(len(recording)) > self.config["media"]["max_size"]: + self.logger.info(f"Skipping saving recording to {path} because {self.b_to_mb(len(recording))} > {self.config["media"]["max_size"]} MB") + return None + try: file_path.write_bytes(recording.encode("latin-1")) except IOError as err: