diff --git a/homeassistant/components/websocket_api/permissions.py b/homeassistant/auth/permissions/events.py similarity index 70% rename from homeassistant/components/websocket_api/permissions.py rename to homeassistant/auth/permissions/events.py index f3a0cebe51f..d50da96a39f 100644 --- a/homeassistant/components/websocket_api/permissions.py +++ b/homeassistant/auth/permissions/events.py @@ -1,26 +1,18 @@ -"""Permission constants for the websocket API. - -Separate file to avoid circular imports. -""" +"""Permission for events.""" from __future__ import annotations from typing import Final -from homeassistant.components.frontend import EVENT_PANELS_UPDATED -from homeassistant.components.lovelace import EVENT_LOVELACE_UPDATED -from homeassistant.components.persistent_notification import ( - EVENT_PERSISTENT_NOTIFICATIONS_UPDATED, -) -from homeassistant.components.recorder import ( - EVENT_RECORDER_5MIN_STATISTICS_GENERATED, - EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, -) -from homeassistant.components.shopping_list import EVENT_SHOPPING_LIST_UPDATED from homeassistant.const import ( EVENT_COMPONENT_LOADED, EVENT_CORE_CONFIG_UPDATE, + EVENT_LOVELACE_UPDATED, + EVENT_PANELS_UPDATED, + EVENT_RECORDER_5MIN_STATISTICS_GENERATED, + EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REMOVED, + EVENT_SHOPPING_LIST_UPDATED, EVENT_STATE_CHANGED, EVENT_THEMES_UPDATED, ) @@ -38,7 +30,6 @@ SUBSCRIBE_ALLOWLIST: Final[set[str]] = { EVENT_ENTITY_REGISTRY_UPDATED, EVENT_LOVELACE_UPDATED, EVENT_PANELS_UPDATED, - EVENT_PERSISTENT_NOTIFICATIONS_UPDATED, EVENT_RECORDER_5MIN_STATISTICS_GENERATED, EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, EVENT_SERVICE_REGISTERED, diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index a5a4d76f9e7..98b6f0331b5 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -17,7 +17,12 @@ from homeassistant.components import onboarding, websocket_api from homeassistant.components.http.view import HomeAssistantView from homeassistant.components.websocket_api.connection import ActiveConnection from homeassistant.config import async_hass_config_yaml -from homeassistant.const import CONF_MODE, CONF_NAME, EVENT_THEMES_UPDATED +from homeassistant.const import ( + CONF_MODE, + CONF_NAME, + EVENT_PANELS_UPDATED, + EVENT_THEMES_UPDATED, +) from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import service import homeassistant.helpers.config_validation as cv @@ -40,7 +45,6 @@ CONF_EXTRA_MODULE_URL = "extra_module_url" CONF_EXTRA_JS_URL_ES5 = "extra_js_url_es5" CONF_FRONTEND_REPO = "development_repo" CONF_JS_VERSION = "javascript_version" -EVENT_PANELS_UPDATED = "panels_updated" DEFAULT_THEME_COLOR = "#03A9F4" diff --git a/homeassistant/components/lovelace/const.py b/homeassistant/components/lovelace/const.py index 6952a80a214..01110bb8a7c 100644 --- a/homeassistant/components/lovelace/const.py +++ b/homeassistant/components/lovelace/const.py @@ -3,13 +3,18 @@ from typing import Any import voluptuous as vol -from homeassistant.const import CONF_ICON, CONF_MODE, CONF_TYPE, CONF_URL +from homeassistant.const import ( + CONF_ICON, + CONF_MODE, + CONF_TYPE, + CONF_URL, + EVENT_LOVELACE_UPDATED, # noqa: F401 +) from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv from homeassistant.util import slugify DOMAIN = "lovelace" -EVENT_LOVELACE_UPDATED = "lovelace_updated" DEFAULT_ICON = "hass:view-dashboard" diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index c9e8e3703db..9ecb91bdb7f 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -30,10 +30,6 @@ ATTR_TITLE: Final = "title" ATTR_STATUS: Final = "status" -# Remove EVENT_PERSISTENT_NOTIFICATIONS_UPDATED in Home Assistant 2023.9 -EVENT_PERSISTENT_NOTIFICATIONS_UPDATED = "persistent_notifications_updated" - - class Notification(TypedDict): """Persistent notification.""" diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index 1c00149192f..c82d431a8fa 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -6,7 +6,12 @@ from typing import Any import voluptuous as vol -from homeassistant.const import CONF_EXCLUDE, EVENT_STATE_CHANGED +from homeassistant.const import ( + CONF_EXCLUDE, + EVENT_RECORDER_5MIN_STATISTICS_GENERATED, # noqa: F401 + EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, # noqa: F401 + EVENT_STATE_CHANGED, +) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entityfilter import ( @@ -25,8 +30,6 @@ from .const import ( # noqa: F401 CONF_DB_INTEGRITY_CHECK, DATA_INSTANCE, DOMAIN, - EVENT_RECORDER_5MIN_STATISTICS_GENERATED, - EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, INTEGRATION_PLATFORM_COMPILE_STATISTICS, INTEGRATION_PLATFORMS_LOAD_IN_RECORDER_THREAD, SQLITE_URL_PREFIX, diff --git a/homeassistant/components/recorder/const.py b/homeassistant/components/recorder/const.py index dbfa1a2ff73..66d46c0c20e 100644 --- a/homeassistant/components/recorder/const.py +++ b/homeassistant/components/recorder/const.py @@ -2,7 +2,13 @@ from enum import StrEnum -from homeassistant.const import ATTR_ATTRIBUTION, ATTR_RESTORED, ATTR_SUPPORTED_FEATURES +from homeassistant.const import ( + ATTR_ATTRIBUTION, + ATTR_RESTORED, + ATTR_SUPPORTED_FEATURES, + EVENT_RECORDER_5MIN_STATISTICS_GENERATED, # noqa: F401 + EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, # noqa: F401 +) from homeassistant.helpers.json import JSON_DUMP # noqa: F401 DATA_INSTANCE = "recorder_instance" @@ -13,9 +19,6 @@ MYSQLDB_URL_PREFIX = "mysql://" MYSQLDB_PYMYSQL_URL_PREFIX = "mysql+pymysql://" DOMAIN = "recorder" -EVENT_RECORDER_5MIN_STATISTICS_GENERATED = "recorder_5min_statistics_generated" -EVENT_RECORDER_HOURLY_STATISTICS_GENERATED = "recorder_hourly_statistics_generated" - CONF_DB_INTEGRITY_CHECK = "db_integrity_check" MAX_QUEUE_BACKLOG_MIN_VALUE = 65000 diff --git a/homeassistant/components/shopping_list/const.py b/homeassistant/components/shopping_list/const.py index c519123a414..22553d9c316 100644 --- a/homeassistant/components/shopping_list/const.py +++ b/homeassistant/components/shopping_list/const.py @@ -1,6 +1,9 @@ """All constants related to the shopping list component.""" + +from homeassistant.const import EVENT_SHOPPING_LIST_UPDATED # noqa: F401 + DOMAIN = "shopping_list" -EVENT_SHOPPING_LIST_UPDATED = "shopping_list_updated" + ATTR_REVERSE = "reverse" diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index cef9e7bb706..a29bee86116 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -12,6 +12,7 @@ import voluptuous as vol from homeassistant.auth.models import User from homeassistant.auth.permissions.const import POLICY_READ +from homeassistant.auth.permissions.events import SUBSCRIBE_ALLOWLIST from homeassistant.const import ( EVENT_STATE_CHANGED, MATCH_ALL, @@ -128,10 +129,6 @@ def handle_subscribe_events( hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any] ) -> None: """Handle subscribe events command.""" - # Circular dep - # pylint: disable-next=import-outside-toplevel - from .permissions import SUBSCRIBE_ALLOWLIST - event_type = msg["event_type"] if event_type not in SUBSCRIBE_ALLOWLIST and not connection.user.is_admin: diff --git a/homeassistant/const.py b/homeassistant/const.py index 31256e502a4..2d84a57afa4 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -293,6 +293,13 @@ EVENT_SERVICE_REGISTERED: Final = "service_registered" EVENT_SERVICE_REMOVED: Final = "service_removed" EVENT_STATE_CHANGED: Final = "state_changed" EVENT_THEMES_UPDATED: Final = "themes_updated" +EVENT_PANELS_UPDATED: Final = "panels_updated" +EVENT_LOVELACE_UPDATED: Final = "lovelace_updated" +EVENT_RECORDER_5MIN_STATISTICS_GENERATED: Final = "recorder_5min_statistics_generated" +EVENT_RECORDER_HOURLY_STATISTICS_GENERATED: Final = ( + "recorder_hourly_statistics_generated" +) +EVENT_SHOPPING_LIST_UPDATED: Final = "shopping_list_updated" # #### DEVICE CLASSES #### # DEVICE_CLASS_* below are deprecated as of 2021.12