mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Add new Remote Python Debugger integration (#36960)
This commit is contained in:
79
homeassistant/components/debugpy/__init__.py
Normal file
79
homeassistant/components/debugpy/__init__.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""The Remote Python Debugger integration."""
|
||||
from asyncio import Event
|
||||
import logging
|
||||
from threading import Thread
|
||||
from typing import Optional
|
||||
|
||||
import debugpy
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.service import async_register_admin_service
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
DOMAIN = "debugpy"
|
||||
CONF_WAIT = "wait"
|
||||
CONF_START = "start"
|
||||
SERVICE_START = "start"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_HOST, default="0.0.0.0"): cv.string,
|
||||
vol.Optional(CONF_PORT, default=5678): cv.port,
|
||||
vol.Optional(CONF_START, default=True): cv.boolean,
|
||||
vol.Optional(CONF_WAIT, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Remote Python Debugger component."""
|
||||
conf = config[DOMAIN]
|
||||
|
||||
async def debug_start(
|
||||
call: Optional[ServiceCall] = None, *, wait: bool = True
|
||||
) -> None:
|
||||
"""Start the debugger."""
|
||||
debugpy.listen((conf[CONF_HOST], conf[CONF_PORT]))
|
||||
|
||||
wait = conf[CONF_WAIT]
|
||||
if wait:
|
||||
_LOGGER.warning(
|
||||
"Waiting for remote debug connection on %s:%s",
|
||||
conf[CONF_HOST],
|
||||
conf[CONF_PORT],
|
||||
)
|
||||
ready = Event()
|
||||
|
||||
def waitfor():
|
||||
debugpy.wait_for_client()
|
||||
hass.loop.call_soon_threadsafe(ready.set)
|
||||
|
||||
Thread(target=waitfor).start()
|
||||
|
||||
await ready.wait()
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"Listening for remote debug connection on %s:%s",
|
||||
conf[CONF_HOST],
|
||||
conf[CONF_PORT],
|
||||
)
|
||||
|
||||
async_register_admin_service(
|
||||
hass, DOMAIN, SERVICE_START, debug_start, schema=vol.Schema({})
|
||||
)
|
||||
|
||||
# If set to start the debugger on startup, do so
|
||||
if conf[CONF_START]:
|
||||
await debug_start(wait=conf[CONF_WAIT])
|
||||
|
||||
return True
|
||||
8
homeassistant/components/debugpy/manifest.json
Normal file
8
homeassistant/components/debugpy/manifest.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"domain": "debugpy",
|
||||
"name": "Remote Python Debugger",
|
||||
"documentation": "https://www.home-assistant.io/integrations/debugpy",
|
||||
"requirements": ["debugpy==1.0.0b11"],
|
||||
"codeowners": ["@frenck"],
|
||||
"quality_scale": "internal"
|
||||
}
|
||||
3
homeassistant/components/debugpy/services.yaml
Normal file
3
homeassistant/components/debugpy/services.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
# Describes the format for available Remote Python Debugger services
|
||||
start:
|
||||
description: Start the Remote Python Debugger.
|
||||
Reference in New Issue
Block a user