mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-07 03:11:15 +03:00
Add isort and ruff linter (#6575)
* Add isort and ruff linter Both linters are pretty common among modern python code bases. The isort tool provides stable sorting and grouping, as well as pruning of unused imports. Ruff is a modern linter, that is very fast due to being written in rust. It can detect many common issues in a python codebase. Removes the pylint dev requirement, since ruff replaces it. * treewide: fix issues detected by ruff * treewide: fix bare except clauses * .devcontainer: Set up isort * treewide: optimize imports * treewide: apply black * treewide: make regex patterns raw strings This is necessary for escape sequences to be properly recognized.
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
"""Handle communication between Frigate and other applications."""
|
||||
|
||||
import logging
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Callable
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.ptz import OnvifController, OnvifCommandEnum
|
||||
from frigate.ptz import OnvifCommandEnum, OnvifController
|
||||
from frigate.types import CameraMetricsTypes, RecordMetricsTypes
|
||||
from frigate.util import restart_frigate
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -72,7 +69,7 @@ class Dispatcher:
|
||||
camera_name = topic.split("/")[-3]
|
||||
command = topic.split("/")[-2]
|
||||
self._camera_settings_handlers[command](camera_name, payload)
|
||||
except IndexError as e:
|
||||
except IndexError:
|
||||
logger.error(f"Received invalid set command: {topic}")
|
||||
return
|
||||
elif topic.endswith("ptz"):
|
||||
@@ -80,7 +77,7 @@ class Dispatcher:
|
||||
# example /cam_name/ptz payload=MOVE_UP|MOVE_DOWN|STOP...
|
||||
camera_name = topic.split("/")[-2]
|
||||
self._on_ptz_command(camera_name, payload)
|
||||
except IndexError as e:
|
||||
except IndexError:
|
||||
logger.error(f"Received invalid ptz command: {topic}")
|
||||
return
|
||||
elif topic == "restart":
|
||||
@@ -128,7 +125,7 @@ class Dispatcher:
|
||||
elif payload == "OFF":
|
||||
if self.camera_metrics[camera_name]["detection_enabled"].value:
|
||||
logger.error(
|
||||
f"Turning off motion is not allowed when detection is enabled."
|
||||
"Turning off motion is not allowed when detection is enabled."
|
||||
)
|
||||
return
|
||||
|
||||
@@ -196,7 +193,7 @@ class Dispatcher:
|
||||
if payload == "ON":
|
||||
if not self.config.cameras[camera_name].record.enabled_in_config:
|
||||
logger.error(
|
||||
f"Recordings must be enabled in the config to be turned on via MQTT."
|
||||
"Recordings must be enabled in the config to be turned on via MQTT."
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from typing import Any, Callable
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
@@ -8,7 +7,6 @@ import paho.mqtt.client as mqtt
|
||||
from frigate.comms.dispatcher import Communicator
|
||||
from frigate.config import FrigateConfig
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -177,10 +175,10 @@ class MqttClient(Communicator): # type: ignore[misc]
|
||||
f"{self.mqtt_config.topic_prefix}/restart", self.on_mqtt_command
|
||||
)
|
||||
|
||||
if not self.mqtt_config.tls_ca_certs is None:
|
||||
if self.mqtt_config.tls_ca_certs is not None:
|
||||
if (
|
||||
not self.mqtt_config.tls_client_cert is None
|
||||
and not self.mqtt_config.tls_client_key is None
|
||||
self.mqtt_config.tls_client_cert is not None
|
||||
and self.mqtt_config.tls_client_key is not None
|
||||
):
|
||||
self.client.tls_set(
|
||||
self.mqtt_config.tls_ca_certs,
|
||||
@@ -189,9 +187,9 @@ class MqttClient(Communicator): # type: ignore[misc]
|
||||
)
|
||||
else:
|
||||
self.client.tls_set(self.mqtt_config.tls_ca_certs)
|
||||
if not self.mqtt_config.tls_insecure is None:
|
||||
if self.mqtt_config.tls_insecure is not None:
|
||||
self.client.tls_insecure_set(self.mqtt_config.tls_insecure)
|
||||
if not self.mqtt_config.user is None:
|
||||
if self.mqtt_config.user is not None:
|
||||
self.client.username_pw_set(
|
||||
self.mqtt_config.user, password=self.mqtt_config.password
|
||||
)
|
||||
|
||||
+3
-5
@@ -3,10 +3,9 @@
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from typing import Callable
|
||||
|
||||
from wsgiref.simple_server import make_server
|
||||
|
||||
from ws4py.server.wsgirefserver import (
|
||||
WebSocketWSGIHandler,
|
||||
WebSocketWSGIRequestHandler,
|
||||
@@ -18,7 +17,6 @@ from ws4py.websocket import WebSocket
|
||||
from frigate.comms.dispatcher import Communicator
|
||||
from frigate.config import FrigateConfig
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -45,7 +43,7 @@ class WebSocketClient(Communicator): # type: ignore[misc]
|
||||
"topic": json_message.get("topic"),
|
||||
"payload": json_message.get("payload"),
|
||||
}
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.warning(
|
||||
f"Unable to parse websocket message as valid json: {message.data.decode('utf-8')}"
|
||||
)
|
||||
@@ -82,7 +80,7 @@ class WebSocketClient(Communicator): # type: ignore[misc]
|
||||
"payload": payload,
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
# if the payload can't be decoded don't relay to clients
|
||||
logger.debug(f"payload for {topic} wasn't text. Skipping...")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user