Component python debugging

Hi there lovely programmers!

spent a day today familiarising with YAML and Python. I’m a web developer but I’m very new to these technologies, have no problems to play around though and get an idea, but not without proper and efficient debugging.

Have been setting up a develop environment as mentioned here, which really wasn’t a walk in the park for me, because VSCode won’t work with WSL 2 and containers. So I configured a manual environment. I’m stuck though. I don’t want to just write code, I need to see some results somewhere, and be able to print() or log variables.

I’ve moved on to writing straight in the /config/custom_components folder, and there I found I do get some (noisy) logs from the dashboards System Logs and Logs sections, but I need to restart HA every time to get new results.

I’m very lost with this setup. To those experienced code tinkerers, can you help me to set me up and get me started? My goal is to write components ( as this seems it can go anywhere eventually ), I figure I don’t really need the whole dev environment but writing the custom component straight in my HA installation does the job, as I also have the visual - but the need of system restart is tedious. I might be talking gibberish though.

How are you locally setup to efficiently write code for HA? Help!

1 Like

I don’t know of a better way to develop custom components other than the trial and error method you are already using. Ideally you could write tests which would eliminate the need to keep restarting home assistant servers, but it isn’t straightforward to write tests for a custom component. If anyone has a streamlined way to write tests, I would love to know.