Setting up VSCode¶
The following steps will configure Visual Studio Code to recognize the Helper Libraries and provide examples of how to reduce the number of errors being displayed because VSCode does not have access to any openHAB packages.
ENV File¶
Create a
.envfile in the root of your openHAB conf directory (ex{OH_CONF}/.env) and add the following to it:PYTHONPATH="./automation/lib/python"This will allow
pylintto see any packages or modules in that directory and no longer show import errors for them.
Exclude Helper Libraries¶
If you don’t already have an
{OH_CONF}/.vscode/settings.jsonfile, create it and add the following:{ "python.linting.ignorePatterns": [ "**/automation/**/python/core/**/*.py", "**/automation/**/python/community/**/*.py" ] }This will tell
pylintto ignore all files in the Helper Libraries’coreandcommunitydirectories, greatly reducing the number of errors you will see because of openHAB packages it cannot import.
pylint Directives¶
Lastly, you can use
pylintdirectives if you want to disable the import error messages in your files for the openHAB packages that it cannot import.When importing packages or classes from openHAB:
# pylint: disable=import-error from org.openhab.core.library.items import SwitchItem # pylint: enable=import-errorWhen importing
scopefromcore.jsr223:# pylint: disable=import-error, no-name-in-module from core.jsr223 import scope # pylint: enable=import-error, no-name-in-module