mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-10 07:25:27 +03:00
Compare commits
No commits in common. "78bc11d7e0a01eeef1363778c88ccbaeae7052dc" and "f7271e0a5b9f6d409904665c303aedcd38333b32" have entirely different histories.
78bc11d7e0
...
f7271e0a5b
@ -170,19 +170,6 @@ def config(request: Request):
|
||||
)
|
||||
)
|
||||
|
||||
# When a profile is active, the top-level camera sections contain
|
||||
# profile-merged (effective) values. Include the original base
|
||||
# configs so the frontend settings can display them separately.
|
||||
if (
|
||||
config_obj.active_profile is not None
|
||||
and request.app.profile_manager is not None
|
||||
):
|
||||
base_sections = request.app.profile_manager.get_base_configs_for_api(
|
||||
camera_name
|
||||
)
|
||||
if base_sections:
|
||||
camera_dict["base_config"] = base_sections
|
||||
|
||||
# remove go2rtc stream passwords
|
||||
go2rtc: dict[str, Any] = config_obj.go2rtc.model_dump(
|
||||
mode="json", warnings="none", exclude_none=True
|
||||
|
||||
@ -352,9 +352,7 @@ class FrigateApp:
|
||||
)
|
||||
|
||||
def init_profile_manager(self) -> None:
|
||||
self.profile_manager = ProfileManager(
|
||||
self.config, self.inter_config_updater, self.dispatcher
|
||||
)
|
||||
self.profile_manager = ProfileManager(self.config, self.inter_config_updater)
|
||||
self.dispatcher.profile_manager = self.profile_manager
|
||||
|
||||
persisted = ProfileManager.load_persisted_profile()
|
||||
|
||||
@ -12,6 +12,7 @@ from pydantic import (
|
||||
Field,
|
||||
TypeAdapter,
|
||||
ValidationInfo,
|
||||
field_serializer,
|
||||
field_validator,
|
||||
model_validator,
|
||||
)
|
||||
@ -97,7 +98,8 @@ stream_info_retriever = StreamInfoRetriever()
|
||||
class RuntimeMotionConfig(MotionConfig):
|
||||
"""Runtime version of MotionConfig with rasterized masks."""
|
||||
|
||||
rasterized_mask: np.ndarray = Field(default=None, exclude=True)
|
||||
# The rasterized numpy mask (combination of all enabled masks)
|
||||
rasterized_mask: np.ndarray = None
|
||||
|
||||
def __init__(self, **config):
|
||||
frame_shape = config.get("frame_shape", (1, 1))
|
||||
@ -143,13 +145,24 @@ class RuntimeMotionConfig(MotionConfig):
|
||||
empty_mask[:] = 255
|
||||
self.rasterized_mask = empty_mask
|
||||
|
||||
def dict(self, **kwargs):
|
||||
ret = super().model_dump(**kwargs)
|
||||
if "rasterized_mask" in ret:
|
||||
ret.pop("rasterized_mask")
|
||||
return ret
|
||||
|
||||
@field_serializer("rasterized_mask", when_used="json")
|
||||
def serialize_rasterized_mask(self, value: Any, info):
|
||||
return None
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True, extra="ignore")
|
||||
|
||||
|
||||
class RuntimeFilterConfig(FilterConfig):
|
||||
"""Runtime version of FilterConfig with rasterized masks."""
|
||||
|
||||
rasterized_mask: Optional[np.ndarray] = Field(default=None, exclude=True)
|
||||
# The rasterized numpy mask (combination of all enabled masks)
|
||||
rasterized_mask: Optional[np.ndarray] = None
|
||||
|
||||
def __init__(self, **config):
|
||||
frame_shape = config.get("frame_shape", (1, 1))
|
||||
@ -213,6 +226,16 @@ class RuntimeFilterConfig(FilterConfig):
|
||||
else:
|
||||
self.rasterized_mask = None
|
||||
|
||||
def dict(self, **kwargs):
|
||||
ret = super().model_dump(**kwargs)
|
||||
if "rasterized_mask" in ret:
|
||||
ret.pop("rasterized_mask")
|
||||
return ret
|
||||
|
||||
@field_serializer("rasterized_mask", when_used="json")
|
||||
def serialize_rasterized_mask(self, value: Any, info):
|
||||
return None
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True, extra="ignore")
|
||||
|
||||
|
||||
|
||||
@ -29,7 +29,6 @@ PROFILE_SECTION_UPDATES: dict[str, CameraConfigUpdateEnum] = {
|
||||
"record": CameraConfigUpdateEnum.record,
|
||||
"review": CameraConfigUpdateEnum.review,
|
||||
"snapshots": CameraConfigUpdateEnum.snapshots,
|
||||
"zones": CameraConfigUpdateEnum.zones,
|
||||
}
|
||||
|
||||
PERSISTENCE_FILE = Path(CONFIG_DIR) / ".active_profile"
|
||||
@ -42,15 +41,12 @@ class ProfileManager:
|
||||
self,
|
||||
config,
|
||||
config_updater: CameraConfigUpdatePublisher,
|
||||
dispatcher=None,
|
||||
):
|
||||
from frigate.config.config import FrigateConfig
|
||||
|
||||
self.config: FrigateConfig = config
|
||||
self.config_updater = config_updater
|
||||
self.dispatcher = dispatcher
|
||||
self._base_configs: dict[str, dict[str, dict]] = {}
|
||||
self._base_api_configs: dict[str, dict[str, dict]] = {}
|
||||
self._base_enabled: dict[str, bool] = {}
|
||||
self._base_zones: dict[str, dict[str, ZoneConfig]] = {}
|
||||
self._snapshot_base_configs()
|
||||
@ -59,39 +55,12 @@ class ProfileManager:
|
||||
"""Snapshot each camera's current section configs, enabled, and zones."""
|
||||
for cam_name, cam_config in self.config.cameras.items():
|
||||
self._base_configs[cam_name] = {}
|
||||
self._base_api_configs[cam_name] = {}
|
||||
self._base_enabled[cam_name] = cam_config.enabled
|
||||
self._base_zones[cam_name] = copy.deepcopy(cam_config.zones)
|
||||
for section in PROFILE_SECTION_UPDATES:
|
||||
section_value = getattr(cam_config, section, None)
|
||||
if section_value is None:
|
||||
continue
|
||||
|
||||
if section == "zones":
|
||||
# zones is a dict of ZoneConfig models
|
||||
self._base_configs[cam_name][section] = {
|
||||
name: zone.model_dump() for name, zone in section_value.items()
|
||||
}
|
||||
self._base_api_configs[cam_name][section] = {
|
||||
name: {
|
||||
**zone.model_dump(
|
||||
mode="json",
|
||||
warnings="none",
|
||||
exclude_none=True,
|
||||
),
|
||||
"color": zone.color,
|
||||
}
|
||||
for name, zone in section_value.items()
|
||||
}
|
||||
else:
|
||||
self._base_configs[cam_name][section] = section_value.model_dump()
|
||||
self._base_api_configs[cam_name][section] = (
|
||||
section_value.model_dump(
|
||||
mode="json",
|
||||
warnings="none",
|
||||
exclude_none=True,
|
||||
)
|
||||
)
|
||||
section_config = getattr(cam_config, section, None)
|
||||
if section_config is not None:
|
||||
self._base_configs[cam_name][section] = section_config.model_dump()
|
||||
|
||||
def update_config(self, new_config) -> None:
|
||||
"""Update config reference after config/set replaces the in-memory config.
|
||||
@ -105,7 +74,6 @@ class ProfileManager:
|
||||
|
||||
# Re-snapshot base configs from the new config (which has base values)
|
||||
self._base_configs.clear()
|
||||
self._base_api_configs.clear()
|
||||
self._base_enabled.clear()
|
||||
self._base_zones.clear()
|
||||
self._snapshot_base_configs()
|
||||
@ -176,11 +144,9 @@ class ProfileManager:
|
||||
cam_config.zones = copy.deepcopy(base_zones)
|
||||
changed.setdefault(cam_name, set()).add("zones")
|
||||
|
||||
# Restore section configs (zones handled above)
|
||||
# Restore section configs
|
||||
base = self._base_configs.get(cam_name, {})
|
||||
for section in PROFILE_SECTION_UPDATES:
|
||||
if section == "zones":
|
||||
continue
|
||||
base_data = base.get(section)
|
||||
if base_data is None:
|
||||
continue
|
||||
@ -214,23 +180,12 @@ class ProfileManager:
|
||||
base_zones = self._base_zones.get(cam_name, {})
|
||||
merged_zones = copy.deepcopy(base_zones)
|
||||
merged_zones.update(profile.zones)
|
||||
# Profile zone objects are parsed without colors or contours
|
||||
# (those are set during CameraConfig init / post-validation).
|
||||
# Inherit the base zone's color when available, and ensure
|
||||
# every zone has a valid contour for rendering.
|
||||
for name, zone in merged_zones.items():
|
||||
if zone.contour.size == 0:
|
||||
zone.generate_contour(cam_config.frame_shape)
|
||||
if zone.color == (0, 0, 0) and name in base_zones:
|
||||
zone._color = base_zones[name].color
|
||||
cam_config.zones = merged_zones
|
||||
changed.setdefault(cam_name, set()).add("zones")
|
||||
|
||||
base = self._base_configs.get(cam_name, {})
|
||||
|
||||
for section in PROFILE_SECTION_UPDATES:
|
||||
if section == "zones":
|
||||
continue
|
||||
profile_section = getattr(profile, section, None)
|
||||
if profile_section is None:
|
||||
continue
|
||||
@ -265,12 +220,6 @@ class ProfileManager:
|
||||
),
|
||||
cam_config.enabled,
|
||||
)
|
||||
if self.dispatcher is not None:
|
||||
self.dispatcher.publish(
|
||||
f"{cam_name}/enabled/state",
|
||||
"ON" if cam_config.enabled else "OFF",
|
||||
retain=True,
|
||||
)
|
||||
continue
|
||||
|
||||
if section == "zones":
|
||||
@ -311,14 +260,6 @@ class ProfileManager:
|
||||
logger.exception("Failed to load persisted profile")
|
||||
return None
|
||||
|
||||
def get_base_configs_for_api(self, camera_name: str) -> dict[str, dict]:
|
||||
"""Return base (pre-profile) section configs for a camera.
|
||||
|
||||
These are JSON-serializable dicts suitable for direct inclusion in
|
||||
the /api/config response, with None values already excluded.
|
||||
"""
|
||||
return self._base_api_configs.get(camera_name, {})
|
||||
|
||||
def get_available_profiles(self) -> list[dict[str, str]]:
|
||||
"""Get list of all profile definitions from the top-level config."""
|
||||
return [
|
||||
|
||||
@ -557,34 +557,6 @@ class TestProfileManager(unittest.TestCase):
|
||||
assert "armed" in names
|
||||
assert "disarmed" in names
|
||||
|
||||
@patch.object(ProfileManager, "_persist_active_profile")
|
||||
def test_base_configs_for_api_unchanged_after_activation(self, mock_persist):
|
||||
"""API base configs reflect pre-profile values after activation."""
|
||||
base_track = self.config.cameras["front"].objects.track[:]
|
||||
assert base_track == ["person"]
|
||||
|
||||
self.manager.activate_profile("armed")
|
||||
|
||||
# In-memory config has the profile-merged values
|
||||
assert self.config.cameras["front"].objects.track == [
|
||||
"person",
|
||||
"car",
|
||||
"package",
|
||||
]
|
||||
|
||||
# But the API base configs still return the original base values
|
||||
api_base = self.manager.get_base_configs_for_api("front")
|
||||
assert "objects" in api_base
|
||||
assert api_base["objects"]["track"] == ["person"]
|
||||
|
||||
def test_base_configs_for_api_are_json_serializable(self):
|
||||
"""API base configs are JSON-serializable (mode='json')."""
|
||||
import json
|
||||
|
||||
api_base = self.manager.get_base_configs_for_api("front")
|
||||
# Should not raise
|
||||
json.dumps(api_base)
|
||||
|
||||
|
||||
class TestProfilePersistence(unittest.TestCase):
|
||||
"""Test profile persistence to disk."""
|
||||
|
||||
@ -717,7 +717,7 @@ def apply_section_update(camera_config, section: str, update: dict) -> Optional[
|
||||
|
||||
if section == "motion":
|
||||
merged = deep_merge(
|
||||
current.model_dump(exclude_unset=True),
|
||||
current.model_dump(exclude_unset=True, exclude={"rasterized_mask"}),
|
||||
update,
|
||||
override=True,
|
||||
)
|
||||
@ -727,7 +727,9 @@ def apply_section_update(camera_config, section: str, update: dict) -> Optional[
|
||||
|
||||
elif section == "objects":
|
||||
merged = deep_merge(
|
||||
current.model_dump(),
|
||||
current.model_dump(
|
||||
exclude={"filters": {"__all__": {"rasterized_mask"}}}
|
||||
),
|
||||
update,
|
||||
override=True,
|
||||
)
|
||||
|
||||
@ -65,7 +65,6 @@ import {
|
||||
globalCameraDefaultSections,
|
||||
buildOverrides,
|
||||
buildConfigDataForPath,
|
||||
getBaseCameraSectionValue,
|
||||
sanitizeSectionData as sharedSanitizeSectionData,
|
||||
requiresRestartForOverrides as sharedRequiresRestartForOverrides,
|
||||
} from "@/utils/configUtil";
|
||||
@ -304,20 +303,12 @@ export function ConfigSection({
|
||||
profileOverridesSection ? "profile" : isOverridden ? "global" : undefined;
|
||||
|
||||
// Get current form data
|
||||
// When a profile is active the top-level camera sections contain the
|
||||
// effective (profile-merged) values. For the base-config view we read
|
||||
// from `base_config` (original values before the profile was applied).
|
||||
// When editing a profile, we merge the base value with profile overrides.
|
||||
// When editing a profile, show base camera config deep-merged with profile overrides
|
||||
const rawSectionValue = useMemo(() => {
|
||||
if (!config) return undefined;
|
||||
|
||||
if (effectiveLevel === "camera" && cameraName) {
|
||||
// Base value: prefer base_config (pre-profile) over effective value
|
||||
const baseValue = getBaseCameraSectionValue(
|
||||
config,
|
||||
cameraName,
|
||||
sectionPath,
|
||||
);
|
||||
const baseValue = get(config.cameras?.[cameraName], sectionPath);
|
||||
if (profileName) {
|
||||
const profileOverrides = get(
|
||||
config.cameras?.[cameraName],
|
||||
|
||||
@ -7,35 +7,41 @@ import type { FormContext } from "./SwitchesWidget";
|
||||
import { getTranslatedLabel } from "@/utils/i18n";
|
||||
import { JsonObject } from "@/types/configForm";
|
||||
|
||||
function extractListenLabels(value: unknown): string[] {
|
||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||
const listenValue = (value as JsonObject).listen;
|
||||
function getEnabledAudioLabels(context: FormContext): string[] {
|
||||
let cameraLabels: string[] = [];
|
||||
let globalLabels: string[] = [];
|
||||
|
||||
if (context) {
|
||||
// context.cameraValue and context.globalValue should be the entire audio section
|
||||
if (
|
||||
context.cameraValue &&
|
||||
typeof context.cameraValue === "object" &&
|
||||
!Array.isArray(context.cameraValue)
|
||||
) {
|
||||
const listenValue = (context.cameraValue as JsonObject).listen;
|
||||
if (Array.isArray(listenValue)) {
|
||||
return listenValue.filter(
|
||||
cameraLabels = listenValue.filter(
|
||||
(item): item is string => typeof item === "string",
|
||||
);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function getEnabledAudioLabels(context: FormContext): string[] {
|
||||
let cameraLabels: string[] = [];
|
||||
let globalLabels: string[] = [];
|
||||
let formDataLabels: string[] = [];
|
||||
|
||||
if (context) {
|
||||
// context.cameraValue and context.globalValue should be the entire audio section
|
||||
cameraLabels = extractListenLabels(context.cameraValue);
|
||||
globalLabels = extractListenLabels(context.globalValue);
|
||||
|
||||
// Include labels from the current form data so that labels added via
|
||||
// profile overrides (or user edits) are always visible as switches.
|
||||
formDataLabels = extractListenLabels(context.formData);
|
||||
if (
|
||||
context.globalValue &&
|
||||
typeof context.globalValue === "object" &&
|
||||
!Array.isArray(context.globalValue)
|
||||
) {
|
||||
const globalListenValue = (context.globalValue as JsonObject).listen;
|
||||
if (Array.isArray(globalListenValue)) {
|
||||
globalLabels = globalListenValue.filter(
|
||||
(item): item is string => typeof item === "string",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sourceLabels = cameraLabels.length > 0 ? cameraLabels : globalLabels;
|
||||
return [...new Set([...sourceLabels, ...formDataLabels])].sort();
|
||||
return [...sourceLabels].sort();
|
||||
}
|
||||
|
||||
function getAudioLabelDisplayName(label: string): string {
|
||||
|
||||
@ -40,42 +40,43 @@ function getLabelmapLabels(context: FormContext): string[] {
|
||||
return [...labels];
|
||||
}
|
||||
|
||||
// Extract track labels from an objects section value.
|
||||
function extractTrackLabels(value: unknown): string[] {
|
||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||
const trackValue = (value as JsonObject).track;
|
||||
if (Array.isArray(trackValue)) {
|
||||
return trackValue.filter(
|
||||
(item): item is string => typeof item === "string",
|
||||
);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
// Build the list of labels for switches (labelmap + configured track list).
|
||||
function getObjectLabels(context: FormContext): string[] {
|
||||
const labelmapLabels = getLabelmapLabels(context);
|
||||
let cameraLabels: string[] = [];
|
||||
let globalLabels: string[] = [];
|
||||
let formDataLabels: string[] = [];
|
||||
|
||||
if (context) {
|
||||
// context.cameraValue and context.globalValue should be the entire objects section
|
||||
cameraLabels = extractTrackLabels(context.cameraValue);
|
||||
globalLabels = extractTrackLabels(context.globalValue);
|
||||
if (
|
||||
context.cameraValue &&
|
||||
typeof context.cameraValue === "object" &&
|
||||
!Array.isArray(context.cameraValue)
|
||||
) {
|
||||
const trackValue = (context.cameraValue as JsonObject).track;
|
||||
if (Array.isArray(trackValue)) {
|
||||
cameraLabels = trackValue.filter(
|
||||
(item): item is string => typeof item === "string",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Include labels from the current form data so that labels added via
|
||||
// profile overrides (or user edits) are always visible as switches.
|
||||
formDataLabels = extractTrackLabels(context.formData);
|
||||
if (
|
||||
context.globalValue &&
|
||||
typeof context.globalValue === "object" &&
|
||||
!Array.isArray(context.globalValue)
|
||||
) {
|
||||
const globalTrackValue = (context.globalValue as JsonObject).track;
|
||||
if (Array.isArray(globalTrackValue)) {
|
||||
globalLabels = globalTrackValue.filter(
|
||||
(item): item is string => typeof item === "string",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sourceLabels = cameraLabels.length > 0 ? cameraLabels : globalLabels;
|
||||
const combinedLabels = new Set<string>([
|
||||
...labelmapLabels,
|
||||
...sourceLabels,
|
||||
...formDataLabels,
|
||||
]);
|
||||
const combinedLabels = new Set<string>([...labelmapLabels, ...sourceLabels]);
|
||||
return [...combinedLabels].sort();
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ type FormContext = Pick<
|
||||
| "globalValue"
|
||||
| "fullCameraConfig"
|
||||
| "fullConfig"
|
||||
| "formData"
|
||||
| "t"
|
||||
| "level"
|
||||
> & {
|
||||
|
||||
@ -6,7 +6,6 @@ import set from "lodash/set";
|
||||
import { FrigateConfig } from "@/types/frigateConfig";
|
||||
import { JsonObject, JsonValue } from "@/types/configForm";
|
||||
import { isJsonObject } from "@/lib/utils";
|
||||
import { getBaseCameraSectionValue } from "@/utils/configUtil";
|
||||
|
||||
const INTERNAL_FIELD_SUFFIXES = ["enabled_in_config", "raw_mask"];
|
||||
|
||||
@ -145,13 +144,7 @@ export function useConfigOverride({
|
||||
};
|
||||
}
|
||||
|
||||
// Prefer the base (pre-profile) value so that override detection and
|
||||
// widget context reflect the camera's own config, not profile effects.
|
||||
const cameraValue = getBaseCameraSectionValue(
|
||||
config,
|
||||
cameraName,
|
||||
sectionPath,
|
||||
);
|
||||
const cameraValue = get(cameraConfig, sectionPath);
|
||||
|
||||
const normalizedGlobalValue = normalizeConfigValue(globalValue);
|
||||
const normalizedCameraValue = normalizeConfigValue(cameraValue);
|
||||
@ -263,9 +256,7 @@ export function useAllCameraOverrides(
|
||||
|
||||
for (const { key, compareFields } of sectionsToCheck) {
|
||||
const globalValue = normalizeConfigValue(get(config, key));
|
||||
const cameraValue = normalizeConfigValue(
|
||||
getBaseCameraSectionValue(config, cameraName, key),
|
||||
);
|
||||
const cameraValue = normalizeConfigValue(get(cameraConfig, key));
|
||||
|
||||
const comparisonGlobal = compareFields
|
||||
? pickFields(globalValue, compareFields)
|
||||
|
||||
@ -316,8 +316,6 @@ export interface CameraConfig {
|
||||
};
|
||||
};
|
||||
profiles?: Record<string, CameraProfileConfig>;
|
||||
/** Pre-profile base section configs, present only when a profile is active */
|
||||
base_config?: Record<string, Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export type CameraProfileConfig = {
|
||||
|
||||
@ -73,25 +73,6 @@ export const globalCameraDefaultSections = new Set([
|
||||
// Profile helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the base (pre-profile) value for a camera section.
|
||||
*
|
||||
* When a profile is active the API populates `base_config` with original
|
||||
* section values. This helper returns that value when available, falling
|
||||
* back to the top-level (effective) value otherwise.
|
||||
*/
|
||||
export function getBaseCameraSectionValue(
|
||||
config: FrigateConfig | undefined,
|
||||
cameraName: string | undefined,
|
||||
sectionPath: string,
|
||||
): unknown {
|
||||
if (!config || !cameraName) return undefined;
|
||||
const cam = config.cameras?.[cameraName];
|
||||
if (!cam) return undefined;
|
||||
const base = cam.base_config?.[sectionPath];
|
||||
return base !== undefined ? base : get(cam, sectionPath);
|
||||
}
|
||||
|
||||
/** Sections that can appear inside a camera profile definition. */
|
||||
export const PROFILE_ELIGIBLE_SECTIONS = new Set([
|
||||
"audio",
|
||||
@ -523,9 +504,8 @@ export function prepareSectionSavePayload(opts: {
|
||||
let rawSectionValue: unknown;
|
||||
if (level === "camera" && cameraName) {
|
||||
if (profileInfo.isProfile) {
|
||||
const baseValue = getBaseCameraSectionValue(
|
||||
config,
|
||||
cameraName,
|
||||
const baseValue = get(
|
||||
config.cameras?.[cameraName],
|
||||
profileInfo.actualSection,
|
||||
);
|
||||
const profileOverrides = get(config.cameras?.[cameraName], sectionPath);
|
||||
@ -543,12 +523,7 @@ export function prepareSectionSavePayload(opts: {
|
||||
rawSectionValue = baseValue;
|
||||
}
|
||||
} else {
|
||||
// Use base (pre-profile) value so the diff matches what the form shows
|
||||
rawSectionValue = getBaseCameraSectionValue(
|
||||
config,
|
||||
cameraName,
|
||||
sectionPath,
|
||||
);
|
||||
rawSectionValue = get(config.cameras?.[cameraName], sectionPath);
|
||||
}
|
||||
} else {
|
||||
rawSectionValue = get(config, sectionPath);
|
||||
|
||||
@ -435,10 +435,7 @@ function ProfileCameraEnableSection({
|
||||
},
|
||||
};
|
||||
|
||||
await axios.put("config/set", {
|
||||
requires_restart: 0,
|
||||
config_data: configData,
|
||||
});
|
||||
await axios.put("config/set", { config_data: configData });
|
||||
await onConfigChanged();
|
||||
|
||||
setLocalOverrides((prev) => ({
|
||||
|
||||
@ -249,26 +249,17 @@ export default function MasksAndZonesView({
|
||||
? cameraConfig.profiles?.[currentEditingProfile]
|
||||
: undefined;
|
||||
|
||||
// When a profile is active, the top-level sections contain
|
||||
// effective (profile-merged) values. Use base_config for the
|
||||
// original base values so the "Base Config" view is accurate and
|
||||
// the base layer for profile merging is correct.
|
||||
const baseMotion = (cameraConfig.base_config?.motion ??
|
||||
cameraConfig.motion) as typeof cameraConfig.motion;
|
||||
const baseObjects = (cameraConfig.base_config?.objects ??
|
||||
cameraConfig.objects) as typeof cameraConfig.objects;
|
||||
const baseZones = (cameraConfig.base_config?.zones ??
|
||||
cameraConfig.zones) as typeof cameraConfig.zones;
|
||||
|
||||
// Build base zone names set for source tracking
|
||||
const baseZoneNames = new Set(Object.keys(baseZones));
|
||||
const baseZoneNames = new Set(Object.keys(cameraConfig.zones));
|
||||
const profileZoneNames = new Set(Object.keys(profileData?.zones ?? {}));
|
||||
const baseMotionMaskNames = new Set(Object.keys(baseMotion.mask || {}));
|
||||
const baseMotionMaskNames = new Set(
|
||||
Object.keys(cameraConfig.motion.mask || {}),
|
||||
);
|
||||
const profileMotionMaskNames = new Set(
|
||||
Object.keys(profileData?.motion?.mask ?? {}),
|
||||
);
|
||||
const baseGlobalObjectMaskNames = new Set(
|
||||
Object.keys(baseObjects.mask || {}),
|
||||
Object.keys(cameraConfig.objects.mask || {}),
|
||||
);
|
||||
const profileGlobalObjectMaskNames = new Set(
|
||||
Object.keys(profileData?.objects?.mask ?? {}),
|
||||
@ -283,7 +274,7 @@ export default function MasksAndZonesView({
|
||||
}
|
||||
>();
|
||||
|
||||
for (const [name, zoneData] of Object.entries(baseZones)) {
|
||||
for (const [name, zoneData] of Object.entries(cameraConfig.zones)) {
|
||||
if (currentEditingProfile && profileZoneNames.has(name)) {
|
||||
// Profile overrides this base zone
|
||||
mergedZones.set(name, {
|
||||
@ -311,8 +302,7 @@ export default function MasksAndZonesView({
|
||||
const zones: Polygon[] = [];
|
||||
for (const [name, { data: zoneData, source }] of mergedZones) {
|
||||
const isBase = source === "base" && !!currentEditingProfile;
|
||||
const baseColor = zoneData.color ??
|
||||
baseZones[name]?.color ?? [128, 128, 0];
|
||||
const baseColor = zoneData.color ?? [128, 128, 0];
|
||||
zones.push({
|
||||
type: "zone" as PolygonType,
|
||||
typeIndex: zoneIndex,
|
||||
@ -349,7 +339,9 @@ export default function MasksAndZonesView({
|
||||
}
|
||||
>();
|
||||
|
||||
for (const [maskId, maskData] of Object.entries(baseMotion.mask || {})) {
|
||||
for (const [maskId, maskData] of Object.entries(
|
||||
cameraConfig.motion.mask || {},
|
||||
)) {
|
||||
if (currentEditingProfile && profileMotionMaskNames.has(maskId)) {
|
||||
mergedMotionMasks.set(maskId, {
|
||||
data: profileData!.motion!.mask![maskId],
|
||||
@ -414,7 +406,9 @@ export default function MasksAndZonesView({
|
||||
}
|
||||
>();
|
||||
|
||||
for (const [maskId, maskData] of Object.entries(baseObjects.mask || {})) {
|
||||
for (const [maskId, maskData] of Object.entries(
|
||||
cameraConfig.objects.mask || {},
|
||||
)) {
|
||||
if (currentEditingProfile && profileGlobalObjectMaskNames.has(maskId)) {
|
||||
mergedGlobalObjectMasks.set(maskId, {
|
||||
data: profileData!.objects!.mask![maskId],
|
||||
@ -478,7 +472,7 @@ export default function MasksAndZonesView({
|
||||
// Build per-object filter mask names for profile tracking
|
||||
const baseFilterMaskNames = new Set<string>();
|
||||
for (const [, filterConfig] of Object.entries(
|
||||
baseObjects.filters || {},
|
||||
cameraConfig.objects.filters,
|
||||
)) {
|
||||
for (const maskId of Object.keys(filterConfig.mask || {})) {
|
||||
if (!maskId.startsWith("global_")) {
|
||||
@ -501,7 +495,9 @@ export default function MasksAndZonesView({
|
||||
}
|
||||
|
||||
// Per-object filter masks (base)
|
||||
const objectMasks: Polygon[] = Object.entries(baseObjects.filters || {})
|
||||
const objectMasks: Polygon[] = Object.entries(
|
||||
cameraConfig.objects.filters,
|
||||
)
|
||||
.filter(
|
||||
([, filterConfig]) =>
|
||||
filterConfig.mask && Object.keys(filterConfig.mask).length > 0,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user