From 6faa1ef8882e4366f36d5701f4aa82730025d2a8 Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Wed, 19 Mar 2025 22:13:39 +1100 Subject: [PATCH 1/7] validate ssl option --- custom_components/frigate/__init__.py | 2 ++ custom_components/frigate/api.py | 4 +++- custom_components/frigate/config_flow.py | 6 +++++- custom_components/frigate/const.py | 1 + custom_components/frigate/translations/en.json | 1 + custom_components/frigate/translations/fr.json | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/custom_components/frigate/__init__.py b/custom_components/frigate/__init__.py index 233ad9a5..001aa52a 100644 --- a/custom_components/frigate/__init__.py +++ b/custom_components/frigate/__init__.py @@ -31,6 +31,7 @@ CONF_PASSWORD, CONF_URL, CONF_USERNAME, + CONF_VALIDATE_SSL, ) from homeassistant.core import HomeAssistant, callback, valid_entity_id from homeassistant.exceptions import ConfigEntryNotReady @@ -204,6 +205,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async_get_clientsession(hass), entry.data.get(CONF_USERNAME), entry.data.get(CONF_PASSWORD), + entry.data.get(CONF_VALIDATE_SSL), ) coordinator = FrigateDataUpdateCoordinator(hass, client=client) await coordinator.async_config_entry_first_refresh() diff --git a/custom_components/frigate/api.py b/custom_components/frigate/api.py index a39e4217..a7de4578 100644 --- a/custom_components/frigate/api.py +++ b/custom_components/frigate/api.py @@ -40,6 +40,7 @@ def __init__( session: aiohttp.ClientSession, username: str | None = None, password: str | None = None, + validate_ssl: bool = True ) -> None: """Construct API Client.""" self._host = host @@ -47,6 +48,7 @@ def __init__( self._username = username self._password = password self._token_data: dict[str, Any] = {} + self.validate_ssl = validate_ssl async def async_get_version(self) -> str: """Get data from the API.""" @@ -347,7 +349,7 @@ async def api_wrapper( func = getattr(self._session, method) if func: response = await func( - url, headers=headers, raise_for_status=True, json=data + url, headers=headers, raise_for_status=True, json=data, ssl=self.validate_ssl ) response.raise_for_status() if is_login_request: diff --git a/custom_components/frigate/config_flow.py b/custom_components/frigate/config_flow.py index 39852f59..f5b092d3 100644 --- a/custom_components/frigate/config_flow.py +++ b/custom_components/frigate/config_flow.py @@ -10,7 +10,7 @@ from yarl import URL from homeassistant import config_entries -from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME +from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VALIDATE_SSL from homeassistant.core import callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_create_clientsession @@ -83,6 +83,7 @@ async def _handle_config_step( session, user_input.get(CONF_USERNAME), user_input.get(CONF_PASSWORD), + user_input.get(CONF_VALIDATE_SSL) ) await client.async_get_stats() except FrigateApiClientError: @@ -121,6 +122,9 @@ def _show_config_form( vol.Required( CONF_URL, default=user_input.get(CONF_URL, DEFAULT_HOST) ): str, + vol.Required( + CONF_VALIDATE_SSL, default=user_input.get(CONF_VALIDATE_SSL, True) + ): bool, vol.Optional( CONF_USERNAME, default=user_input.get(CONF_USERNAME, "") ): str, diff --git a/custom_components/frigate/const.py b/custom_components/frigate/const.py index 633d4954..b61a172a 100644 --- a/custom_components/frigate/const.py +++ b/custom_components/frigate/const.py @@ -59,6 +59,7 @@ CONF_PASSWORD = "password" CONF_PATH = "path" CONF_RTSP_URL_TEMPLATE = "rtsp_url_template" +CONF_VALIDATE_SSL = "validate_ssl" # Removed options CONF_CAMERA_STATIC_IMAGE_HEIGHT = "camera_image_height" diff --git a/custom_components/frigate/translations/en.json b/custom_components/frigate/translations/en.json index 669ed8b8..f17cd4b0 100644 --- a/custom_components/frigate/translations/en.json +++ b/custom_components/frigate/translations/en.json @@ -5,6 +5,7 @@ "description": "URL you use to access Frigate (ie. `http://frigate:5000/`)\n\nIf you are using HassOS with the addon, the URL should be `http://ccab4aaf-frigate:5000/`\n\nHome Assistant needs access to port 5000 (api) and 8554/8555 (rtsp, webrtc) for all features.\n\nThe integration will setup sensors, cameras, and media browser functionality.\n\nSensors:\n- Stats to monitor frigate performance\n- Object counts for all zones and cameras\n\nCameras:\n- Cameras for image of the last detected object for each camera\n- Camera entities with stream support\n\nMedia Browser:\n- Rich UI with thumbnails for browsing event clips\n- Rich UI for browsing 24/7 recordings by month, day, camera, time\n\nAPI:\n- Notification API with public facing endpoints for images in notifications", "data": { "url": "URL", + "validate_ssl": "Validate SSL", "username": "Username (optional)", "password": "Password (optional)" } diff --git a/custom_components/frigate/translations/fr.json b/custom_components/frigate/translations/fr.json index 8704d828..9adff763 100644 --- a/custom_components/frigate/translations/fr.json +++ b/custom_components/frigate/translations/fr.json @@ -5,6 +5,7 @@ "description": "URL que vous utilisez pour accéder à Frigate (par exemple, `http://frigate:5000/`)\n\nSi vous utilisez HassOS avec l'addon, l'URL devrait être `http://ccab4aaf-frigate:5000/`\n\nHome Assistant a besoin d'accès au port 5000 (api) et 8554/8555 (rtsp, webrtc) pour toutes les fonctionnalités.\n\nL'intégration configurera des capteurs, des caméras et la fonctionnalité de navigateur multimédia.\n\nCapteurs :\n- Statistiques pour surveiller la performance de Frigate\n- Comptes d'objets pour toutes les zones et caméras\n\nCaméras :\n- Caméras pour l'image du dernier objet détecté pour chaque caméra\n- Entités de caméra avec support de flux\n\nNavigateur multimédia :\n- Interface riche avec miniatures pour parcourir les clips d'événements\n- Interface riche pour parcourir les enregistrements 24/7 par mois, jour, caméra, heure\n\nAPI :\n- API de notification avec des points de terminaison publics pour les images dans les notifications", "data": { "url": "URL", + "validate_ssl": "Valider SSL", "username": "Nom d'utilisateur (facultatif)", "password": "Mot de passe (facultatif)" } From 89cc0ac0b5eab7b6af9c10526d04eb23569d3ce6 Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Thu, 20 Mar 2025 09:38:32 +1100 Subject: [PATCH 2/7] fix imports --- custom_components/frigate/__init__.py | 2 +- custom_components/frigate/config_flow.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/frigate/__init__.py b/custom_components/frigate/__init__.py index 001aa52a..5625e93e 100644 --- a/custom_components/frigate/__init__.py +++ b/custom_components/frigate/__init__.py @@ -31,7 +31,6 @@ CONF_PASSWORD, CONF_URL, CONF_USERNAME, - CONF_VALIDATE_SSL, ) from homeassistant.core import HomeAssistant, callback, valid_entity_id from homeassistant.exceptions import ConfigEntryNotReady @@ -52,6 +51,7 @@ ATTRIBUTE_LABELS, CONF_CAMERA_STATIC_IMAGE_HEIGHT, CONF_RTMP_URL_TEMPLATE, + CONF_VALIDATE_SSL, DOMAIN, FRIGATE_RELEASES_URL, FRIGATE_VERSION_ERROR_CUTOFF, diff --git a/custom_components/frigate/config_flow.py b/custom_components/frigate/config_flow.py index f5b092d3..e294dd97 100644 --- a/custom_components/frigate/config_flow.py +++ b/custom_components/frigate/config_flow.py @@ -10,7 +10,7 @@ from yarl import URL from homeassistant import config_entries -from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VALIDATE_SSL +from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME from homeassistant.core import callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_create_clientsession @@ -22,6 +22,7 @@ CONF_NOTIFICATION_PROXY_ENABLE, CONF_NOTIFICATION_PROXY_EXPIRE_AFTER_SECONDS, CONF_RTSP_URL_TEMPLATE, + CONF_VALIDATE_SSL, DEFAULT_HOST, DOMAIN, ) From 42ff8ec13ae86da805ce1c5f04c62026db1de056 Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Thu, 20 Mar 2025 10:16:35 +1100 Subject: [PATCH 3/7] fix var --- custom_components/frigate/__init__.py | 3 +-- custom_components/frigate/config_flow.py | 5 ++--- custom_components/frigate/const.py | 1 - 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/custom_components/frigate/__init__.py b/custom_components/frigate/__init__.py index 5625e93e..f357a65d 100644 --- a/custom_components/frigate/__init__.py +++ b/custom_components/frigate/__init__.py @@ -51,7 +51,6 @@ ATTRIBUTE_LABELS, CONF_CAMERA_STATIC_IMAGE_HEIGHT, CONF_RTMP_URL_TEMPLATE, - CONF_VALIDATE_SSL, DOMAIN, FRIGATE_RELEASES_URL, FRIGATE_VERSION_ERROR_CUTOFF, @@ -205,7 +204,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async_get_clientsession(hass), entry.data.get(CONF_USERNAME), entry.data.get(CONF_PASSWORD), - entry.data.get(CONF_VALIDATE_SSL), + entry.data.get("validate_ssl"), ) coordinator = FrigateDataUpdateCoordinator(hass, client=client) await coordinator.async_config_entry_first_refresh() diff --git a/custom_components/frigate/config_flow.py b/custom_components/frigate/config_flow.py index e294dd97..0cacf66f 100644 --- a/custom_components/frigate/config_flow.py +++ b/custom_components/frigate/config_flow.py @@ -22,7 +22,6 @@ CONF_NOTIFICATION_PROXY_ENABLE, CONF_NOTIFICATION_PROXY_EXPIRE_AFTER_SECONDS, CONF_RTSP_URL_TEMPLATE, - CONF_VALIDATE_SSL, DEFAULT_HOST, DOMAIN, ) @@ -84,7 +83,7 @@ async def _handle_config_step( session, user_input.get(CONF_USERNAME), user_input.get(CONF_PASSWORD), - user_input.get(CONF_VALIDATE_SSL) + user_input.get("validate_ssl") ) await client.async_get_stats() except FrigateApiClientError: @@ -124,7 +123,7 @@ def _show_config_form( CONF_URL, default=user_input.get(CONF_URL, DEFAULT_HOST) ): str, vol.Required( - CONF_VALIDATE_SSL, default=user_input.get(CONF_VALIDATE_SSL, True) + "validate_ssl", default=user_input.get("validate_ssl", True) ): bool, vol.Optional( CONF_USERNAME, default=user_input.get(CONF_USERNAME, "") diff --git a/custom_components/frigate/const.py b/custom_components/frigate/const.py index b61a172a..633d4954 100644 --- a/custom_components/frigate/const.py +++ b/custom_components/frigate/const.py @@ -59,7 +59,6 @@ CONF_PASSWORD = "password" CONF_PATH = "path" CONF_RTSP_URL_TEMPLATE = "rtsp_url_template" -CONF_VALIDATE_SSL = "validate_ssl" # Removed options CONF_CAMERA_STATIC_IMAGE_HEIGHT = "camera_image_height" From df448353508b336159f109a6b7ac90487e9bcca9 Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Thu, 20 Mar 2025 10:24:07 +1100 Subject: [PATCH 4/7] format --- custom_components/frigate/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/frigate/api.py b/custom_components/frigate/api.py index a7de4578..cffa40b8 100644 --- a/custom_components/frigate/api.py +++ b/custom_components/frigate/api.py @@ -349,7 +349,11 @@ async def api_wrapper( func = getattr(self._session, method) if func: response = await func( - url, headers=headers, raise_for_status=True, json=data, ssl=self.validate_ssl + url, + headers=headers, + raise_for_status=True, + json=data, + ssl=self.validate_ssl ) response.raise_for_status() if is_login_request: From 792a6b61c6e175d4e4c5f7b266d74b5306c1fc3a Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Thu, 20 Mar 2025 10:32:33 +1100 Subject: [PATCH 5/7] fix tests --- tests/test_config_flow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 24938103..1fd54bc9 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -62,6 +62,7 @@ async def test_user_success(hass: HomeAssistant) -> None: CONF_URL: TEST_URL, CONF_PASSWORD: "", CONF_USERNAME: "", + "validate_ssl": True, } assert len(mock_setup_entry.mock_calls) == 1 assert mock_client.async_get_stats.called @@ -90,6 +91,7 @@ async def test_user_success_with_auth(hass: HomeAssistant) -> None: CONF_PASSWORD: TEST_PASSWORD, CONF_URL: TEST_URL, CONF_USERNAME: TEST_USERNAME, + "validate_ssl": True, }, ) await hass.async_block_till_done() From 171ec1ae3593dd468f28b9ebe5d15b956dd6796d Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Thu, 20 Mar 2025 10:33:18 +1100 Subject: [PATCH 6/7] fix tests --- tests/test_config_flow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 1fd54bc9..12a1dd40 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -102,6 +102,7 @@ async def test_user_success_with_auth(hass: HomeAssistant) -> None: CONF_URL: TEST_URL, CONF_PASSWORD: TEST_PASSWORD, CONF_USERNAME: TEST_USERNAME, + "validate_ssl": True, } assert len(mock_setup_entry.mock_calls) == 1 assert mock_client.async_get_stats.called From 9604a10e24b722051ed64ec3c8ce8162ceeba81b Mon Sep 17 00:00:00 2001 From: nickwalchli Date: Thu, 20 Mar 2025 13:46:37 +1100 Subject: [PATCH 7/7] black+mypi fixes --- custom_components/frigate/__init__.py | 2 +- custom_components/frigate/api.py | 4 ++-- custom_components/frigate/config_flow.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/frigate/__init__.py b/custom_components/frigate/__init__.py index f357a65d..87f8cb2e 100644 --- a/custom_components/frigate/__init__.py +++ b/custom_components/frigate/__init__.py @@ -204,7 +204,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async_get_clientsession(hass), entry.data.get(CONF_USERNAME), entry.data.get(CONF_PASSWORD), - entry.data.get("validate_ssl"), + bool(entry.data.get("validate_ssl")), ) coordinator = FrigateDataUpdateCoordinator(hass, client=client) await coordinator.async_config_entry_first_refresh() diff --git a/custom_components/frigate/api.py b/custom_components/frigate/api.py index cffa40b8..0e7a5c33 100644 --- a/custom_components/frigate/api.py +++ b/custom_components/frigate/api.py @@ -40,7 +40,7 @@ def __init__( session: aiohttp.ClientSession, username: str | None = None, password: str | None = None, - validate_ssl: bool = True + validate_ssl: bool = True, ) -> None: """Construct API Client.""" self._host = host @@ -353,7 +353,7 @@ async def api_wrapper( headers=headers, raise_for_status=True, json=data, - ssl=self.validate_ssl + ssl=self.validate_ssl, ) response.raise_for_status() if is_login_request: diff --git a/custom_components/frigate/config_flow.py b/custom_components/frigate/config_flow.py index 0cacf66f..47c78dc3 100644 --- a/custom_components/frigate/config_flow.py +++ b/custom_components/frigate/config_flow.py @@ -83,7 +83,7 @@ async def _handle_config_step( session, user_input.get(CONF_USERNAME), user_input.get(CONF_PASSWORD), - user_input.get("validate_ssl") + bool(user_input.get("validate_ssl")), ) await client.async_get_stats() except FrigateApiClientError: