fix: sending images in notifs

This commit is contained in:
2026-06-03 14:48:34 -05:00
parent 9abe2daa8f
commit 068976ebc4

View File

@@ -948,7 +948,6 @@ class KobraXBridge:
urls_plain = [e["url"] for e in matching if not e.get("include_image")]
urls_image = [e["url"] for e in matching if e.get("include_image")]
jpeg_bytes = self.camera_cache.latest_jpeg if urls_image else b""
def _send():
import apprise, os, tempfile
@@ -964,12 +963,25 @@ class KobraXBridge:
ap2.add(u)
attach = None
tmppath = None
if jpeg_bytes:
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as f:
f.write(jpeg_bytes)
tmppath = f.name
attach = apprise.AppriseAttachment()
attach.add(tmppath)
jpeg = self.camera_cache.latest_jpeg
if not jpeg and self.camera_cache._url:
# Camera URL is set but no frame yet — wait briefly (camera may be starting)
deadline = time.monotonic() + 5.0
while not jpeg and time.monotonic() < deadline:
time.sleep(0.3)
jpeg = self.camera_cache.latest_jpeg
if jpeg:
try:
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as f:
f.write(jpeg)
tmppath = f.name
attach = apprise.AppriseAttachment()
attach.add(tmppath)
except Exception as e:
log.warning(f"Kamera-Anhang fehlgeschlagen: {e}")
attach = None
else:
log.debug("Bild-Benachrichtigung ohne Anhang (kein Kamera-Frame verfügbar)")
ap2.notify(title=title, body=body, attach=attach)
if tmppath:
try: