From c69495b64f7c06ae5519c002a42901174dfc252e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 15 Mar 2024 00:13:44 -1000 Subject: [PATCH] Remove supports_encryption check from mobile_app (#113490) helpers already ports nacl at top level so this check can never be False ``` >>> import sys >>> from nacl.secret import SecretBox >>> assert nacl in sys.modules >>> ``` --- homeassistant/components/mobile_app/helpers.py | 10 ---------- homeassistant/components/mobile_app/http_api.py | 3 +-- homeassistant/components/mobile_app/webhook.py | 9 --------- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/homeassistant/components/mobile_app/helpers.py b/homeassistant/components/mobile_app/helpers.py index e30974123df..13d50b7984f 100644 --- a/homeassistant/components/mobile_app/helpers.py +++ b/homeassistant/components/mobile_app/helpers.py @@ -143,16 +143,6 @@ def error_response( ) -def supports_encryption() -> bool: - """Test if we support encryption.""" - try: - import nacl # noqa: F401 pylint: disable=import-outside-toplevel - - return True - except OSError: - return False - - def safe_registration(registration: dict) -> dict: """Return a registration without sensitive values.""" # Sensitive values: webhook_id, secret, cloudhook_url diff --git a/homeassistant/components/mobile_app/http_api.py b/homeassistant/components/mobile_app/http_api.py index 8c071fe0342..f4786b2914c 100644 --- a/homeassistant/components/mobile_app/http_api.py +++ b/homeassistant/components/mobile_app/http_api.py @@ -35,7 +35,6 @@ from .const import ( DOMAIN, SCHEMA_APP_DATA, ) -from .helpers import supports_encryption from .util import async_create_cloud_hook @@ -77,7 +76,7 @@ class RegistrationsView(HomeAssistantView): data[CONF_WEBHOOK_ID] = webhook_id - if data[ATTR_SUPPORTS_ENCRYPTION] and supports_encryption(): + if data[ATTR_SUPPORTS_ENCRYPTION]: data[CONF_SECRET] = secrets.token_hex(SecretBox.KEY_SIZE) data[CONF_USER_ID] = request["hass_user"].id diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index 0a55a5337b3..3cef5ae645a 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -100,7 +100,6 @@ from .const import ( DATA_DEVICES, DOMAIN, ERR_ENCRYPTION_ALREADY_ENABLED, - ERR_ENCRYPTION_NOT_AVAILABLE, ERR_ENCRYPTION_REQUIRED, ERR_INVALID_FORMAT, ERR_SENSOR_NOT_REGISTERED, @@ -115,7 +114,6 @@ from .helpers import ( error_response, registration_context, safe_registration, - supports_encryption, webhook_response, ) @@ -484,13 +482,6 @@ async def webhook_enable_encryption( ERR_ENCRYPTION_ALREADY_ENABLED, "Encryption already enabled" ) - if not supports_encryption(): - _LOGGER.warning( - "Unable to enable encryption for %s because libsodium is unavailable!", - config_entry.data[ATTR_DEVICE_NAME], - ) - return error_response(ERR_ENCRYPTION_NOT_AVAILABLE, "Encryption is unavailable") - secret = secrets.token_hex(SecretBox.KEY_SIZE) update_data = {