use enabled_in_config for switch in HA integration (#8630)

This commit is contained in:
Josh Hawkins 2023-11-15 19:25:48 -06:00 committed by GitHub
parent cadb1a6a5b
commit 7b520e8a9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -185,6 +185,13 @@ class Dispatcher:
ptz_autotracker_settings = self.config.cameras[camera_name].onvif.autotracking
if payload == "ON":
if not self.config.cameras[
camera_name
].onvif.autotracking.enabled_in_config:
logger.error(
"Autotracking must be enabled in the config to be turned on via MQTT."
)
return
if not self.ptz_metrics[camera_name]["ptz_autotracker_enabled"].value:
logger.info(f"Turning on ptz autotracker for {camera_name}")
self.ptz_metrics[camera_name]["ptz_autotracker_enabled"].value = True

View File

@ -71,7 +71,7 @@ class MqttClient(Communicator): # type: ignore[misc]
)
self.publish(
f"{camera_name}/ptz_autotracker/state",
"ON" if camera.onvif.autotracking.enabled else "OFF",
"ON" if camera.onvif.autotracking.enabled_in_config else "OFF",
retain=True,
)
self.publish(

View File

@ -184,6 +184,9 @@ class PtzAutotrackConfig(FrigateBaseModel):
default=[],
title="Internal value used for PTZ movements based on the speed of your camera's motor.",
)
enabled_in_config: Optional[bool] = Field(
title="Keep track of original state of autotracking."
)
@validator("movement_weights", pre=True)
def validate_weights(cls, v):
@ -1191,6 +1194,9 @@ class FrigateConfig(FrigateBaseModel):
# set config pre-value
camera_config.record.enabled_in_config = camera_config.record.enabled
camera_config.audio.enabled_in_config = camera_config.audio.enabled
camera_config.onvif.autotracking.enabled_in_config = (
camera_config.onvif.autotracking.enabled
)
# Add default filters
object_keys = camera_config.objects.track

View File

@ -208,7 +208,10 @@ class PtzAutoTracker:
continue
self.autotracker_init[camera] = False
if camera_config.onvif.autotracking.enabled:
if (
camera_config.onvif.autotracking.enabled
and camera_config.onvif.autotracking.enabled_in_config
):
self._autotracker_setup(camera_config, camera)
def _autotracker_setup(self, camera_config, camera):