forked from viewit/KX-Bridge-Release
Merge pull request 'Enhancements' (#5) from enhance into master
Reviewed-on: http://192.168.1.103:3000/fenopy/KX-Bridge-Release/pulls/5
This commit is contained in:
@@ -800,6 +800,7 @@ class KobraXBridge:
|
||||
self._camera_autostarted: bool = False
|
||||
self.camera_cache: CameraCache = CameraCache()
|
||||
self._prev_kobra_state: str = ""
|
||||
self._print_active: bool = False
|
||||
self._notify_every_minutes: int = 0
|
||||
self._notify_every_layers: int = 0
|
||||
self._last_progress_notif_time: float = 0.0
|
||||
@@ -947,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
|
||||
@@ -963,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:
|
||||
@@ -1061,14 +1074,19 @@ class KobraXBridge:
|
||||
if kobra_state and kobra_state != self._prev_kobra_state:
|
||||
_notif_filename = d.get("filename", self._state.get("filename", ""))
|
||||
if kobra_state == "printing":
|
||||
self._notify("started", _notif_filename)
|
||||
self._last_progress_notif_time = time.monotonic()
|
||||
self._last_progress_notif_layer = self._state.get("curr_layer", 0)
|
||||
if not self._print_active:
|
||||
self._print_active = True
|
||||
self._notify("started", _notif_filename)
|
||||
self._last_progress_notif_time = time.monotonic()
|
||||
self._last_progress_notif_layer = self._state.get("curr_layer", 0)
|
||||
elif kobra_state == "finished":
|
||||
self._print_active = False
|
||||
self._notify("finished", _notif_filename)
|
||||
elif kobra_state == "failed":
|
||||
self._print_active = False
|
||||
self._notify("failed", _notif_filename)
|
||||
elif kobra_state in ("stoped", "canceled"):
|
||||
self._print_active = False
|
||||
self._notify("cancelled", _notif_filename)
|
||||
elif kobra_state == "paused":
|
||||
self._notify("paused", _notif_filename)
|
||||
@@ -1138,6 +1156,7 @@ class KobraXBridge:
|
||||
log.warning(f"Kamera-Autostart fehlgeschlagen: {e}")
|
||||
elif kobra_state in ("free", "finished", "stoped", "canceled"):
|
||||
self._camera_autostarted = False
|
||||
self._print_active = False
|
||||
if project:
|
||||
if "filename" in project:
|
||||
self._state["filename"] = project["filename"]
|
||||
|
||||
Reference in New Issue
Block a user