Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2034cfa

Browse files
committed
Add more detail on how to setup editor if using VSCode addon
1 parent b2b5396 commit 2034cfa

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,52 @@ You may use VSCode either:
171171
- Simpler setup because no file transfer is necessary
172172
- I would still recommended to use `git` to save versions of your code (learn it by using a graphical git client such as VSCode + Git Graph extension), but you could also choose to rely only on Home Assistant backups.
173173

174+
#### Install Python extension
175+
176+
Open your editor (e.g. VSCode), and browse to your AppDaemon apps folder (e.g. if using the VSCode addon, `File > Open folder > /addon_configs/a0d7b954_appdaemon`).
177+
178+
- If you are using the VSCode addon of Home Assistant (or any other non-packed-by-microsoft flavor), install the [BasedPyright](https://open-vsx.org/extension/detachhead/basedpyright) extension.
179+
- If you are using the Microsoft-packed VSCode, you may install the [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) extension (which contains Pylance, which uses Pyright).
180+
174181
#### Python configuration & venv
175182

176-
Install python, [create a virtual environment and install appdaemon in there](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/), then [select the venv in `VSCode`](https://code.visualstudio.com/docs/python/environments).
183+
We need to make appdaemon accessible to the type checker.
184+
185+
1. Create a virtual environment in your VSCode workspace:
186+
- Press Ctrl+Shift+P (or Cmd+Shift+P on mac) to open the command palette (Ctrl+P then type `>` if that doesn't work)
187+
- Type `> Python: Select Interpreter`
188+
- Click "Create virtual environment"
189+
- Once that [complates](https://code.visualstudio.com/docs/python/environments#_using-the-create-environment-command), at the bottom right of the editor, if you have any `.py` file open, it should show `3.11.2 ('.venv': venv)`
190+
2. Install appdaemon in the virtual env:
191+
- Press Ctrl+Shift+C to open a terminal
192+
- It should show `.venv` at the beginning of the prompt, to signify that it is running within the context of the virtual env.
193+
- Type `pip install --upgrade appdaemon` in the VSCode terminal. It should complete without any error after some time.
177194

178195
#### Typer configuration
179196

180197
To have the typer catch as many mistakes as possible right from your editor, you should configure [`pyright`](https://github.com/microsoft/pyright) (default typer of VsCode) with appropriate typing constraints in the project where you develop your own automations (with `hapt.py` copied there).
181198

182199
Suggested parameters are available in this repository's `pyrightconfig.json`.
183200

184-
It is recommended to copy the same parameters over to the folder that you open in VSCode when working on your AppDaemon Apps.
201+
It is recommended to copy the same parameters over to the folder that you open in VSCode when working on your AppDaemon Apps:
202+
```bash
203+
cp /addon_configs/a0d7b954_appdaemon/homeassistant_python_typer/pyrightconfig.json /addon_configs/a0d7b954_appdaemon/pyrightconfig.json
204+
```
185205

186-
You probably also want to enable checking all files and not only those you currently have open:
206+
You probably also want to enable checking all files and not only those you currently have open, by adding to the `.vscode/settings.json` file (may need to be created):
187207

188-
With Pylance (official VSCode on local machine):
208+
With BasedPyright (if running e.g. the VSCode home assistant addon):
189209
```json
190-
{ "python.analysis.diagnosticMode": "workspace" }
210+
{ "basedpyright.analysis.diagnosticMode": "workspace" }
191211
```
192212

193-
With BasedPyright (if running e.g. the VSCode home assistant addon):
213+
With Pylance (official VSCode on local machine):
194214
```json
195-
{ "basedpyright.analysis.diagnosticMode": "workspace" }
215+
{ "python.analysis.diagnosticMode": "workspace" }
196216
```
197217

218+
219+
198220
### Running directly on your computer
199221

200222
If you prefer to develop directly from the confort of your own computer from your local editor, you may run the script there.

0 commit comments

Comments
 (0)