Refresh snapshots after light actions
This commit is contained in:
@@ -235,6 +235,11 @@ def config_from_env():
|
||||
"snapshot_retry_seconds": int(os.environ.get("SNAPSHOT_RETRY_SECONDS", "600")),
|
||||
"snapshot_refresh_seconds": int(os.environ.get("SNAPSHOT_REFRESH_SECONDS", "3600")),
|
||||
"snapshot_live_on_gui": env_bool("SNAPSHOT_LIVE_ON_GUI", True),
|
||||
"frigate_public_url": os.environ.get("FRIGATE_PUBLIC_URL"),
|
||||
"frigate_camera_path_template": os.environ.get(
|
||||
"FRIGATE_CAMERA_PATH_TEMPLATE",
|
||||
"/#{camera_quoted}",
|
||||
),
|
||||
"frigate_refresh_seconds": int(os.environ.get("FRIGATE_REFRESH_SECONDS", "300")),
|
||||
"auto_off_siren_seconds": int(os.environ.get("AUTO_OFF_SIREN_SECONDS", "180")),
|
||||
"auto_off_red_blue_seconds": int(os.environ.get("AUTO_OFF_RED_BLUE_SECONDS", "300")),
|
||||
@@ -333,6 +338,7 @@ class Action:
|
||||
self.state = None
|
||||
self.auto_off_seconds = int(cfg.get("auto_off_seconds") or 0)
|
||||
self.auto_off_at = None
|
||||
self.snapshot_version = 0
|
||||
|
||||
def display_name(self, lang):
|
||||
names = self.cfg.get("name_i18n") or {}
|
||||
@@ -714,6 +720,7 @@ class CameraControlBridge:
|
||||
continue
|
||||
action.state = old.state
|
||||
action.auto_off_at = old.auto_off_at
|
||||
action.snapshot_version = old.snapshot_version
|
||||
|
||||
def initialize_action_states(self):
|
||||
for action in self.actions.values():
|
||||
@@ -1181,12 +1188,17 @@ class CameraControlBridge:
|
||||
"configuration_url": item["frigate_url"],
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def snapshot_config(item):
|
||||
return {
|
||||
def snapshot_config(self, item):
|
||||
config = {
|
||||
"frigate_url": item["frigate_url"],
|
||||
"camera": item["camera"],
|
||||
}
|
||||
defaults = self.config.get("defaults", {})
|
||||
if defaults.get("frigate_public_url"):
|
||||
config["public_url"] = defaults["frigate_public_url"]
|
||||
if defaults.get("frigate_camera_path_template"):
|
||||
config["camera_path_template"] = defaults["frigate_camera_path_template"]
|
||||
return config
|
||||
|
||||
@staticmethod
|
||||
def xml_text(xml, tag):
|
||||
@@ -1243,6 +1255,23 @@ class CameraControlBridge:
|
||||
LOG.info("snapshot unavailable for %s: %s", action.id, exc)
|
||||
return ok
|
||||
|
||||
@staticmethod
|
||||
def should_refresh_snapshot_after_command(action, command):
|
||||
if command.lower() not in ("on", "off", "safe_off"):
|
||||
return False
|
||||
return action.cfg.get("name_key") in ("action.manual_white", "action.red_blue")
|
||||
|
||||
def invalidate_action_snapshot(self, action):
|
||||
url = self.snapshot_url(action)
|
||||
if not url:
|
||||
return
|
||||
with self.action_lock:
|
||||
self.snapshot_cache.pop(url, None)
|
||||
version = int(time.time() * 1000)
|
||||
for item in self.actions.values():
|
||||
if self.snapshot_url(item) == url:
|
||||
item.snapshot_version = version
|
||||
|
||||
def snapshot_url(self, action):
|
||||
snapshot = action.cfg.get("snapshot")
|
||||
if not snapshot:
|
||||
@@ -1390,6 +1419,8 @@ class CameraControlBridge:
|
||||
self.schedule_auto_off(action)
|
||||
elif command in ("off", "safe_off"):
|
||||
self.cancel_auto_off(action.id)
|
||||
if self.should_refresh_snapshot_after_command(action, command):
|
||||
self.invalidate_action_snapshot(action)
|
||||
if publish:
|
||||
try:
|
||||
self.publish_result(action, command, result)
|
||||
|
||||
Reference in New Issue
Block a user