Ptvsd debugger component. (#23336)
* ptvsd debugger component. * Add test case * ptvsd as test dependency * Fix for 3.5 * Fixed bootstrap test * Use dict direct lookup. * Don't need to load dependencies. * Get the test working. * 3.5 fix * Set mock return value * Put tests back, but skip them * Change log level
This commit is contained in:
1 parent
24060e0fb5
commit
b0843f4a38
10 files changed
+150
-1
No files matched your search
@@ -26,6 +26,7 @@ ERROR_LOG_FILENAME = 'home-assistant.log'
|
||||
# hass.data key for logging information.
|
||||
DATA_LOGGING = 'logging'
|
||||
|
||||
DEBUGGER_INTEGRATIONS = {'ptvsd', }
|
||||
CORE_INTEGRATIONS = ('homeassistant', 'persistent_notification')
|
||||
LOGGING_INTEGRATIONS = {'logger', 'system_log'}
|
||||
STAGE_1_INTEGRATIONS = {
|
||||
@@ -306,6 +307,15 @@ async def _async_set_up_integrations(
|
||||
"""Set up all the integrations."""
|
||||
domains = _get_domains(hass, config)
|
||||
|
||||
# Start up debuggers. Start these first in case they want to wait.
|
||||
debuggers = domains & DEBUGGER_INTEGRATIONS
|
||||
if debuggers:
|
||||
_LOGGER.debug("Starting up debuggers %s", debuggers)
|
||||
await asyncio.gather(*[
|
||||
async_setup_component(hass, domain, config)
|
||||
for domain in debuggers])
|
||||
domains -= DEBUGGER_INTEGRATIONS
|
||||
|
||||
# Resolve all dependencies of all components so we can find the logging
|
||||
# and integrations that need faster initialization.
|
||||
resolved_domains_task = asyncio.gather(*[
|
||||
@@ -339,7 +349,7 @@ async def _async_set_up_integrations(
|
||||
stage_2_domains = domains - logging_domains - stage_1_domains
|
||||
|
||||
if logging_domains:
|
||||
_LOGGER.debug("Setting up %s", logging_domains)
|
||||
_LOGGER.info("Setting up %s", logging_domains)
|
||||
|
||||
await asyncio.gather(*[
|
||||
async_setup_component(hass, domain, config)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
Enable ptvsd debugger to attach to HA.
|
||||
|
||||
Attach ptvsd debugger by default to port 5678.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from threading import Thread
|
||||
from asyncio import Event
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PORT)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
|
||||
DOMAIN = 'ptvsd'
|
||||
|
||||
CONF_WAIT = 'wait'
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
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_WAIT, default=False
|
||||
): cv.boolean,
|
||||
})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistantType, config: ConfigType):
|
||||
"""Set up ptvsd debugger."""
|
||||
import ptvsd
|
||||
|
||||
conf = config[DOMAIN]
|
||||
host = conf[CONF_HOST]
|
||||
port = conf[CONF_PORT]
|
||||
|
||||
ptvsd.enable_attach((host, port))
|
||||
|
||||
wait = conf[CONF_WAIT]
|
||||
if wait:
|
||||
_LOGGER.warning("Waiting for ptvsd connection on %s:%s", host, port)
|
||||
ready = Event()
|
||||
|
||||
def waitfor():
|
||||
ptvsd.wait_for_attach()
|
||||
hass.loop.call_soon_threadsafe(ready.set)
|
||||
Thread(target=waitfor).start()
|
||||
|
||||
await ready.wait()
|
||||
else:
|
||||
_LOGGER.warning("Listening for ptvsd connection on %s:%s", host, port)
|
||||
|
||||
return True
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"domain": "ptvsd",
|
||||
"name": "ptvsd",
|
||||
"documentation": "https://www.home-assistant.io/components/ptvsd",
|
||||
"requirements": [
|
||||
"ptvsd==4.2.8"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@swamp-ig"]
|
||||
}
|
||||
Reference in new issue
Block a user