From 0d4c82b54dfa8268374c515d855142e35c4f27a7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 17 Feb 2024 19:49:47 -0600 Subject: [PATCH] Convert Integration platforms processors where nothing is awaited to callbacks (#110825) Convert Integration platforms processors where nothing is awaited callbacks --- homeassistant/components/backup/manager.py | 5 +++-- homeassistant/components/cast/__init__.py | 5 +++-- homeassistant/components/diagnostics/__init__.py | 3 ++- homeassistant/components/energy/websocket_api.py | 3 ++- homeassistant/components/group/__init__.py | 3 ++- homeassistant/components/hardware/hardware.py | 5 +++-- homeassistant/components/logbook/__init__.py | 5 ++--- homeassistant/components/recorder/__init__.py | 5 +++-- homeassistant/components/repairs/issue_handler.py | 3 ++- homeassistant/components/system_health/__init__.py | 3 ++- homeassistant/helpers/significant_change.py | 3 ++- tests/components/logbook/test_init.py | 2 +- tests/components/logbook/test_websocket_api.py | 4 ++-- 13 files changed, 29 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/backup/manager.py b/homeassistant/components/backup/manager.py index 60739c39c2b..4c06f2171b6 100644 --- a/homeassistant/components/backup/manager.py +++ b/homeassistant/components/backup/manager.py @@ -15,7 +15,7 @@ from typing import Any, Protocol, cast from securetar import SecureTarFile, atomic_contents_add from homeassistant.const import __version__ as HAVERSION -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import integration_platform from homeassistant.helpers.json import json_bytes @@ -65,7 +65,8 @@ class BackupManager: self.loaded_backups = False self.loaded_platforms = False - async def _add_platform( + @callback + def _add_platform( self, hass: HomeAssistant, integration_domain: str, diff --git a/homeassistant/components/cast/__init__.py b/homeassistant/components/cast/__init__.py index aa0bdfa8118..8c574e0792b 100644 --- a/homeassistant/components/cast/__init__.py +++ b/homeassistant/components/cast/__init__.py @@ -8,7 +8,7 @@ from pychromecast import Chromecast from homeassistant.components.media_player import BrowseMedia, MediaType from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers.integration_platform import ( @@ -66,7 +66,8 @@ class CastProtocol(Protocol): """ -async def _register_cast_platform( +@callback +def _register_cast_platform( hass: HomeAssistant, integration_domain: str, platform: CastProtocol ): """Register a cast platform.""" diff --git a/homeassistant/components/diagnostics/__init__.py b/homeassistant/components/diagnostics/__init__.py index 939bd5f5000..679efd137ce 100644 --- a/homeassistant/components/diagnostics/__init__.py +++ b/homeassistant/components/diagnostics/__init__.py @@ -85,7 +85,8 @@ class DiagnosticsProtocol(Protocol): """Return diagnostics for a device.""" -async def _register_diagnostics_platform( +@callback +def _register_diagnostics_platform( hass: HomeAssistant, integration_domain: str, platform: DiagnosticsProtocol ) -> None: """Register a diagnostics platform.""" diff --git a/homeassistant/components/energy/websocket_api.py b/homeassistant/components/energy/websocket_api.py index a4ee4d0d15f..5d9cd81013d 100644 --- a/homeassistant/components/energy/websocket_api.py +++ b/homeassistant/components/energy/websocket_api.py @@ -61,7 +61,8 @@ async def async_get_energy_platforms( """Get energy platforms.""" platforms: dict[str, GetSolarForecastType] = {} - async def _process_energy_platform( + @callback + def _process_energy_platform( hass: HomeAssistant, domain: str, platform: ModuleType ) -> None: """Process energy platforms.""" diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py index 894a20629ee..9ee81191bf8 100644 --- a/homeassistant/components/group/__init__.py +++ b/homeassistant/components/group/__init__.py @@ -383,7 +383,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def _process_group_platform( +@callback +def _process_group_platform( hass: HomeAssistant, domain: str, platform: GroupProtocol ) -> None: """Process a group platform.""" diff --git a/homeassistant/components/hardware/hardware.py b/homeassistant/components/hardware/hardware.py index cc904fbf131..d44a232c232 100644 --- a/homeassistant/components/hardware/hardware.py +++ b/homeassistant/components/hardware/hardware.py @@ -1,7 +1,7 @@ """The Hardware integration.""" from __future__ import annotations -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.integration_platform import ( async_process_integration_platforms, @@ -18,7 +18,8 @@ async def async_process_hardware_platforms(hass: HomeAssistant) -> None: await async_process_integration_platforms(hass, DOMAIN, _register_hardware_platform) -async def _register_hardware_platform( +@callback +def _register_hardware_platform( hass: HomeAssistant, integration_domain: str, platform: HardwareProtocol ) -> None: """Register a hardware platform.""" diff --git a/homeassistant/components/logbook/__init__.py b/homeassistant/components/logbook/__init__.py index 0c614972e1e..891d1fb3fb0 100644 --- a/homeassistant/components/logbook/__init__.py +++ b/homeassistant/components/logbook/__init__.py @@ -145,9 +145,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def _process_logbook_platform( - hass: HomeAssistant, domain: str, platform: Any -) -> None: +@callback +def _process_logbook_platform(hass: HomeAssistant, domain: str, platform: Any) -> None: """Process a logbook platform.""" logbook_config: LogbookConfig = hass.data[DOMAIN] external_events = logbook_config.external_events diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index c82d431a8fa..2217d6c7d4e 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -12,7 +12,7 @@ from homeassistant.const import ( EVENT_RECORDER_HOURLY_STATISTICS_GENERATED, # noqa: F401 EVENT_STATE_CHANGED, ) -from homeassistant.core import HomeAssistant +from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entityfilter import ( INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA, @@ -178,7 +178,8 @@ async def _async_setup_integration_platform( ) -> None: """Set up a recorder integration platform.""" - async def _process_recorder_platform( + @callback + def _process_recorder_platform( hass: HomeAssistant, domain: str, platform: Any ) -> None: """Process a recorder platform.""" diff --git a/homeassistant/components/repairs/issue_handler.py b/homeassistant/components/repairs/issue_handler.py index 54b1f249ca6..f2ce3bac84e 100644 --- a/homeassistant/components/repairs/issue_handler.py +++ b/homeassistant/components/repairs/issue_handler.py @@ -105,7 +105,8 @@ async def async_process_repairs_platforms(hass: HomeAssistant) -> None: await async_process_integration_platforms(hass, DOMAIN, _register_repairs_platform) -async def _register_repairs_platform( +@callback +def _register_repairs_platform( hass: HomeAssistant, integration_domain: str, platform: RepairsProtocol ) -> None: """Register a repairs platform.""" diff --git a/homeassistant/components/system_health/__init__.py b/homeassistant/components/system_health/__init__.py index 4b33a2f7423..7c4d0f9ac46 100644 --- a/homeassistant/components/system_health/__init__.py +++ b/homeassistant/components/system_health/__init__.py @@ -70,7 +70,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: return True -async def _register_system_health_platform( +@callback +def _register_system_health_platform( hass: HomeAssistant, integration_domain: str, platform: SystemHealthProtocol ) -> None: """Register a system health platform.""" diff --git a/homeassistant/helpers/significant_change.py b/homeassistant/helpers/significant_change.py index 9bda3ca4eb2..12b78b75fa2 100644 --- a/homeassistant/helpers/significant_change.py +++ b/homeassistant/helpers/significant_change.py @@ -82,7 +82,8 @@ async def _initialize(hass: HomeAssistant) -> None: functions = hass.data[DATA_FUNCTIONS] = {} - async def process_platform( + @callback + def process_platform( hass: HomeAssistant, component_name: str, platform: Any ) -> None: """Process a significant change platform.""" diff --git a/tests/components/logbook/test_init.py b/tests/components/logbook/test_init.py index 671c70168d2..803aaba346a 100644 --- a/tests/components/logbook/test_init.py +++ b/tests/components/logbook/test_init.py @@ -2654,7 +2654,7 @@ async def test_get_events_with_device_ids( async_describe_event("test", "mock_event", async_describe_test_event) - await logbook._process_logbook_platform(hass, "test", MockLogbookPlatform) + logbook._process_logbook_platform(hass, "test", MockLogbookPlatform) hass.bus.async_fire(EVENT_HOMEASSISTANT_START) hass.bus.async_fire("mock_event", {"device_id": device.id}) diff --git a/tests/components/logbook/test_websocket_api.py b/tests/components/logbook/test_websocket_api.py index c68cbedc44a..7100f914ff4 100644 --- a/tests/components/logbook/test_websocket_api.py +++ b/tests/components/logbook/test_websocket_api.py @@ -82,7 +82,7 @@ async def _async_mock_logbook_platform_with_broken_describe( async_describe_event("test", "mock_event", async_describe_test_event) - await logbook._process_logbook_platform(hass, "test", MockLogbookPlatform) + logbook._process_logbook_platform(hass, "test", MockLogbookPlatform) async def _async_mock_logbook_platform(hass: HomeAssistant) -> None: @@ -108,7 +108,7 @@ async def _async_mock_logbook_platform(hass: HomeAssistant) -> None: async_describe_event("test", "mock_event", async_describe_test_event) - await logbook._process_logbook_platform(hass, "test", MockLogbookPlatform) + logbook._process_logbook_platform(hass, "test", MockLogbookPlatform) async def _async_mock_entity_with_broken_logbook_platform(