Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to restart/rebuild addon from vscode #58

Merged
merged 3 commits into from
Jun 18, 2024

Conversation

davet2001
Copy link
Contributor

@davet2001 davet2001 commented Jan 1, 2023

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
Copy link
Contributor Author

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.

@ludeeus
Copy link
Member

ludeeus commented Jan 20, 2023

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.

@davet2001 davet2001 marked this pull request as draft February 1, 2023 21:39
@davet2001
Copy link
Contributor Author

@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?

.vscode/tasks.json Outdated Show resolved Hide resolved
@davet2001 davet2001 marked this pull request as ready for review June 10, 2024 21:55
@davet2001
Copy link
Contributor Author

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

Copy link
Member

@ludeeus ludeeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, we have "direct" access to the ha CLI, so lets use that 👍

.vscode/tasks.json Outdated Show resolved Hide resolved
.vscode/tasks.json Outdated Show resolved Hide resolved
@home-assistant
Copy link

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

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft June 11, 2024 07:14
@davet2001 davet2001 marked this pull request as ready for review June 11, 2024 19:44
@home-assistant home-assistant bot requested a review from ludeeus June 11, 2024 19:44
Copy link
Member

@ludeeus ludeeus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@ludeeus ludeeus merged commit 3033f65 into home-assistant:main Jun 18, 2024
5 checks passed
@davet2001 davet2001 deleted the vscode_helper_tasks branch June 18, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants