From af666c119ba67ac713925a505428d94b77b8f2da Mon Sep 17 00:00:00 2001 From: Jeff Culverhouse Date: Tue, 27 Jan 2026 13:01:13 -0500 Subject: [PATCH] fix: handle cameras without SD card storage Return default values (0) for storage stats when a camera has no SD card instead of an empty dict. This prevents KeyError when build_device_states tries to access storage["used"]. Co-Authored-By: Claude Opus 4.5 --- src/amcrest2mqtt/mixins/amcrest_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amcrest2mqtt/mixins/amcrest_api.py b/src/amcrest2mqtt/mixins/amcrest_api.py index 818a792..73656b9 100644 --- a/src/amcrest2mqtt/mixins/amcrest_api.py +++ b/src/amcrest2mqtt/mixins/amcrest_api.py @@ -191,7 +191,7 @@ class AmcrestAPIMixin: device = self.amcrest_devices[device_id] states = self.states[device_id] - # return our last known state if something fails + # return our last known state if something fails, or defaults for cameras without storage current: dict[str, str | float] = ( { "used_percent": states["sensor"].get("storage_used_pct", 0), @@ -199,7 +199,7 @@ class AmcrestAPIMixin: "total": states["sensor"].get("storage_total", 0), } if "sensor" in states - else {} + else {"used_percent": 0, "used": 0, "total": 0} ) if not device["camera"]: