diff --git a/homeassistant/components/cast/home_assistant_cast.py b/homeassistant/components/cast/home_assistant_cast.py index 2f9583f329c..010e4a046b4 100644 --- a/homeassistant/components/cast/home_assistant_cast.py +++ b/homeassistant/components/cast/home_assistant_cast.py @@ -9,6 +9,7 @@ from homeassistant.const import ATTR_ENTITY_ID from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import config_validation as cv, dispatcher from homeassistant.helpers.network import NoURLAvailableError, get_url +from homeassistant.helpers.service import async_register_admin_service from .const import DOMAIN, SIGNAL_HASS_CAST_SHOW_VIEW @@ -65,7 +66,8 @@ async def async_setup_ha_cast( call.data.get(ATTR_URL_PATH), ) - hass.helpers.service.async_register_admin_service( + async_register_admin_service( + hass, DOMAIN, SERVICE_SHOW_VIEW, handle_show_view, diff --git a/homeassistant/components/cloud/__init__.py b/homeassistant/components/cloud/__init__.py index 360e726c89e..559453fe02b 100644 --- a/homeassistant/components/cloud/__init__.py +++ b/homeassistant/components/cloud/__init__.py @@ -26,6 +26,7 @@ from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) +from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util.aiohttp import MockRequest @@ -250,11 +251,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: elif service.service == SERVICE_REMOTE_DISCONNECT: await prefs.async_update(remote_enabled=False) - hass.helpers.service.async_register_admin_service( - DOMAIN, SERVICE_REMOTE_CONNECT, _service_handler - ) - hass.helpers.service.async_register_admin_service( - DOMAIN, SERVICE_REMOTE_DISCONNECT, _service_handler + async_register_admin_service(hass, DOMAIN, SERVICE_REMOTE_CONNECT, _service_handler) + async_register_admin_service( + hass, DOMAIN, SERVICE_REMOTE_DISCONNECT, _service_handler ) loaded = False diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index f79213e2484..81d79b03c10 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -27,6 +27,7 @@ from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.service import ( async_extract_config_entry_ids, async_extract_referenced_entity_ids, + async_register_admin_service, ) from homeassistant.helpers.typing import ConfigType @@ -206,14 +207,14 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no if tasks: await asyncio.wait(tasks) - hass.helpers.service.async_register_admin_service( - ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP, async_handle_core_service + async_register_admin_service( + hass, ha.DOMAIN, SERVICE_HOMEASSISTANT_STOP, async_handle_core_service ) - hass.helpers.service.async_register_admin_service( - ha.DOMAIN, SERVICE_HOMEASSISTANT_RESTART, async_handle_core_service + async_register_admin_service( + hass, ha.DOMAIN, SERVICE_HOMEASSISTANT_RESTART, async_handle_core_service ) - hass.helpers.service.async_register_admin_service( - ha.DOMAIN, SERVICE_CHECK_CONFIG, async_handle_core_service + async_register_admin_service( + hass, ha.DOMAIN, SERVICE_CHECK_CONFIG, async_handle_core_service ) hass.services.async_register( ha.DOMAIN, @@ -233,8 +234,8 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no # auth only processed during startup await conf_util.async_process_ha_core_config(hass, conf.get(ha.DOMAIN) or {}) - hass.helpers.service.async_register_admin_service( - ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG, async_handle_reload_config + async_register_admin_service( + hass, ha.DOMAIN, SERVICE_RELOAD_CORE_CONFIG, async_handle_reload_config ) async def async_set_location(call: ha.ServiceCall) -> None: @@ -243,7 +244,8 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no latitude=call.data[ATTR_LATITUDE], longitude=call.data[ATTR_LONGITUDE] ) - hass.helpers.service.async_register_admin_service( + async_register_admin_service( + hass, ha.DOMAIN, SERVICE_SET_LOCATION, async_set_location, @@ -265,7 +267,8 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no ) ) - hass.helpers.service.async_register_admin_service( + async_register_admin_service( + hass, ha.DOMAIN, SERVICE_RELOAD_CONFIG_ENTRY, async_handle_reload_config_entry, diff --git a/homeassistant/components/homeassistant/scene.py b/homeassistant/components/homeassistant/scene.py index 505dc0027d6..bf8affd902e 100644 --- a/homeassistant/components/homeassistant/scene.py +++ b/homeassistant/components/homeassistant/scene.py @@ -35,6 +35,7 @@ from homeassistant.helpers import ( entity_platform, ) from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.state import async_reproduce_state from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.loader import async_get_integration @@ -206,9 +207,7 @@ async def async_setup_platform( hass.bus.async_fire(EVENT_SCENE_RELOADED, context=call.context) - hass.helpers.service.async_register_admin_service( - SCENE_DOMAIN, SERVICE_RELOAD, reload_config - ) + async_register_admin_service(hass, SCENE_DOMAIN, SERVICE_RELOAD, reload_config) async def apply_service(call: ServiceCall) -> None: """Apply a scene.""" diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 48f8f336fe7..1cba9746609 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -54,7 +54,10 @@ from homeassistant.helpers.entityfilter import ( EntityFilter, ) from homeassistant.helpers.reload import async_integration_yaml_config -from homeassistant.helpers.service import async_extract_referenced_entity_ids +from homeassistant.helpers.service import ( + async_extract_referenced_entity_ids, + async_register_admin_service, +) from homeassistant.helpers.typing import ConfigType from homeassistant.loader import IntegrationNotFound, async_get_integration @@ -461,7 +464,8 @@ def _async_register_events_and_services(hass: HomeAssistant) -> None: await asyncio.gather(*reload_tasks) - hass.helpers.service.async_register_admin_service( + async_register_admin_service( + hass, DOMAIN, SERVICE_RELOAD, _handle_homekit_reload, diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index d8afbd752a4..601a3b9af8d 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -47,6 +47,7 @@ from homeassistant.helpers import ( from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.event import async_track_time_interval +from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.typing import ConfigType from .const import ( @@ -531,7 +532,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: _LOGGER.error("%s: unsupported service", service.service) for service in ADMIN_SERVICES: - hass.helpers.service.async_register_admin_service( + async_register_admin_service( + hass, DOMAIN, service, service_handler, diff --git a/homeassistant/components/isy994/services.py b/homeassistant/components/isy994/services.py index 8323394803f..654b65309fc 100644 --- a/homeassistant/components/isy994/services.py +++ b/homeassistant/components/isy994/services.py @@ -19,6 +19,7 @@ from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import async_get_platforms import homeassistant.helpers.entity_registry as er +from homeassistant.helpers.service import entity_service_call from .const import ( _LOGGER, @@ -373,8 +374,8 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901 ) async def _async_send_raw_node_command(call: ServiceCall) -> None: - await hass.helpers.service.entity_service_call( - async_get_platforms(hass, DOMAIN), "async_send_raw_node_command", call + await entity_service_call( + hass, async_get_platforms(hass, DOMAIN), "async_send_raw_node_command", call ) hass.services.async_register( @@ -385,8 +386,8 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901 ) async def _async_send_node_command(call: ServiceCall) -> None: - await hass.helpers.service.entity_service_call( - async_get_platforms(hass, DOMAIN), "async_send_node_command", call + await entity_service_call( + hass, async_get_platforms(hass, DOMAIN), "async_send_node_command", call ) hass.services.async_register( @@ -397,8 +398,8 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901 ) async def _async_get_zwave_parameter(call: ServiceCall) -> None: - await hass.helpers.service.entity_service_call( - async_get_platforms(hass, DOMAIN), "async_get_zwave_parameter", call + await entity_service_call( + hass, async_get_platforms(hass, DOMAIN), "async_get_zwave_parameter", call ) hass.services.async_register( @@ -409,8 +410,8 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901 ) async def _async_set_zwave_parameter(call: ServiceCall) -> None: - await hass.helpers.service.entity_service_call( - async_get_platforms(hass, DOMAIN), "async_set_zwave_parameter", call + await entity_service_call( + hass, async_get_platforms(hass, DOMAIN), "async_set_zwave_parameter", call ) hass.services.async_register( @@ -421,8 +422,8 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901 ) async def _async_rename_node(call: ServiceCall) -> None: - await hass.helpers.service.entity_service_call( - async_get_platforms(hass, DOMAIN), "async_rename_node", call + await entity_service_call( + hass, async_get_platforms(hass, DOMAIN), "async_rename_node", call ) hass.services.async_register( diff --git a/homeassistant/components/template/__init__.py b/homeassistant/components/template/__init__.py index a1231708b91..47b51853bcd 100644 --- a/homeassistant/components/template/__init__.py +++ b/homeassistant/components/template/__init__.py @@ -19,6 +19,7 @@ from homeassistant.helpers import ( update_coordinator, ) from homeassistant.helpers.reload import async_reload_integration_platforms +from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.typing import ConfigType from homeassistant.loader import async_get_integration @@ -54,9 +55,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: hass.bus.async_fire(f"event_{DOMAIN}_reloaded", context=call.context) - hass.helpers.service.async_register_admin_service( - DOMAIN, SERVICE_RELOAD, _reload_config - ) + async_register_admin_service(hass, DOMAIN, SERVICE_RELOAD, _reload_config) return True diff --git a/tests/components/script/test_init.py b/tests/components/script/test_init.py index 480bbcbc4f0..4ef4cd9d2b0 100644 --- a/tests/components/script/test_init.py +++ b/tests/components/script/test_init.py @@ -377,7 +377,7 @@ async def test_async_get_descriptions_script(hass): } await async_setup_component(hass, DOMAIN, script_config) - descriptions = await hass.helpers.service.async_get_all_descriptions() + descriptions = await async_get_all_descriptions(hass) assert descriptions[DOMAIN]["test1"]["description"] == "" assert not descriptions[DOMAIN]["test1"]["fields"] diff --git a/tests/helpers/test_service.py b/tests/helpers/test_service.py index cf87377dd8f..1e947a9353f 100644 --- a/tests/helpers/test_service.py +++ b/tests/helpers/test_service.py @@ -819,8 +819,9 @@ async def test_register_admin_service(hass, hass_read_only_user, hass_admin_user async def mock_service(call): calls.append(call) - hass.helpers.service.async_register_admin_service("test", "test", mock_service) - hass.helpers.service.async_register_admin_service( + service.async_register_admin_service(hass, "test", "test", mock_service) + service.async_register_admin_service( + hass, "test", "test2", mock_service, @@ -887,7 +888,7 @@ async def test_domain_control_not_async(hass, mock_entities): calls.append(call) with pytest.raises(exceptions.HomeAssistantError): - hass.helpers.service.verify_domain_control("test_domain")(mock_service_log) + service.verify_domain_control(hass, "test_domain")(mock_service_log) async def test_domain_control_unknown(hass, mock_entities): @@ -902,9 +903,9 @@ async def test_domain_control_unknown(hass, mock_entities): "homeassistant.helpers.entity_registry.async_get_registry", return_value=Mock(entities=mock_entities), ): - protected_mock_service = hass.helpers.service.verify_domain_control( - "test_domain" - )(mock_service_log) + protected_mock_service = service.verify_domain_control(hass, "test_domain")( + mock_service_log + ) hass.services.async_register( "test_domain", "test_service", protected_mock_service, schema=None @@ -940,7 +941,7 @@ async def test_domain_control_unauthorized(hass, hass_read_only_user): """Define a protected service.""" calls.append(call) - protected_mock_service = hass.helpers.service.verify_domain_control("test_domain")( + protected_mock_service = service.verify_domain_control(hass, "test_domain")( mock_service_log ) @@ -979,7 +980,7 @@ async def test_domain_control_admin(hass, hass_admin_user): """Define a protected service.""" calls.append(call) - protected_mock_service = hass.helpers.service.verify_domain_control("test_domain")( + protected_mock_service = service.verify_domain_control(hass, "test_domain")( mock_service_log ) @@ -1017,7 +1018,7 @@ async def test_domain_control_no_user(hass): """Define a protected service.""" calls.append(call) - protected_mock_service = hass.helpers.service.verify_domain_control("test_domain")( + protected_mock_service = service.verify_domain_control(hass, "test_domain")( mock_service_log )