addons-example icon indicating copy to clipboard operation
addons-example copied to clipboard

Add ability to restart/rebuild addon from vscode

Open davet2001 opened this issue 2 years ago • 3 comments

Working from within vscode, it is helpful to have the ability to immediately run the code you have just edited, and watch the output. Shortening this iteration cycle makes a big difference to productivity.

Currently it seems the normal method is to start and stop addons via the web UI, and view logs in a non-live way via the web-based log view.

This PR adds two 'tasks' to the vscode command palette within the development environment:

  1. Start Addon - starts the addon by invoking the ha cli through docker, then following the docker container console output.
  2. Rebuild and start Addon - same as above, but triggers a reinstall of the addon through the ha cli first.

The grep is needed to get the slug name of the addon which is configured by the user in config.yaml

Note that it is necessary for HA to be running (e.g. via first running 'Start Home Assistant') before triggering either of the above two tasks from the palette. Also note that this PR makes no difference to the way the addon operates. It's just to help vscode users during development.

image

In both cases it is possible to use vscode's built-in 'Tasks: Restart Running Task' which effectively stops and restarts the addon.

The end result is that ctrl-shift-p,<enter>,<enter> without leaving vscode is enough to iterate.

davet2001 avatar Jan 01 '23 23:01 davet2001

Update: I'm slightly less happy with this than I was.

Since creating the PR I've realised that the template repo is probably intended for a collection of add-ons, not just one.

If you have just one addon it works well, but if you have more then one, there's not an easy way to configure which one to start/rebuild.

Perhaps it makes more sense to define the slug explicitly for the example addon, then let the developer duplicate that section of tasks.json if they have multiple addons in the repo.

davet2001 avatar Jan 18 '23 12:01 davet2001

While there is only 1 addon here, that's generally not the case for an actual repository. You can define inputs for tasks like https://github.com/home-assistant/frontend/blob/dev/.vscode/tasks.json#L202 that will fit well with what you try to do here.

ludeeus avatar Jan 20 '23 09:01 ludeeus

@ludeeus I tried this and it works, but when I call the function I have to manually type the addon directory name in to make it run.
It's slightly better if I set the reevaluateOnRerun property to false, but I'm still asked to type it if I choose 'restart running task'.

I have updated the PR with this now. Can you think of any improvements?

davet2001 avatar Feb 01 '23 22:02 davet2001

@ludeeus If I understood you correctly, this should be ready now.

davet2001 avatar Jun 10 '24 21:06 davet2001

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1:

Learn more about our pull request process.

home-assistant[bot] avatar Jun 11 '24 07:06 home-assistant[bot]