Dev Setup, Visual Studio, Windows Subsystem, & Backend

I’m trying to create an environment where I can activitly debug into home assistant as it’s running. My knowledge is limited in this department. I currently have ubuntu running on windows sub system. I followed these 2 guides for setting up backend and frontend development.

https://developers.home-assistant.io/docs/en/frontend_development.html

The last piece of the puzzle is somehow linking Visual Studio to the hass library.

Now, I’m used to working with C# and C++ through visual studio. In those circumstances, you select debug or release, your platform, build/compile and run. When in debug, you can add stop points and view objects live.

How can I achieve that with home assistant? I’ve opened the home-assistant directory in visual studio as a new project and I can develop, but I can’t really debug. Does anyone have pointers?

You VS is running on Windows, and your HA is running on Linux, they are not hosted in the same “machine”. Therefore you need setup remote interpreter in VS to allow VS to running your HA source code using the Python interpreter in remote Linux.

That is only a theory, I never try to do that by using VS. However, I have done the similar settings on PyCharm for Windows and remote interpreter in Ubuntu VM. There is the official guide for setup a WSL remote interpreter

Ah thanks. I’ll look into this some more. What are you using to do this? I don’t necessarily need to be on windows w/ windows subsystem. I’m open to anything really. As long as I can debug as home assistant is running.

Most of my HA contribution was done on Ubuntu VM + PyCharm + Visual Studio Code (frontend). I am moving away this setup to macOS since this year. Still using PyCharm + VS Code. I also have a dev environment on Windows + PyCharm + VS Code (again). Finally I have a Cloud9 setup for some random ideas.

I am using both IDEA and VS in work. I like JetBrains product, so I purchased their all products pack for personal use in one of their Cyber Monday sale event.

1 Like

You’ve helped me look in the right direction. Just doing a few google searches for “Python interpreter windows subsystem linux visual studio” turn up some promising results for visual studio. I’m going to play around until I get this working. Thanks.

So, I’ve switched to developing on linux using visual studio code. I’ve got it working but I cannot use breakpoints. My launch.json is:

{
    "name": "Python: HomeAssistant",
    "type": "python",
    "request": "launch",
    "module": "homeassistant",
    "args": []
}

and my settings.json are:

{
    "python.pythonPath": "bin/python3"
}
  1. Is this setup correct?
  2. You know of any reason why I can’t use break points?

Microsoft released VS Code Remote Development plugin (https://github.com/microsoft/vscode-remote-release) and it supports Raspberry Pi 3 (I have Home Assistant on Pi 3).
Anyone tried this?
I’m a Windows user, but I’d like to develop and debug on my Pi.

Right now I based my integration on MCP23017 by @Jardiamj, but it’s hard to code without breakpoints and debugger, so any advice is more than welcome!

I have also been using VS Code lately, I haven’t had issues with using breakpoints.
I use NFS for sharing my .homeassistant directory with my laptop, running Pop_OS!, then I mount the NFS directory under /mnt/nfs/homeassistant and use VS Code for remote editing.
This is what my /etc/exports looks like:

/home/homeassistant/.homeassistant  remote-IP-Address(rw,all_squash,no_subtree_check,anonuid=999,anongid=996)

Where, remote-IP-Address is my laptops IP address, 999 is the homeassistant user ID and 996 is the homeassistant group ID.

I haven’t had any issues with this setup.

The remote development plugin is great. I connect to my servers with ssh and although the GUI is on my windows machine VSCode is running remotely, commands I run in VSCode run on the server. And I have an integrated shell. Not used it for python, but for setting up and testing ansible playbooks.

You can also define a development build in docker on your Windows PC and have it build it and start it automatically then you can edit and run code directly in the docker environment.

Oh well, I didn’t read the whole thread before posting. I haven’t tried remote debugging code running on the pi. I’ll have to give the ssh-remote plug in a try today.

1 Like