add switch to frontend

This commit is contained in:
Josh Hawkins 2025-06-30 16:39:01 -05:00
parent d435d6628b
commit 8102f070ee
4 changed files with 57 additions and 1 deletions

View File

@ -150,6 +150,10 @@
"title": "Streams",
"desc": "Disabling a camera completely stops Frigate's processing of this camera's streams. Detection, recording, and debugging will be unavailable.<br /> <em>Note: This does not disable go2rtc restreams.</em>"
},
"genai": {
"title": "Generative AI",
"desc": "Temporarily enable/disable Generative AI for this camera. When disabled, AI generated descriptions will not be requested for tracked objects on this camera."
},
"review": {
"title": "Review",
"desc": "Enable/disable alerts and detections for this camera. When disabled, no new review items will be generated.",

View File

@ -68,6 +68,7 @@ function useValue(): useValueReturn {
autotracking,
alerts,
detections,
genai,
} = state["config"];
cameraStates[`${name}/recordings/state`] = record ? "ON" : "OFF";
cameraStates[`${name}/enabled/state`] = enabled ? "ON" : "OFF";
@ -89,6 +90,7 @@ function useValue(): useValueReturn {
cameraStates[`${name}/review_detections/state`] = detections
? "ON"
: "OFF";
cameraStates[`${name}/genai/state`] = genai ? "ON" : "OFF";
});
setWsState((prevState) => ({
@ -276,6 +278,17 @@ export function useDetectionsState(camera: string): {
return { payload: payload as ToggleableSetting, send };
}
export function useGenAIState(camera: string): {
payload: ToggleableSetting;
send: (payload: ToggleableSetting, retain?: boolean) => void;
} {
const {
value: { payload },
send,
} = useWs(`${camera}/genai/state`, `${camera}/genai/set`);
return { payload: payload as ToggleableSetting, send };
}
export function usePtzCommand(camera: string): {
payload: string;
send: (payload: string, retain?: boolean) => void;

View File

@ -64,6 +64,7 @@ export interface FrigateCameraState {
autotracking: boolean;
alerts: boolean;
detections: boolean;
genai: boolean;
};
motion: boolean;
objects: ObjectType[];

View File

@ -29,7 +29,12 @@ import { cn } from "@/lib/utils";
import { Trans, useTranslation } from "react-i18next";
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
import { useAlertsState, useDetectionsState, useEnabledState } from "@/api/ws";
import {
useAlertsState,
useDetectionsState,
useEnabledState,
useGenAIState,
} from "@/api/ws";
import CameraEditForm from "@/components/settings/CameraEditForm";
import { LuPlus } from "react-icons/lu";
import {
@ -142,6 +147,9 @@ export default function CameraSettingsView({
const { payload: detectionsState, send: sendDetections } =
useDetectionsState(selectedCamera);
const { payload: genAIState, send: sendGenAI } =
useGenAIState(selectedCamera);
const handleCheckedChange = useCallback(
(isChecked: boolean) => {
if (!isChecked) {
@ -402,6 +410,36 @@ export default function CameraSettingsView({
</div>
</div>
</div>
{config?.genai?.enabled && (
<>
<Separator className="my-2 flex bg-secondary" />
<Heading as="h4" className="my-2">
<Trans ns="views/settings">camera.genai.title</Trans>
</Heading>
<div className="mb-5 mt-2 flex max-w-5xl flex-col gap-2 space-y-3 text-sm text-primary-variant">
<div className="flex flex-row items-center">
<Switch
id="alerts-enabled"
className="mr-3"
checked={genAIState == "ON"}
onCheckedChange={(isChecked) => {
sendGenAI(isChecked ? "ON" : "OFF");
}}
/>
<div className="space-y-0.5">
<Label htmlFor="genai-enabled">
<Trans>button.enabled</Trans>
</Label>
</div>
</div>
<div className="mt-3 text-sm text-muted-foreground">
<Trans ns="views/settings">camera.genai.desc</Trans>
</div>
</div>
</>
)}
<Separator className="my-2 flex bg-secondary" />