How to debug?

[Windows]

I’ve followed the setup guide for development of the core. Installed vscode, docker etc. cloned the repo etc.

In VSCode, i’ve changed launch.json to point at the URL that the docker container is running at:
“url”: “http://127.0.0.1:8123”,

I have executed hass -c config --debug in the terminal.

When i start a debug session (F5), chrome is opened and HA is running there. Debugging messages are in the terminal of vscode.

But my breakpoints are greyed-out and marked as “unbound”, i can see debug messages in the terminal, but it’s not stopping at breakpoints.

Any idea?

Solved. Here’s what helped: (thanks to discord: @balloob)
Open Docker Desktop and check the container’s url by clicking “open in browser”. Mine opened a browser window to http://127.0.0.1:8123/

I added this to configuration.yaml

# Enable VSCode debugging
debugpy:
  start: true
  wait: true

And added this to launch.json

    {
      // Example of attaching to local debug server
      "name": "Python: Attach Local",
      "type": "python",
      "request": "attach",
      "port": 5678,
      "host": "127.0.0.1", // same as the browser that was opened by Docker Desktop.
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "."
        }
      ]
    }

Then run this in the terminal:

hass -c config --debug

The debug window will show that debugpy is taking >10 secs to startup, ignore this; its just waiting for you to start the debug session, so do this:

From the RUN drop menu, select “Python: Attach Local”
Add your breakpoints, and click F5 (Start Debugging).

Hope this helps someone.

2 Likes