Skip to content

Commit

Permalink
Add 'reload cameras' option to WebUI #1255
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Jun 13, 2024
1 parent 17ca218 commit 42a9ee2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def restart_bridge(restart_cmd: str):
wb.streams.monitor_streams(wb.rtsp.health_check)
elif restart_cmd == "rtsp_server":
wb.rtsp.restart()
elif restart_cmd == "cam_data":
wb.refresh_cams()
restart_cmd = "cameras"
elif restart_cmd == "all":
wb.restart(fresh_data=True)
restart_cmd = "cameras,rtsp_server"
Expand Down
6 changes: 6 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
</span>
<span>mtx-server</span>
</a>
<a data-restart="cam_data" class="dropdown-item">
<span class="icon is-small">
<i class="fas fa-rotate"></i>
</span>
<span>reload camera data</span>
</a>
<a data-restart="all" class="dropdown-item">
<span class="icon is-small">
<i class="fas fa-solid fa-cloud-arrow-down"></i>
Expand Down
6 changes: 6 additions & 0 deletions app/wyze_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def restart(self, fresh_data: bool = False) -> None:
self.streams.stop_all()
self._initialize(fresh_data)

def refresh_cams(self) -> None:
self.rtsp.stop()
self.streams.stop_all()
self.api.get_cameras(fresh_data=True)
self._initialize(False)

def setup_streams(self):
"""Gather and setup streams for each camera."""
WyzeStream.user = self.api.get_user()
Expand Down
1 change: 0 additions & 1 deletion app/wyzebridge/mtx_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(self, streams):
self.buf: str = ""
with contextlib.suppress(FileExistsError):
os.mkfifo(self.FIFO)
print("RtspEvent initialized")

def read(self, timeout: int = 1):
if not self.pipe or self.pipe.closed:
Expand Down
23 changes: 15 additions & 8 deletions app/wyzebridge/wyze_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,21 @@ def set_device_info(self, cam: WyzeCamera, params: dict):
logger.error(f"[CONTROL] ERROR: {error}")
return {"status": "error", "response": f"{error}"}

def clear_cache(self):
logger.info("♻️ Clearing local cache...")
self.auth = None
self.user = None
self.cameras = None
for name in listdir(TOKEN_PATH):
if name.endswith("pickle"):
remove(TOKEN_PATH + name)
def clear_cache(self, name: Optional[str] = None):
data = {"auth", "user", "cameras"}

if name in data:
logger.info(f"♻️ Clearing {name} from local cache...")
setattr(self, name, None)
pickled_data = Path(TOKEN_PATH, f"{name}.pickle")
if pickled_data.exists():
pickled_data.unlink()
else:
logger.info("♻️ Clearing local cache...")
for data_attr in data:
setattr(self, data_attr, None)
for token_file in Path(TOKEN_PATH).glob("*.pickle"):
token_file.unlink()

def get_mfa(self):
return self.mfa_req
Expand Down

0 comments on commit 42a9ee2

Please sign in to comment.