mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-26 19:06:11 +01:00
fix mqtt switch handling
This commit is contained in:
parent
7f663328dc
commit
1e84f08018
@ -15,7 +15,6 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
logger.debug(f"on_clips_toggle: {message.topic} {payload}")
|
logger.debug(f"on_clips_toggle: {message.topic} {payload}")
|
||||||
|
|
||||||
camera_name = message.topic.split('/')[-3]
|
camera_name = message.topic.split('/')[-3]
|
||||||
command = message.topic.split('/')[-1]
|
|
||||||
|
|
||||||
clips_settings = config.cameras[camera_name].clips
|
clips_settings = config.cameras[camera_name].clips
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
||||||
|
|
||||||
if command == "set":
|
|
||||||
state_topic = f"{message.topic[:-4]}/state"
|
state_topic = f"{message.topic[:-4]}/state"
|
||||||
client.publish(state_topic, payload, retain=True)
|
client.publish(state_topic, payload, retain=True)
|
||||||
|
|
||||||
@ -39,7 +37,6 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
logger.debug(f"on_snapshots_toggle: {message.topic} {payload}")
|
logger.debug(f"on_snapshots_toggle: {message.topic} {payload}")
|
||||||
|
|
||||||
camera_name = message.topic.split('/')[-3]
|
camera_name = message.topic.split('/')[-3]
|
||||||
command = message.topic.split('/')[-1]
|
|
||||||
|
|
||||||
snapshots_settings = config.cameras[camera_name].snapshots
|
snapshots_settings = config.cameras[camera_name].snapshots
|
||||||
|
|
||||||
@ -54,7 +51,6 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
||||||
|
|
||||||
if command == "set":
|
|
||||||
state_topic = f"{message.topic[:-4]}/state"
|
state_topic = f"{message.topic[:-4]}/state"
|
||||||
client.publish(state_topic, payload, retain=True)
|
client.publish(state_topic, payload, retain=True)
|
||||||
|
|
||||||
@ -63,7 +59,6 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
logger.debug(f"on_detect_toggle: {message.topic} {payload}")
|
logger.debug(f"on_detect_toggle: {message.topic} {payload}")
|
||||||
|
|
||||||
camera_name = message.topic.split('/')[-3]
|
camera_name = message.topic.split('/')[-3]
|
||||||
command = message.topic.split('/')[-1]
|
|
||||||
|
|
||||||
detect_settings = config.cameras[camera_name].detect
|
detect_settings = config.cameras[camera_name].detect
|
||||||
|
|
||||||
@ -80,7 +75,6 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
logger.warning(f"Received unsupported value at {message.topic}: {payload}")
|
||||||
|
|
||||||
if command == "set":
|
|
||||||
state_topic = f"{message.topic[:-4]}/state"
|
state_topic = f"{message.topic[:-4]}/state"
|
||||||
client.publish(state_topic, payload, retain=True)
|
client.publish(state_topic, payload, retain=True)
|
||||||
|
|
||||||
@ -105,9 +99,9 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
|
|
||||||
# register callbacks
|
# register callbacks
|
||||||
for name in config.cameras.keys():
|
for name in config.cameras.keys():
|
||||||
client.message_callback_add(f"{mqtt_config.topic_prefix}/{name}/clips/#", on_clips_command)
|
client.message_callback_add(f"{mqtt_config.topic_prefix}/{name}/clips/set", on_clips_command)
|
||||||
client.message_callback_add(f"{mqtt_config.topic_prefix}/{name}/snapshots/#", on_snapshots_command)
|
client.message_callback_add(f"{mqtt_config.topic_prefix}/{name}/snapshots/set", on_snapshots_command)
|
||||||
client.message_callback_add(f"{mqtt_config.topic_prefix}/{name}/detect/#", on_detect_command)
|
client.message_callback_add(f"{mqtt_config.topic_prefix}/{name}/detect/set", on_detect_command)
|
||||||
|
|
||||||
if not mqtt_config.user is None:
|
if not mqtt_config.user is None:
|
||||||
client.username_pw_set(mqtt_config.user, password=mqtt_config.password)
|
client.username_pw_set(mqtt_config.user, password=mqtt_config.password)
|
||||||
@ -124,8 +118,8 @@ def create_mqtt_client(config: FrigateConfig, camera_metrics):
|
|||||||
client.publish(f"{mqtt_config.topic_prefix}/{name}/snapshots/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
|
client.publish(f"{mqtt_config.topic_prefix}/{name}/snapshots/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
|
||||||
client.publish(f"{mqtt_config.topic_prefix}/{name}/detect/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
|
client.publish(f"{mqtt_config.topic_prefix}/{name}/detect/state", 'ON' if config.cameras[name].clips.enabled else 'OFF', retain=True)
|
||||||
|
|
||||||
client.subscribe(f"{mqtt_config.topic_prefix}/+/clips/#")
|
client.subscribe(f"{mqtt_config.topic_prefix}/+/clips/set")
|
||||||
client.subscribe(f"{mqtt_config.topic_prefix}/+/snapshots/#")
|
client.subscribe(f"{mqtt_config.topic_prefix}/+/snapshots/set")
|
||||||
client.subscribe(f"{mqtt_config.topic_prefix}/+/detect/#")
|
client.subscribe(f"{mqtt_config.topic_prefix}/+/detect/set")
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
Loading…
Reference in New Issue
Block a user