Are there any python debuggers that I’d be able to install and use within Hassio? I basically just want to be able to step through python code in custom_components and be able to set breakpoints and view values of variables.
Wasn’t sure if this is even possible or whether I would have to move away from hassio if I want to use a debugger of some sort? Also is there a hassio debugger addon?
How does that work exactly? I’m a noob. Googling says to add
import pdb; pdb.set_trace() where I want a breakpoint and pdb shell will appear upon execution.
Does that work under hassio? I’m also wondering if I execute the custom component py script from an ssh session, will it still get its configuration from configuration.yaml or does it only read its config if it is called by Home Assistant during the update interval?
It appears as though I can run python from the web terminal addon. Then using, “python -m pdb sensor.py” I can step through the code with pdb.
Is there any way for importing of the config and entity to work?:
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity
If not I guess, I should just comment those lines out and hard code the config values into the script just while debugging?
Sorry for the noob questions. Just trying to get my feet wet.
Personally, I debug custom components by writing to the logs. But I’ll follow this in case you manage get it working .
Instead of doing that from the terminal add-on, have you tried from the Home Assistant container itself? You may need to figure out how to restart HA within the container since a brief search suggests pdb can’t attach to an already running process.
i’ve been looking for an answer to this question as well. The documentation is not very detailed. LOGGER is an option, but not enough. I am looking to stop the flow and actually look at dictionaries and data structures to understand their integrity and formatting. Can;t do all that with simple debug prints. There are complex components in home assistant, there MUST be a way to do realtime debug somehow
Very good point @anon34565116. I assumed it was a binary because it’s in the bin directory and python3 hass returns an error. So running your command;
~$ file /home/cagabi/.local/bin/hass
/home/cagabi/.local/bin/hass: Python script, ASCII text executable
But then doing pip3 freeze I see that homeassistant is installed and I can start it with python3 -m homeassistant in the same way that just running hass
But when I do
~$ python3 -m pdb homeassistant
Error: homeassistant does not exist
Sorry for never getting back to this.
Finally debug it is working but I am not starting pdb from the command line, I only have to import pdb in the script and call pdb.set_trace(). Simply running hass in the command line stops at the breakpoint