Hubitat Developer VSCode Plugin

Hello Hubitat Developers,

I just finished up building a VSCode extension that allows for the publishing of local files to the hubitat and I am looking for some folks to help test it out.

I haven’t published it out to the Visual Studio Marketplace (yet), but you can download the extension as a .vsix file on my github releases page and install it into VSCode manually. There is more documentation available on the README of the repo. GitHub - louisparks/vscode-hubitat-dev

Steps to install

  1. Install the Free Visual Studio Code from Microsoft
  2. Download the latest release of the .vsix file from Releases · louisparks/vscode-hubitat-dev · GitHub
  3. While in VSCode, type in Control-Shift-P (Command-Shift-P) and then start typing “vsix”.
  4. Select “Extensions: Install from vsix”.
  5. Select the downloaded vsix file to install the extension.

Once it's installed, you can add a local folder with your drivers and apps in it to your VSCode workspace. With a document open, again type Control-Shift-P and this time type in Hubitat - Publish. It will prompt you for the address of your Hubitat and push the currently open file to your hub.

hubitat_publish_new

To be clear, this method of deploying drivers and apps is not officially published or supported by Hubitat, it was reverse engineered from the web app IDE. But, it works great, and many of us have been doing this for years though some CLI scripts. It’s my hope that if enough of us request it, Hubitat will hopefully codify some API’s for publishing.

This is use at your own risk, but there really isn’t too much trouble you can get yourself into.

I hope you enjoy this, it should be a massive time and hopefully overall improve the readability of all the wonderful apps and drivers out there. VSCode is great (and free) IDE and it has a wonderful groovy linter and code formatter. The linter is a great way to learn more idiomatic groovy. I have created a groovy lint config that make some exceptions to make Hubitat development easier.

Please provide bugs or feedback, I'll do my best to get a version 1.0.0 out and stable.

Thanks,
Louis

22 Likes

Nice addition!

I’ll give this a try later, does it support app and drivers?

For some years now I have been using my own script that fully syncs my apps and drivers, this could be a nice feature. This is my code if it can help:

Hubitat/deploy.py at master · syepes/Hubitat · GitHub

2 Likes

Quick test and it seems to work out of the box, my fingers are going to have to get used to using this to publish instead of "select-all-copy-switch-window-paste" :smiley:

1 Like

Yes drivers, apps and libraries

thanks for the help testing Jonathon!

Installed and trying to push existing code, when I open the JSON file and indicate the ID number of the app or driver, when I try to push the new code to HE, it indicates "created new driver...", nothing was pushed and the JSON file goes back to ID= null.

BTW, on github release notes of the readme.md file, it indicates release 1.0.1 as the latest, yet the release link is 0.0.9

Also when I go to the settings page for the extension, it indicates that there are no settings, yet the "feature contributions" tab indicates 2 settings?

Do you not see this under extensions?

So you pushed a local file and it created a new one on the hubitat, then you updated that id in the metadata file to be an existing one? that should work.

I'll sync up the release number with the release notes on the next commit

thanks for testing

This looks fantastic. So much time is wasted scrolling around trying to jump between functions, that alone will be a vast improvement. I have not used VS Code before. Where does the lint config go?

1 Like

This is long overdue IMO. I've been on Hubitat 3 years and the dev environment has not even inched forward, let alone taken any strides.

2 Likes

After a restart of VSCode, it is now visible, thanks!

Actually no, your extension says it created a new file (in the popup window down right) but it didn't do anything, the ID always reverts back to Null in the JSON file when I give it an existing ID.

If I don't set an ID, it is also Null since it probably can't create a new device with same "name" and "nameplace".

Might have something to do with the "overwrite" setting being off, I'll do more tests later and confirm my findings.

ok, I had security enabled on that hub, and when I first went and switched it off, I did not enter my credentials to turn it off, so it wasn't actually off.

Now that it's off, all works as intended, might want to see if you can catch that kind of numb nuts thing and display a message when it fails or something. (I'll be good to test out those problems :grin: )

install the groovy lint extension then plop that config in the root of your folder(s).
beware, the linter is pretty opinionated, so when building a driver from scratch the results are beautiful groovy files.... however, most drivers out there generate dozens of warnings.

good luck...

yes, i should handle the authorization error better. I will note that. I also would love to support auth and can, but its a really big hack and I wanted to gauge interest on it first. Also, would love for the hubitat team to give a proper token rather than cookie stealing

That’s a nice script, there are a few nuggets in there I might snatch.

Do you recall how long the cookies lasted?

Don’t remember the number exactly but at least weeks, becaus I don’t have to refresh it :slight_smile:

Hi @Iparks and thanks for this awesome extension. I'm facing an issue though and I am probably missing something elementary but for now I can't find how to resolve it:

I tested the app on one of my development hubs to be on the safe side of things and it did create a new copy of my app every time, instead of overwriting the last one it created. I checked the box "overwrite" in the extension's settings, to no avail.

Since it looks like it's working for other people in this forum, can you give me a hint of where I should look to sort this out? Clearly, my app seems to be missing something considered standard and that your extension needs for version control.

Let me know if you have something to lead me toward so I can figure this out.

Thanks again for the great work.
Elfege

UPDATE: never mind, I just had to restart VSCode... I'm leaving this post here in case anybody else finds themselves in this ridiculous situation! :smile:

Thanks for giving it some mileage. There are a few tweaks I want to make regarding error handling and support for when security is enabled on the hub. Keep you eyes out for a new build soon, Ill post here.

Is everyone experiencing that you need to restart vscode to get the extension to work?

Well I had to restart as you know to get to the extension settings.

I also experience that each time I add new code and send it to the hub, if I don't have it added manually to the JSON file, it will create a new copy of the app. It would be nice if there would be a way to detect it and maybe ask if we want to create a new copy or overwrite the one already there when not already in the JSON file?

originally I had it prompt the user for an existing id if it didn't have an entry yet. entering nothing would create a new one. maybe I should put that back in.

It would be dirtier but not impossible to query all the deployed code on the hub and try to find a match based on namespace-name. maybe for now I'll just put back my original method