diff --git a/homeassistant/components/debugpy/__init__.py b/homeassistant/components/debugpy/__init__.py index bec030da8429..801609812601 100644 --- a/homeassistant/components/debugpy/__init__.py +++ b/homeassistant/components/debugpy/__init__.py @@ -3,13 +3,13 @@ import probatio from homeassistant.const import CONF_HOST, CONF_PORT -from homeassistant.core import HomeAssistant, ServiceCall +from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.typing import ConfigType -from .const import CONF_START, CONF_WAIT, DATA_DEBUGPY_CONFIG, DOMAIN, SERVICE_START +from .const import CONF_START, CONF_WAIT, DATA_DEBUGPY_CONFIG, DOMAIN from .helpers import async_start_debugger +from .services import async_setup_services CONFIG_SCHEMA = probatio.Schema( { @@ -31,13 +31,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: conf = config[DOMAIN] hass.data[DATA_DEBUGPY_CONFIG] = conf - async def debug_start(call: ServiceCall) -> None: - """Enable asyncio debugging and start the debugger.""" - await async_start_debugger(call.hass) - - async_register_admin_service( - hass, DOMAIN, SERVICE_START, debug_start, schema=probatio.Schema({}) - ) + async_setup_services(hass) # If set to start the debugger on startup, do so if conf[CONF_START]: diff --git a/homeassistant/components/debugpy/services.py b/homeassistant/components/debugpy/services.py new file mode 100644 index 000000000000..fe0d95cdd362 --- /dev/null +++ b/homeassistant/components/debugpy/services.py @@ -0,0 +1,22 @@ +"""Services for the Remote Python Debugger integration.""" + +import probatio + +from homeassistant.core import HomeAssistant, ServiceCall, callback +from homeassistant.helpers.service import async_register_admin_service + +from .const import DOMAIN, SERVICE_START +from .helpers import async_start_debugger + + +async def _debug_start(call: ServiceCall) -> None: + """Enable asyncio debugging and start the debugger.""" + await async_start_debugger(call.hass) + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Remote Python Debugger integration.""" + async_register_admin_service( + hass, DOMAIN, SERVICE_START, _debug_start, schema=probatio.Schema({}) + )