Clean up accessing service helpers via hass (#72013)
parent
5433c0a535
commit
c0da97b038
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue